libpass 1.7.5.post0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. libpass-1.7.5.post0.dist-info/METADATA +81 -0
  2. libpass-1.7.5.post0.dist-info/RECORD +69 -0
  3. libpass-1.7.5.post0.dist-info/WHEEL +4 -0
  4. libpass-1.7.5.post0.dist-info/licenses/LICENSE +116 -0
  5. passlib/__init__.py +3 -0
  6. passlib/_data/wordsets/bip39.txt +2049 -0
  7. passlib/_data/wordsets/eff_long.txt +7776 -0
  8. passlib/_data/wordsets/eff_prefixed.txt +1296 -0
  9. passlib/_data/wordsets/eff_short.txt +1296 -0
  10. passlib/_setup/__init__.py +1 -0
  11. passlib/_setup/stamp.py +159 -0
  12. passlib/apache.py +1185 -0
  13. passlib/apps.py +260 -0
  14. passlib/context.py +2066 -0
  15. passlib/crypto/__init__.py +1 -0
  16. passlib/crypto/_blowfish/__init__.py +171 -0
  17. passlib/crypto/_blowfish/_gen_files.py +256 -0
  18. passlib/crypto/_blowfish/base.py +1239 -0
  19. passlib/crypto/_blowfish/unrolled.py +1691 -0
  20. passlib/crypto/_md4.py +249 -0
  21. passlib/crypto/des.py +2283 -0
  22. passlib/crypto/digest.py +1111 -0
  23. passlib/crypto/scrypt/__init__.py +299 -0
  24. passlib/crypto/scrypt/_builtin.py +254 -0
  25. passlib/crypto/scrypt/_gen_files.py +161 -0
  26. passlib/crypto/scrypt/_salsa.py +188 -0
  27. passlib/exc.py +432 -0
  28. passlib/ext/__init__.py +1 -0
  29. passlib/ext/django/__init__.py +6 -0
  30. passlib/ext/django/models.py +38 -0
  31. passlib/ext/django/utils.py +1326 -0
  32. passlib/handlers/__init__.py +1 -0
  33. passlib/handlers/argon2.py +1119 -0
  34. passlib/handlers/bcrypt.py +1217 -0
  35. passlib/handlers/cisco.py +450 -0
  36. passlib/handlers/des_crypt.py +642 -0
  37. passlib/handlers/digests.py +184 -0
  38. passlib/handlers/django.py +545 -0
  39. passlib/handlers/fshp.py +223 -0
  40. passlib/handlers/ldap_digests.py +379 -0
  41. passlib/handlers/md5_crypt.py +375 -0
  42. passlib/handlers/misc.py +224 -0
  43. passlib/handlers/mssql.py +258 -0
  44. passlib/handlers/mysql.py +136 -0
  45. passlib/handlers/oracle.py +177 -0
  46. passlib/handlers/pbkdf2.py +521 -0
  47. passlib/handlers/phpass.py +142 -0
  48. passlib/handlers/postgres.py +61 -0
  49. passlib/handlers/roundup.py +33 -0
  50. passlib/handlers/scram.py +589 -0
  51. passlib/handlers/scrypt.py +413 -0
  52. passlib/handlers/sha1_crypt.py +173 -0
  53. passlib/handlers/sha2_crypt.py +657 -0
  54. passlib/handlers/sun_md5_crypt.py +387 -0
  55. passlib/handlers/windows.py +349 -0
  56. passlib/hash.py +111 -0
  57. passlib/hosts.py +112 -0
  58. passlib/ifc.py +354 -0
  59. passlib/pwd.py +813 -0
  60. passlib/registry.py +583 -0
  61. passlib/totp.py +1968 -0
  62. passlib/utils/__init__.py +1221 -0
  63. passlib/utils/binary.py +897 -0
  64. passlib/utils/compat/__init__.py +200 -0
  65. passlib/utils/decor.py +234 -0
  66. passlib/utils/des.py +35 -0
  67. passlib/utils/handlers.py +2857 -0
  68. passlib/utils/md4.py +34 -0
  69. passlib/utils/pbkdf2.py +188 -0
