summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin/regen.py106
-rw-r--r--passlib/hash.py52
2 files changed, 152 insertions, 6 deletions
diff --git a/admin/regen.py b/admin/regen.py
new file mode 100644
index 0000000..dc4b2fb
--- /dev/null
+++ b/admin/regen.py
@@ -0,0 +1,106 @@
+"""
+helper script which rebuilds all autogenerated bits of code w/in passlib.
+"""
+#=============================================================================
+# imports
+#=============================================================================
+# core
+from __future__ import absolute_import, division, print_function
+import datetime
+import re
+import os
+# all
+__all__ = [
+ "main",
+ "replace_section",
+]
+
+#=============================================================================
+# helpers
+#=============================================================================
+
+now = datetime.datetime.now().strftime("%Y-%m-%d")
+
+def replace_section(data, ident, content):
+ """
+ helper to replace autogenerated section of content.
+
+ :param data:
+ existing file contents
+
+ :param ident:
+ identifying string for section start and end.
+ will look for "begin <ident>" section marker,
+ and "end <ident>" section marker.
+
+ :param content:
+ replacement content to replace whatever's present
+ between section start & end.
+
+ :returns:
+ modified data
+ """
+ m = re.match(r"""(?ixms)
+ (?P<head>.*?\n)
+ \#[-=]{10,}\n
+ \# \s begin \s* %(ident)s .* \n
+ \#[-=]{10,}\n
+ .*?
+ \#[-=]{10,}\n
+ \# \s end \s* %(ident)s \s* \n
+ \#[-=]{10,}\n
+ (?P<tail>.*)
+ """ % dict(ident=re.escape(ident).replace("\\ ", "\\s+"),),
+ data.replace("\r\n", "\n"))
+ assert m, "%r section not found" % (ident,)
+
+ begin_row = "# begin " + ident + " (autogenerated " + now + ")\n"
+
+ head, tail = m.group("head", "tail")
+ divline = "#" + "-" * max(40, len(begin_row) - 1) + "\n"
+ return "".join([
+ head,
+ divline,
+ begin_row,
+ divline,
+ content,
+ divline,
+ "# end ", ident, "\n",
+ divline,
+ tail,
+ ])
+
+#=============================================================================
+# main
+#=============================================================================
+
+from passlib.hash import sha256_crypt
+
+source_dir = os.path.abspath(os.path.join(__file__, *[".."]*2))
+
+def main():
+ """rebuild autogenerated sections in passlib"""
+
+ #------------------------------------------------
+ # rebuild autocomplete helper in passlib/hash.py
+ #------------------------------------------------
+ content = "if False:\n"
+ from passlib.registry import _locations
+ modules = {}
+ for name, path in _locations.items():
+ modules.setdefault(path, []).append(name)
+ for path, names in sorted(modules.items()):
+ row = " from %s import %s\n" % (path, ", ".join(sorted(names)))
+ content += row
+
+ hash_path = os.path.join(source_dir, "passlib", "hash.py")
+ data = open(hash_path).read()
+ data = replace_section(data, "autocomplete hack", content)
+ open(hash_path, "w").write(data)
+
+if __name__ == "__main__":
+ main()
+
+#=============================================================================
+# eof
+#=============================================================================
diff --git a/passlib/hash.py b/passlib/hash.py
index ec601c1..9b72448 100644
--- a/passlib/hash.py
+++ b/passlib/hash.py
@@ -1,7 +1,10 @@
-"""passlib.hash - proxy object mapping hash scheme names -> handlers
+"""
+passlib.hash - proxy object mapping hash scheme names -> handlers
+
+==================
+***** NOTICE *****
+==================
-Note
-====
This module does not actually contain any hashes. This file
is a stub that replaces itself with a proxy object.
@@ -12,17 +15,54 @@ The actual implementation of the various hashes is store elsewhere,
mainly in the submodules of the ``passlib.handlers`` subpackage.
"""
-# XXX: if any platform has problem w/ lazy modules, could support 'non-lazy'
-# version which just imports all schemes known to list_crypt_handlers()
-
#=============================================================================
# import proxy object and replace this module
#=============================================================================
+# XXX: if any platform has problem w/ lazy modules, could support 'non-lazy'
+# version which just imports all schemes known to list_crypt_handlers()
+
from passlib.registry import _proxy
import sys
sys.modules[__name__] = _proxy
#=============================================================================
+# HACK: the following bit of code is unreachable, but it's presence seems to
+# help make autocomplete work for certain IDEs such as PyCharm.
+# this list is automatically regenerated using $SOURCE/admin/regen.py
+#=============================================================================
+
+#----------------------------------------------------
+# begin autocomplete hack (autogenerated 2016-11-10)
+#----------------------------------------------------
+if False:
+ from passlib.handlers.argon2 import argon2
+ from passlib.handlers.bcrypt import bcrypt, bcrypt_sha256
+ from passlib.handlers.cisco import cisco_asa, cisco_pix, cisco_type7
+ from passlib.handlers.des_crypt import bigcrypt, bsdi_crypt, crypt16, des_crypt
+ from passlib.handlers.digests import hex_md4, hex_md5, hex_sha1, hex_sha256, hex_sha512, htdigest
+ from passlib.handlers.django import django_bcrypt, django_bcrypt_sha256, django_des_crypt, django_disabled, django_pbkdf2_sha1, django_pbkdf2_sha256, django_salted_md5, django_salted_sha1
+ from passlib.handlers.fshp import fshp
+ from passlib.handlers.ldap_digests import ldap_bcrypt, ldap_bsdi_crypt, ldap_des_crypt, ldap_md5, ldap_md5_crypt, ldap_plaintext, ldap_salted_md5, ldap_salted_sha1, ldap_sha1, ldap_sha1_crypt, ldap_sha256_crypt, ldap_sha512_crypt
+ from passlib.handlers.md5_crypt import apr_md5_crypt, md5_crypt
+ from passlib.handlers.misc import plaintext, unix_disabled, unix_fallback
+ from passlib.handlers.mssql import mssql2000, mssql2005
+ from passlib.handlers.mysql import mysql323, mysql41
+ from passlib.handlers.oracle import oracle10, oracle11
+ from passlib.handlers.pbkdf2 import atlassian_pbkdf2_sha1, cta_pbkdf2_sha1, dlitz_pbkdf2_sha1, grub_pbkdf2_sha512, ldap_pbkdf2_sha1, ldap_pbkdf2_sha256, ldap_pbkdf2_sha512, pbkdf2_sha1, pbkdf2_sha256, pbkdf2_sha512
+ from passlib.handlers.phpass import phpass
+ from passlib.handlers.postgres import postgres_md5
+ from passlib.handlers.roundup import ldap_hex_md5, ldap_hex_sha1, roundup_plaintext
+ from passlib.handlers.scram import scram
+ from passlib.handlers.scrypt import scrypt
+ from passlib.handlers.sha1_crypt import sha1_crypt
+ from passlib.handlers.sha2_crypt import sha256_crypt, sha512_crypt
+ from passlib.handlers.sun_md5_crypt import sun_md5_crypt
+ from passlib.handlers.windows import bsd_nthash, lmhash, msdcc, msdcc2, nthash
+#----------------------------------------------------
+# end autocomplete hack
+#----------------------------------------------------
+
+#=============================================================================
# eoc
#=============================================================================