Xc@sdZddlZddlZejeZddlmZddlm Z ddl m Z m Z ddl mZddlmZmZmZddlmZdd lmZd d d d gZdefdYZeZeZejZe ddddddddddddddddddd dd!dd"dd#dd$dd%d&d'd&d(d&d)d&d*d&d+d&d,d&d-d&d.d&d/dd0d1d2dd3d4d5d4d6d4d7d4d8d4d9d4d:d;d<d;d=d;d>d?d@d?dAd;dBd;dCd;dDd;dEd;dFd;dGd;dHd;dId;dJddKddLddMddNddOddPddQdRdSdRdTdUdVdUdWddXdYdZdYd[dd\dd]dd^d_d`dadbdcddd?dedfdgdhdidjdkdldmdldndodpdadqdaKZ!ej"drZ#e$dsdtdudvdwdxdygZ%dzZ&d{Z'e(dd|Z*ed}Z+e(d~Z,e(dZ-e.dZ/ddZ0dZ1dZ2dZ3e1e(dZ4edZ5dZ6dS(s6passlib.registry - registry for password hash handlersiN(twarn(texc(tExpectedTypeErrortPasslibWarning(t PasswordHash(tis_crypt_handlert has_crypttunix_crypt_schemes(tunicode_or_str(tmemoize_single_valuetregister_crypt_handler_pathtregister_crypt_handlertget_crypt_handlertlist_crypt_handlerst_PasslibRegistryProxycBs>eZdZdZdZdZdZdZdZRS(sproxy module passlib.hash this module is in fact an object which lazy-loads the requested password hash algorithm from wherever it has been stored. it acts as a thin wrapper around :func:`passlib.registry.get_crypt_handler`. s passlib.hashcCsU|jdr%td|fnt|d}|r>|Std|fdS(Nt_smissing attribute: %rsunknown password hash: %r(t startswithtAttributeErrorR tNone(tselftattrthandler((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt __getattr__(s cCs9|jdr%tj|||nt|d|dS(NRt_attr(Rtobjectt __setattr__R (RRtvalue((s4/usr/lib/python2.7/site-packages/passlib/registry.pyR1scCsdS(Ns((R((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt__repr__;scCs<tt|j}|j|j|jtt|S(N(tsettdirt __class__tupdatet__dict__t _locationstsorted(Rtattrs((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt__dir__>s N( t__name__t __module__t__doc__Rt __package__RRRR$(((s4/usr/lib/python2.7/site-packages/passlib/registry.pyRs t apr_md5_cryptspasslib.handlers.md5_crypttargon2spasslib.handlers.argon2tatlassian_pbkdf2_sha1spasslib.handlers.pbkdf2tbcryptspasslib.handlers.bcryptt bcrypt_sha256tbigcryptspasslib.handlers.des_cryptt bsd_nthashspasslib.handlers.windowst bsdi_cryptt cisco_pixspasslib.handlers.ciscot cisco_asat cisco_type7tcta_pbkdf2_sha1tcrypt16t des_cryptt django_argon2spasslib.handlers.djangot django_bcrypttdjango_bcrypt_sha256tdjango_pbkdf2_sha256tdjango_pbkdf2_sha1tdjango_salted_sha1tdjango_salted_md5tdjango_des_crypttdjango_disabledtdlitz_pbkdf2_sha1tfshpspasslib.handlers.fshptgrub_pbkdf2_sha512thex_md4spasslib.handlers.digeststhex_md5thex_sha1t hex_sha256t hex_sha512thtdigesttldap_plaintextspasslib.handlers.ldap_digeststldap_md5t ldap_sha1t ldap_hex_md5spasslib.handlers.roundupt ldap_hex_sha1tldap_salted_md5tldap_salted_sha1tldap_des_crypttldap_bsdi_crypttldap_md5_cryptt ldap_bcrypttldap_sha1_crypttldap_sha256_crypttldap_sha512_crypttldap_pbkdf2_sha1tldap_pbkdf2_sha256tldap_pbkdf2_sha512tlmhasht md5_crypttmsdcctmsdcc2t mssql2000spasslib.handlers.mssqlt mssql2005tmysql323spasslib.handlers.mysqltmysql41tnthashtoracle10spasslib.handlers.oracletoracle11t pbkdf2_sha1t pbkdf2_sha256t pbkdf2_sha512tphpassspasslib.handlers.phpasst plaintextspasslib.handlers.misct postgres_md5spasslib.handlers.postgrestroundup_plaintexttscramspasslib.handlers.scramtscryptspasslib.handlers.scryptt sha1_cryptspasslib.handlers.sha1_cryptt sha256_cryptspasslib.handlers.sha2_cryptt sha512_cryptt sun_md5_cryptspasslib.handlers.sun_md5_cryptt unix_disabledt unix_fallbacks^[a-z][a-z0-9_]+[a-z0-9]$tonloadtpolicytcontexttalltdefaulttnonetautocCs|std|fn|j|krDtd|fntj|sitd|fnd|krtd|fn|tkrtd|fntS(shelper to validate handler name :raises ValueError: * if empty name * if name not lower case * if name contains double underscores * if name is reserved (e.g. ``context``, ``all``). s handler name cannot be empty: %rsname must be lower-case: %rs`invalid name (must be 3+ characters, begin with a-z, and contain only underscore, a-z, 0-9): %rt__s+name may not contain double-underscores: %rsthat name is not allowed: %r(t ValueErrortlowert_name_retmatcht_forbidden_namestTrue(tname((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt_validate_handler_names   cCst||jdr(tdnd|kr|jddkrXtdn|jd|jddkrtdqn|t|>> from passlib.registry import registry_crypt_handler_path >>> registry_crypt_handler_path("myhash", "myapp.helpers") ...while this form would cause ``get_handler("myhash")`` to look for a class name ``MyHash`` within the ``myapp.helpers`` module:: >>> from passlib.registry import registry_crypt_handler_path >>> registry_crypt_handler_path("myhash", "myapp.helpers:MyHash") t.spath cannot start with '.'t:is"path cannot have more than one ':'is$path cannot have '.' to right of ':'s!registered path to %r handler: %rN( RRR|tcounttfindtindexR!tlogtdebug(Rtpath((s4/usr/lib/python2.7/site-packages/passlib/registry.pyR s  ! cCst|s!t|ddn|s6tdn|j}t||rt||krttd||fntj|}|r||krtj d||dS|rtj d||qt d||fn|t| %rt stackleveliRtfromlisttleveliRs(no crypt handler found for algorithm: %rN(Rt_UNSETRRtreplaceR}RRR!Rtsplitt __import__tgetattrR (RRxtaltRtmodnametmodattrtmodR((s4/usr/lib/python2.7/site-packages/passlib/registry.pyR (sB         cCs6tt}|s"|jtntd|DS(sreturn sorted list of all known crypt handler names. :param loaded_only: if ``True``, only returns names of handlers which have actually been loaded. :returns: list of names of all known handlers css$|]}|jds|VqdS(RN(R(t.0R((s4/usr/lib/python2.7/site-packages/passlib/registry.pys s(RRRR!R"(t loaded_onlytnames((s4/usr/lib/python2.7/site-packages/passlib/registry.pyR ss cCs|tkp| o|tkS(sAcheck if handler name is known. this is only useful for two cases: * quickly checking if handler has already been loaded * checking if handler exists, without actually loading it :arg name: name of handler :param loaded_only: if ``True``, returns False if handler exists but hasn't been loaded (RR!(RR((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt_has_crypt_handlers cCs6|tkrt|=n|r2|tkr2t|=ndS(sunloads a handler from the registry. .. warning:: this is an internal function, used only by the unittests. if loaded handler is found with specified name, it's removed. if path to lazy load handler is found, it's removed. missing names are a noop. :arg name: name of handler to unload :param locations: if False, won't purge registered handler locations (default True) N(RR!(Rt locations((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt_unload_handler_names  RcCsBt|r|St|tr)t|Stj|t|dS(s> internal helper to resolve argument to hasher object N(Rt isinstanceRR RR(thashertparam((s4/usr/lib/python2.7/site-packages/passlib/registry.pyt_resolves   tanytbuiltintos_cryptcCst|}|tkrXt|ds+tSy|jtSWqXtjk rTtSXnt|dr|r||jkrdS|j |S|t krtS|rdStj ||dS(s Test if specified backend is available for hasher. :param hasher: Hasher name or object. :param backend: Name of backend, or ``"any"`` if any backend will do. For hashers without multiple backends, will pretend they have a single backend named ``"builtin"``. :param safe: By default, throws error if backend is unknown. If ``safe=True``, will just return false value. :raises ValueError: * if hasher name is unknown. * if backend is unknown to hasher, and safe=False. :return: True if backend available, False if not available, and None if unknown + safe=True. t get_backendt has_backendN( RtANYthasattrRRRtMissingBackendErrortFalsetbackendsRRtBUILTINtUnknownBackendError(Rtbackendtsafe((s4/usr/lib/python2.7/site-packages/passlib/registry.pyRs$     cCs=ts dStdtD}|s9tdtjn|S(sN return tuple of schemes which :func:`crypt.crypt` natively supports. css*|] }t|jtr|VqdS(N(R RtOS_CRYPT(RR((s4/usr/lib/python2.7/site-packages/passlib/registry.pys ssTcrypt.crypt() function is present, but doesn't support any formats known to passlib!((tos_crypt_presentttupletos_crypt_schemesRRtPasslibRuntimeWarning(tcache((s4/usr/lib/python2.7/site-packages/passlib/registry.pytget_supported_os_crypt_schemess cCstot|tdtS(s check if hash is supported by native :func:`crypt.crypt` function. if :func:`crypt.crypt` is not present, will always return False. :param hasher: name or hasher object. :returns bool: True if hash format is supported by OS, else False. R(RRRR(R((s4/usr/lib/python2.7/site-packages/passlib/registry.pythas_os_crypt_supports (7R'tretloggingt getLoggerR%RtwarningsRtpasslibRt passlib.excRRt passlib.ifcRt passlib.utilsRRRRRtpasslib.utils.compatRtpasslib.utils.decorR t__all__RRt_proxyRR RtdictR!tcompileR~t frozensetRRR RRR R R RRRRRRRRRR(((s4/usr/lib/python2.7/site-packages/passlib/registry.pyts   )      *5 K   >