@@ -0,0 +1,200 @@
1
+ """passlib.utils.compat - python 2/3 compatibility helpers"""
2
+
3
+ import sys
4
+
5
+ from types import ModuleType
6
+ import logging
7
+
8
+
9
+ # make sure it's not an unsupported version, even if we somehow got this far
10
+ if sys.version_info < (3, 5):
11
+ raise RuntimeError("Passlib requires Python >= 3.5 (as of passlib 1.8)")
12
+
13
+
14
+ JYTHON = sys.platform.startswith("java")
15
+
16
+ PYPY = hasattr(sys, "pypy_version_info")
17
+
18
+ if PYPY and sys.pypy_version_info < (2, 0):
19
+ raise RuntimeError("passlib requires pypy >= 2.0 (as of passlib 1.7)")
20
+
21
+
22
+ def add_doc(obj, doc):
23
+ """add docstring to an object"""
24
+ obj.__doc__ = doc
25
+
26
+
27
+ __all__ = [
28
+ # type detection
29
+ ## 'is_mapping',
30
+ "num_types",
31
+ "unicode_or_bytes",
32
+ # unicode/bytes types & helpers
33
+ "bascii_to_str",
34
+ "str_to_bascii",
35
+ "join_unicode",
36
+ "join_bytes",
37
+ # context helpers
38
+ "nullcontext",
39
+ # introspection
40
+ "get_method_function",
41
+ "add_doc",
42
+ ]
43
+
44
+ # begin accumulating mapping of lazy-loaded attrs,
45
+ # 'merged' into module at bottom
46
+ _lazy_attrs = dict()
47
+
48
+ # =============================================================================
49
+ # unicode & bytes types
50
+ # =============================================================================
51
+
52
+ #: alias for isinstance() tests to detect any string type
53
+ unicode_or_bytes = (str, bytes)
54
+
55
+
56
+ join_unicode = "".join
57
+ join_bytes = b"".join
58
+
59
+ if True: # legacy PY3 indent
60
+
61
+ def bascii_to_str(s):
62
+ assert isinstance(s, bytes)
63
+ return s.decode("ascii")
64
+
65
+ def str_to_bascii(s):
66
+ assert isinstance(s, str)
67
+ return s.encode("ascii")
68
+
69
+ def iter_byte_chars(s):
70
+ assert isinstance(s, bytes)
71
+ # FIXME: there has to be a better way to do this
72
+ return (bytes([c]) for c in s)
73
+
74
+
75
+ # TODO: move docstrings to funcs...
76
+ add_doc(bascii_to_str, "helper to convert ascii bytes -> native str")
77
+ add_doc(str_to_bascii, "helper to convert ascii native str -> bytes")
78
+
79
+ # byte_elem_value -- function to convert byte element to integer -- a noop under PY3
80
+
81
+ add_doc(iter_byte_chars, "iterate over byte string as sequence of 1-byte strings")
82
+
83
+ # =============================================================================
84
+ # numeric
85
+ # =============================================================================
86
+
87
+ num_types = (int, float)
88
+
89
+ # =============================================================================
90
+ # typing
91
+ # =============================================================================
92
+ ##def is_mapping(obj):
93
+ ## # non-exhaustive check, enough to distinguish from lists, etc
94
+ ## return hasattr(obj, "items")
95
+
96
+ # =============================================================================
97
+ # introspection
98
+ # =============================================================================
99
+
100
+
101
+ def get_method_function(func):
102
+ """given (potential) method, return underlying function"""
103
+ return getattr(func, "__func__", func)
104
+
105
+
106
+ # =============================================================================
107
+ # context managers
108
+ # =============================================================================
109
+
110
+ try:
111
+ # new in py37
112
+ from contextlib import nullcontext
113
+ except ImportError:
114
+
115
+ class nullcontext(object):
116
+ """
117
+ Context manager that does no additional processing.
118
+ """
119
+
120
+ def __init__(self, enter_result=None):
121
+ self.enter_result = enter_result
122
+
123
+ def __enter__(self):
124
+ return self.enter_result
125
+
126
+ def __exit__(self, *exc_info):
127
+ pass
128
+
129
+
130
+ def _import_object(source):
131
+ """helper to import object from module; accept format `path.to.object`"""
132
+ modname, modattr = source.rsplit(".", 1)
133
+ mod = __import__(modname, fromlist=[modattr], level=0)
134
+ return getattr(mod, modattr)
135
+
136
+
137
+ class _LazyOverlayModule(ModuleType):
138
+ """proxy module which overlays original module,
139
+ and lazily imports specified attributes.
140
+
141
+ this is mainly used to prevent importing of resources
142
+ that are only needed by certain password hashes,
143
+ yet allow them to be imported from a single location.
144
+
145
+ used by :mod:`passlib.utils`, :mod:`passlib.crypto`,
146
+ and :mod:`passlib.utils.compat`.
147
+ """
148
+
149
+ @classmethod
150
+ def replace_module(cls, name, attrmap):
151
+ orig = sys.modules[name]
152
+ self = cls(name, attrmap, orig)
153
+ sys.modules[name] = self
154
+ return self
155
+
156
+ def __init__(self, name, attrmap, proxy=None):
157
+ ModuleType.__init__(self, name)
158
+ self.__attrmap = attrmap
159
+ self.__proxy = proxy
160
+ self.__log = logging.getLogger(name)
161
+
162
+ def __getattr__(self, attr):
163
+ proxy = self.__proxy
164
+ if proxy and hasattr(proxy, attr):
165
+ return getattr(proxy, attr)
166
+ attrmap = self.__attrmap
167
+ if attr in attrmap:
168
+ source = attrmap[attr]
169
+ if callable(source):
170
+ value = source()
171
+ else:
172
+ value = _import_object(source)
173
+ setattr(self, attr, value)
174
+ self.__log.debug("loaded lazy attr %r: %r", attr, value)
175
+ return value
176
+ raise AttributeError("'module' object has no attribute '%s'" % (attr,))
177
+
178
+ def __repr__(self):
179
+ proxy = self.__proxy
180
+ if proxy:
181
+ return repr(proxy)
182
+ else:
183
+ return ModuleType.__repr__(self)
184
+
185
+ def __dir__(self):
186
+ attrs = set(dir(self.__class__))
187
+ attrs.update(self.__dict__)
188
+ attrs.update(self.__attrmap)
189
+ proxy = self.__proxy
190
+ if proxy is not None:
191
+ attrs.update(dir(proxy))
192
+ return list(attrs)
193
+
194
+
195
+ # replace this module with overlay that will lazily import attributes.
196
+ _LazyOverlayModule.replace_module(__name__, _lazy_attrs)
197
+
198
+ # =============================================================================
199
+ # eof
200
+ # =============================================================================
passlib/utils/decor.py ADDED
@@ -0,0 +1,234 @@
1
+ """
2
+ passlib.utils.decor -- helper decorators & properties
3
+ """
4
+
5
+ from functools import wraps, update_wrapper
6
+ import types
7
+ from warnings import warn
8
+
9
+
10
+ __all__ = [
11
+ "classproperty",
12
+ "hybrid_method",
13
+ "memoize_single_value",
14
+ "memoized_property",
15
+ "deprecated_function",
16
+ "deprecated_method",
17
+ ]
18
+
19
+
20
+ class classproperty:
21
+ """Function decorator which acts like a combination of classmethod+property (limited to read-only properties)"""
22
+
23
+ def __init__(self, func):
24
+ # XXX: rename to .fget to match property?
25
+ self.__func__ = func
26
+
27
+ def __get__(self, obj, cls):
28
+ return self.__func__(cls)
29
+
30
+
31
+ class hybrid_method(object):
32
+ """
33
+ decorator which invokes function with class if called as class method,
34
+ and with object if called at instance level.
35
+ """
36
+
37
+ def __init__(self, func):
38
+ # XXX: rename to .fget to match property?
39
+ self.func = func
40
+ update_wrapper(self, func)
41
+
42
+ def __get__(self, obj, cls):
43
+ if obj is None:
44
+ obj = cls
45
+ return types.MethodType(self.func, obj)
46
+
47
+
48
+ # =============================================================================
49
+ # memoization
50
+ # =============================================================================
51
+
52
+
53
+ def memoize_single_value(func):
54
+ """
55
+ decorator for function which takes no args,
56
+ and memoizes result. exposes a ``.clear_cache`` method
57
+ to clear the cached value.
58
+ """
59
+ cache = {}
60
+
61
+ @wraps(func)
62
+ def wrapper():
63
+ try:
64
+ return cache[True]
65
+ except KeyError:
66
+ pass
67
+ value = cache[True] = func()
68
+ return value
69
+
70
+ def clear_cache():
71
+ cache.pop(True, None)
72
+
73
+ wrapper.clear_cache = clear_cache
74
+
75
+ return wrapper
76
+
77
+
78
+ class memoized_property(object):
79
+ """
80
+ decorator which invokes method once, then replaces attr with result
81
+ """
82
+
83
+ def __init__(self, func):
84
+ self.__func__ = func
85
+ self.__name__ = func.__name__
86
+ self.__doc__ = func.__doc__
87
+
88
+ def __get__(self, obj, cls):
89
+ if obj is None:
90
+ return self
91
+ value = self.__func__(obj)
92
+ setattr(obj, self.__name__, value)
93
+ return value
94
+
95
+ def clear_cache(self, obj):
96
+ """
97
+ class-level helper to clear stored value (if any).
98
+
99
+ usage: :samp:`type(self).{attr}.clear_cache(self)`
100
+ """
101
+ obj.__dict__.pop(self.__name__, None)
102
+
103
+ def peek_cache(self, obj, default=None):
104
+ """
105
+ class-level helper to peek at stored value
106
+
107
+ usage: :samp:`value = type(self).{attr}.clear_cache(self)`
108
+ """
109
+ return obj.__dict__.get(self.__name__, default)
110
+
111
+
112
+ # works but not used
113
+ ##class memoized_class_property(object):
114
+ ## """function decorator which calls function as classmethod,
115
+ ## and replaces itself with result for current and all future invocations.
116
+ ## """
117
+ ## def __init__(self, func):
118
+ ## self.im_func = func
119
+ ##
120
+ ## def __get__(self, obj, cls):
121
+ ## func = self.im_func
122
+ ## value = func(cls)
123
+ ## setattr(cls, func.__name__, value)
124
+ ## return value
125
+ ##
126
+ ## @property
127
+ ## def __func__(self):
128
+ ## "py3 compatible alias"
129
+
130
+
131
+ # =============================================================================
132
+ # deprecation
133
+ # =============================================================================
134
+ def deprecated_function(
135
+ msg=None,
136
+ deprecated=None,
137
+ removed=None,
138
+ updoc=True,
139
+ replacement=None,
140
+ _is_method=False,
141
+ func_module=None,
142
+ ):
143
+ """decorator to deprecate a function.
144
+
145
+ :arg msg: optional msg, default chosen if omitted
146
+ :kwd deprecated: version when function was first deprecated
147
+ :kwd removed: version when function will be removed
148
+ :kwd replacement: alternate name / instructions for replacing this function.
149
+ :kwd updoc: add notice to docstring (default ``True``)
150
+ """
151
+ if msg is None:
152
+ if _is_method:
153
+ msg = "the method %(mod)s.%(klass)s.%(name)s() is deprecated"
154
+ else:
155
+ msg = "the function %(mod)s.%(name)s() is deprecated"
156
+ if deprecated:
157
+ msg += " as of Passlib %(deprecated)s"
158
+ if removed:
159
+ msg += ", and will be removed in Passlib %(removed)s"
160
+ if replacement:
161
+ msg += ", use %s instead" % replacement
162
+ msg += "."
163
+
164
+ def build(func):
165
+ is_classmethod = _is_method and isinstance(func, classmethod)
166
+ if is_classmethod:
167
+ func = func.__func__
168
+ opts = dict(
169
+ mod=func_module or func.__module__,
170
+ name=func.__name__,
171
+ deprecated=deprecated,
172
+ removed=removed,
173
+ )
174
+ if _is_method:
175
+
176
+ def wrapper(*args, **kwds):
177
+ tmp = opts.copy()
178
+ klass = args[0] if is_classmethod else args[0].__class__
179
+ tmp.update(klass=klass.__name__, mod=klass.__module__)
180
+ warn(msg % tmp, DeprecationWarning, stacklevel=2)
181
+ return func(*args, **kwds)
182
+ else:
183
+ text = msg % opts
184
+
185
+ def wrapper(*args, **kwds):
186
+ warn(text, DeprecationWarning, stacklevel=2)
187
+ return func(*args, **kwds)
188
+
189
+ update_wrapper(wrapper, func)
190
+ if (
191
+ updoc
192
+ and (deprecated or removed)
193
+ and wrapper.__doc__
194
+ and ".. deprecated::" not in wrapper.__doc__
195
+ ):
196
+ txt = deprecated or ""
197
+ if removed or replacement:
198
+ txt += "\n "
199
+ if removed:
200
+ txt += "and will be removed in version %s" % (removed,)
201
+ if replacement:
202
+ if removed:
203
+ txt += ", "
204
+ txt += "use %s instead" % replacement
205
+ txt += "."
206
+ if not wrapper.__doc__.strip(" ").endswith("\n"):
207
+ wrapper.__doc__ += "\n"
208
+ wrapper.__doc__ += "\n.. deprecated:: %s\n" % (txt,)
209
+ if is_classmethod:
210
+ wrapper = classmethod(wrapper)
211
+ return wrapper
212
+
213
+ return build
214
+
215
+
216
+ def deprecated_method(
217
+ msg=None, deprecated=None, removed=None, updoc=True, replacement=None
218
+ ):
219
+ """decorator to deprecate a method.
220
+
221
+ :arg msg: optional msg, default chosen if omitted
222
+ :kwd deprecated: version when method was first deprecated
223
+ :kwd removed: version when method will be removed
224
+ :kwd replacement: alternate name / instructions for replacing this method.
225
+ :kwd updoc: add notice to docstring (default ``True``)
226
+ """
227
+ return deprecated_function(
228
+ msg, deprecated, removed, updoc, replacement, _is_method=True
229
+ )
230
+
231
+
232
+ # =============================================================================
233
+ # eof
234
+ # =============================================================================
passlib/utils/des.py ADDED
@@ -0,0 +1,35 @@
1
+ """
2
+ passlib.utils.des - DEPRECATED LOCATION, WILL BE REMOVED IN 2.0
3
+
4
+ This has been moved to :mod:`passlib.crypto.des`.
5
+ """
6
+
7
+ from warnings import warn
8
+
9
+ from passlib.utils.decor import deprecated_function
10
+ from passlib.crypto.des import expand_des_key, des_encrypt_block, des_encrypt_int_block
11
+
12
+ warn(
13
+ "the 'passlib.utils.des' module has been relocated to 'passlib.crypto.des' "
14
+ "as of passlib 1.7, and the old location will be removed in passlib 2.0",
15
+ DeprecationWarning,
16
+ )
17
+
18
+
19
+ expand_des_key = deprecated_function(
20
+ deprecated="1.7", removed="2.0", replacement="passlib.crypto.des.expand_des_key"
21
+ )(expand_des_key)
22
+
23
+ des_encrypt_block = deprecated_function(
24
+ deprecated="1.7", removed="2.0", replacement="passlib.crypto.des.des_encrypt_block"
25
+ )(des_encrypt_block)
26
+
27
+ des_encrypt_int_block = deprecated_function(
28
+ deprecated="1.7",
29
+ removed="2.0",
30
+ replacement="passlib.crypto.des.des_encrypt_int_block",
31
+ )(des_encrypt_int_block)
32
+
33
+ # =============================================================================
34
+ # eof
35
+ # =============================================================================