Skip to content

Commit a4d2675

Browse files
committed
v1.1.0 - Added rDNS functions, exceptions, and more.
- Added various rDNS functions to `privex.helpers.net` such as `ip_to_rdns` - Added unit tests to `tests.py` for the rDNS functions - Created new `exceptions.py` with various exception classes - Fixed `setup.py` to use BASE_DIR, avoiding issues if setup.py is ran relatively - Fixed django.py imports - Cleaned up PyDoc comments for modules and some functions - Added PyDoc comment to tests.py explaining how to use the unit tests - Various other small improvements
1 parent 0251113 commit a4d2675

File tree

9 files changed

+606
-221
lines changed

9 files changed

+606
-221
lines changed

privex/__init__.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
"""
2+
This module folder is just used for structuring ``helpers`` under the ``privex`` root package.
3+
4+
**Copyright**::
5+
6+
+===================================================+
7+
| © 2019 Privex Inc. |
8+
| https://www.privex.io |
9+
+===================================================+
10+
| |
11+
| Originally Developed by Privex Inc. |
12+
| |
13+
| Core Developer(s): |
14+
| |
15+
| (+) Chris (@someguy123) [Privex] |
16+
| (+) Kale (@kryogenic) [Privex] |
17+
| |
18+
+===================================================+
19+
20+
Copyright 2019 Privex Inc. ( https://www.privex.io )
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy of
23+
this software and associated documentation files (the "Software"), to deal in
24+
the Software without restriction, including without limitation the rights to use,
25+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
26+
Software, and to permit persons to whom the Software is furnished to do so,
27+
subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all
30+
copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
33+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
34+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
238
339
"""
4-
+===================================================+
5-
| © 2019 Privex Inc. |
6-
| https://www.privex.io |
7-
+===================================================+
8-
| |
9-
| Originally Developed by Privex Inc. |
10-
| |
11-
| Core Developer(s): |
12-
| |
13-
| (+) Chris (@someguy123) [Privex] |
14-
| (+) Kale (@kryogenic) [Privex] |
15-
| |
16-
+===================================================+
17-
18-
Copyright 2019 Privex Inc. ( https://www.privex.io )
19-
20-
Permission is hereby granted, free of charge, to any person obtaining a copy of
21-
this software and associated documentation files (the "Software"), to deal in
22-
the Software without restriction, including without limitation the rights to use,
23-
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
24-
Software, and to permit persons to whom the Software is furnished to do so,
25-
subject to the following conditions:
26-
27-
The above copyright notice and this permission notice shall be included in all
28-
copies or substantial portions of the Software.
29-
30-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
31-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36-
"""
40+
41+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
42+

privex/helpers/__init__.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,50 @@
33
44
X11 / MIT License
55
6-
Submodules:
7-
8-
* common - Uncategorized functions and classes, including bool checks and data parsing
9-
* decorators - Class / function decorators
10-
* django - Django-specific functions/classes, only available if Django package is installed
11-
* net - Network related functions/classes such as ASN name lookup, and IP version bool checks
12-
13-
14-
+===================================================+
15-
| © 2019 Privex Inc. |
16-
| https://www.privex.io |
17-
+===================================================+
18-
| |
19-
| Originally Developed by Privex Inc. |
20-
| |
21-
| Core Developer(s): |
22-
| |
23-
| (+) Chris (@someguy123) [Privex] |
24-
| (+) Kale (@kryogenic) [Privex] |
25-
| |
26-
+===================================================+
27-
28-
Copyright 2019 Privex Inc. ( https://www.privex.io )
29-
30-
Permission is hereby granted, free of charge, to any person obtaining a copy of
31-
this software and associated documentation files (the "Software"), to deal in
32-
the Software without restriction, including without limitation the rights to use,
33-
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
34-
Software, and to permit persons to whom the Software is furnished to do so,
35-
subject to the following conditions:
36-
37-
The above copyright notice and this permission notice shall be included in all
38-
copies or substantial portions of the Software.
39-
40-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
41-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
42-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
43-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
44-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6+
**Submodules**:
7+
8+
* :py:mod:`.common` - Uncategorized functions and classes, including bool checks and data parsing
9+
* :py:mod:`.decorators` - Class / function decorators
10+
* :py:mod:`.django` - Django-specific functions/classes, only available if Django package is installed
11+
* :py:mod:`.net` - Network related functions/classes such as ASN name lookup, and IP version bool checks
12+
* :py:mod:`.exceptions` - Exception classes used either by our helpers, or generic exceptions for use in projects
13+
14+
15+
**Copyright**::
16+
17+
+===================================================+
18+
| © 2019 Privex Inc. |
19+
| https://www.privex.io |
20+
+===================================================+
21+
| |
22+
| Originally Developed by Privex Inc. |
23+
| |
24+
| Core Developer(s): |
25+
| |
26+
| (+) Chris (@someguy123) [Privex] |
27+
| (+) Kale (@kryogenic) [Privex] |
28+
| |
29+
+===================================================+
30+
31+
Copyright 2019 Privex Inc. ( https://www.privex.io )
32+
33+
Permission is hereby granted, free of charge, to any person obtaining a copy of
34+
this software and associated documentation files (the "Software"), to deal in
35+
the Software without restriction, including without limitation the rights to use,
36+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
37+
Software, and to permit persons to whom the Software is furnished to do so,
38+
subject to the following conditions:
39+
40+
The above copyright notice and this permission notice shall be included in all
41+
copies or substantial portions of the Software.
42+
43+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
44+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
45+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
46+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
47+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49+
4650
"""
4751

4852
import logging
@@ -71,3 +75,4 @@ def _setup_logging(level=logging.WARNING):
7175
from privex.helpers.common import *
7276
from privex.helpers.decorators import *
7377
from privex.helpers.net import *
78+
from privex.helpers.exceptions import *

privex/helpers/common.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
"""
22
Common functions and classes that don't fit into a specific category
33
4-
+===================================================+
5-
| © 2019 Privex Inc. |
6-
| https://www.privex.io |
7-
+===================================================+
8-
| |
9-
| Originally Developed by Privex Inc. |
10-
| |
11-
| Core Developer(s): |
12-
| |
13-
| (+) Chris (@someguy123) [Privex] |
14-
| (+) Kale (@kryogenic) [Privex] |
15-
| |
16-
+===================================================+
17-
18-
Copyright 2019 Privex Inc. ( https://www.privex.io )
19-
20-
Permission is hereby granted, free of charge, to any person obtaining a copy of
21-
this software and associated documentation files (the "Software"), to deal in
22-
the Software without restriction, including without limitation the rights to use,
23-
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
24-
Software, and to permit persons to whom the Software is furnished to do so,
25-
subject to the following conditions:
26-
27-
The above copyright notice and this permission notice shall be included in all
28-
copies or substantial portions of the Software.
29-
30-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
31-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4+
**Copyright**::
5+
6+
+===================================================+
7+
| © 2019 Privex Inc. |
8+
| https://www.privex.io |
9+
+===================================================+
10+
| |
11+
| Originally Developed by Privex Inc. |
12+
| |
13+
| Core Developer(s): |
14+
| |
15+
| (+) Chris (@someguy123) [Privex] |
16+
| (+) Kale (@kryogenic) [Privex] |
17+
| |
18+
+===================================================+
19+
20+
Copyright 2019 Privex Inc. ( https://www.privex.io )
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy of
23+
this software and associated documentation files (the "Software"), to deal in
24+
the Software without restriction, including without limitation the rights to use,
25+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
26+
Software, and to permit persons to whom the Software is furnished to do so,
27+
subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all
30+
copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
33+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
34+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38+
3639
"""
3740
import random
3841
import string
@@ -166,26 +169,28 @@ def is_false(v, chk_none: bool = True) -> bool:
166169

167170
def parse_keyval(line: str) -> List[Tuple[str, str]]:
168171
"""
169-
Parses a csv with key:value pairs such as:
172+
Parses a csv with key:value pairs such as::
170173
171174
John Alex:Doe,Jane Sarah:Doe
172175
173-
Into a list with tuple pairs (can be easily converted to a dict):
176+
177+
Into a list with tuple pairs (can be easily converted to a dict)::
174178
175179
[
176180
('John Alex', 'Doe'),
177181
('Jane Sarah', 'Doe')
178182
]
179-
180-
:param str line: A string of key:value pairs separated by commas e.g. "John Alex:Doe,Jane Sarah:Doe"
183+
184+
185+
:param str line: A string of key:value pairs separated by commas e.g. ``John Alex:Doe,Jane Sarah:Doe``
181186
:return List[Tuple[str,str]] parsed_data: A list of (key, value) tuples that can easily be casted to a dict()
182187
"""
183188
line = [tuple(a.split(':')) for a in line.split(',')] if line != '' else []
184189
return [(a.strip(), b.strip()) for a, b in line]
185190

186191
def env_keyval(env_key: str, env_default = None) -> List[Tuple[str, str]]:
187192
"""
188-
Parses "key:val,key:val" into a list of tuples [(key,val), (key,val)]
193+
Parses ``key:val,key:val`` into a list of tuples [(key,val), (key,val)]
189194
190195
See :py:meth:`parse_keyval`
191196
"""

privex/helpers/decorators.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
"""
22
Class Method / Function decorators
33
4-
+===================================================+
5-
| © 2019 Privex Inc. |
6-
| https://www.privex.io |
7-
+===================================================+
8-
| |
9-
| Originally Developed by Privex Inc. |
10-
| |
11-
| Core Developer(s): |
12-
| |
13-
| (+) Chris (@someguy123) [Privex] |
14-
| (+) Kale (@kryogenic) [Privex] |
15-
| |
16-
+===================================================+
17-
18-
Copyright 2019 Privex Inc. ( https://www.privex.io )
19-
20-
Permission is hereby granted, free of charge, to any person obtaining a copy of
21-
this software and associated documentation files (the "Software"), to deal in
22-
the Software without restriction, including without limitation the rights to use,
23-
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
24-
Software, and to permit persons to whom the Software is furnished to do so,
25-
subject to the following conditions:
26-
27-
The above copyright notice and this permission notice shall be included in all
28-
copies or substantial portions of the Software.
29-
30-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
31-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4+
**Copyright**::
5+
6+
+===================================================+
7+
| © 2019 Privex Inc. |
8+
| https://www.privex.io |
9+
+===================================================+
10+
| |
11+
| Originally Developed by Privex Inc. |
12+
| |
13+
| Core Developer(s): |
14+
| |
15+
| (+) Chris (@someguy123) [Privex] |
16+
| (+) Kale (@kryogenic) [Privex] |
17+
| |
18+
+===================================================+
19+
20+
Copyright 2019 Privex Inc. ( https://www.privex.io )
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy of
23+
this software and associated documentation files (the "Software"), to deal in
24+
the Software without restriction, including without limitation the rights to use,
25+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
26+
Software, and to permit persons to whom the Software is furnished to do so,
27+
subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all
30+
copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
33+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
34+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38+
3639
"""
3740
import functools
3841
import logging

0 commit comments

Comments
 (0)