o
    _6dMO                     @   s  d Z ddlZddlZeeZddlmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZ g d
ZG dd deZe Ze ZejZe di ddddddddddddddddddddddddd dd!dd"d#d$d#d%d#d&d#d'd#d(d#d)d#d*d#d+d#d,dd-d.d/dd0d1d2d1d3d1d4d1d5d1d6d1d7d8d9d8d:d8d;d<d=d<d>d8d?d8d@d8dAd8dBd8dCd8dDd8dEd8dFd8dGd8dHd8dIddJddKddLddMddNddOddPdQdRdQdSdTdUdTdVddWdXdYdXdZdd[dd\dd]d^d_d`dadbdcd<dddedfdgdhdidjdkdldkdmdndod`dpd`Z!e"dqZ#e$g drZ%dsdt Z&dudv Z'ddxdyZ(efdzd{Z)dd|d}Z*dd~dZ+dddZ,dddZ-dZ.dZ/dZ0e.dwfddZ1edd Z2dd Z3dS )z6passlib.registry - registry for password hash handlers    N)warn)exc)ExpectedTypeErrorPasslibWarning)PasswordHash)is_crypt_handler	has_cryptunix_crypt_schemes)unicode_or_str)memoize_single_value)register_crypt_handler_pathregister_crypt_handlerget_crypt_handlerlist_crypt_handlersc                   @   s8   e Zd ZdZdZ dZdd Zdd Zdd	 Zd
d ZdS )_PasslibRegistryProxyzproxy 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`.
    zpasslib.hashNc                 C   s8   | drtd|f t|d }|r|S td|f )N_zmissing attribute: %rzunknown password hash: %r)
startswithAttributeErrorr   )selfattrhandler r   gC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\passlib/registry.py__getattr__(   s   

z!_PasslibRegistryProxy.__getattr__c                 C   s,   | drt| || d S t||d d S )Nr   _attr)r   object__setattr__r   )r   r   valuer   r   r   r   1   s   
z!_PasslibRegistryProxy.__setattr__c                 C   s   dS )Nz<proxy module 'passlib.hash'>r   )r   r   r   r   __repr__;   s   z_PasslibRegistryProxy.__repr__c                 C   s,   t t| j}|| j |t t|S N)setdir	__class__update__dict__
_locationssorted)r   attrsr   r   r   __dir__>   s   
z_PasslibRegistryProxy.__dir__)	__name__
__module____qualname____doc____package__r   r   r   r)   r   r   r   r   r      s    	
r   Zapr_md5_cryptzpasslib.handlers.md5_cryptZargon2zpasslib.handlers.argon2Zatlassian_pbkdf2_sha1zpasslib.handlers.pbkdf2Zbcryptzpasslib.handlers.bcryptZbcrypt_sha256Zbigcryptzpasslib.handlers.des_cryptZ
bsd_nthashzpasslib.handlers.windowsZ
bsdi_cryptZ	cisco_pixzpasslib.handlers.ciscoZ	cisco_asaZcisco_type7Zcta_pbkdf2_sha1Zcrypt16Z	des_cryptZdjango_argon2zpasslib.handlers.djangoZdjango_bcryptZdjango_bcrypt_sha256Zdjango_pbkdf2_sha256Zdjango_pbkdf2_sha1Zdjango_salted_sha1Zdjango_salted_md5Zdjango_des_cryptZdjango_disabledZdlitz_pbkdf2_sha1Zfshpzpasslib.handlers.fshpZgrub_pbkdf2_sha512Zhex_md4zpasslib.handlers.digestsZhex_md5Zhex_sha1Z
hex_sha256Z
hex_sha512ZhtdigestZldap_plaintextzpasslib.handlers.ldap_digestsZldap_md5Z	ldap_sha1Zldap_hex_md5zpasslib.handlers.roundupZldap_hex_sha1Zldap_salted_md5Zldap_salted_sha1Zldap_salted_sha256Zldap_salted_sha512Zldap_des_cryptZldap_bsdi_cryptZldap_md5_cryptZldap_bcryptZldap_sha1_cryptZldap_sha256_cryptZldap_sha512_cryptZldap_pbkdf2_sha1Zldap_pbkdf2_sha256Zldap_pbkdf2_sha512ZlmhashZ	md5_cryptZmsdccZmsdcc2Z	mssql2000zpasslib.handlers.mssqlZ	mssql2005Zmysql323zpasslib.handlers.mysqlZmysql41ZnthashZoracle10zpasslib.handlers.oracleZoracle11Zpbkdf2_sha1Zpbkdf2_sha256Zpbkdf2_sha512Zphpasszpasslib.handlers.phpassZ	plaintextzpasslib.handlers.miscZpostgres_md5zpasslib.handlers.postgresZroundup_plaintextZscramzpasslib.handlers.scramscryptzpasslib.handlers.scryptZ
sha1_cryptzpasslib.handlers.sha1_cryptZsha256_cryptzpasslib.handlers.sha2_cryptZsha512_cryptZsun_md5_cryptzpasslib.handlers.sun_md5_cryptZunix_disabledZunix_fallbackz^[a-z][a-z0-9_]+[a-z0-9]$)Zonloadpolicycontextalldefaultnoneautoc                 C   st   | s	t d| f |  | krt d| f t| s"t d| f d| v r-t d| f | tv r8t d| f dS )zhelper 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``).
    z handler name cannot be empty: %rzname must be lower-case: %rz`invalid name (must be 3+ characters,  begin with a-z, and contain only underscore, a-z, 0-9): %r__z+name may not contain double-underscores: %rzthat name is not allowed: %rT)
ValueErrorlower_name_rematch_forbidden_names)namer   r   r   _validate_handler_name   s   	
r=   c                 C   sp   t |  |drtdd|v r+|ddkrtd|d|ddkr+td|t| < td| | d	S )
av  register location to lazy-load handler when requested.

    custom hashes may be registered via :func:`register_crypt_handler`,
    or they may be registered by this function,
    which will delay actually importing and loading the handler
    until a call to :func:`get_crypt_handler` is made for the specified name.

    :arg name: name of handler
    :arg path: module import path

    the specified module path should contain a password hash handler
    called :samp:`{name}`, or the path may contain a colon,
    specifying the module and module attribute to use.
    for example, the following would cause ``get_handler("myhash")`` to look
    for a class named ``myhash`` within the ``myapp.helpers`` module::

        >>> 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")
    .zpath cannot start with '.':   z"path cannot have more than one ':'z$path cannot have '.' to right of ':'z!registered path to %r handler: %rN)	r=   r   r7   countfindindexr&   logdebug)r<   pathr   r   r   r      s   
r   Fc                 C   s   t | s
t| dd| std| j}t| |r%||kr%td||f t|}|rK|| u r9t	d||  dS |rCt
d|| ntd||f | t|< t	d	||  dS )
a@  register password hash handler.

    this method immediately registers a handler with the internal passlib registry,
    so that it will be returned by :func:`get_crypt_handler` when requested.

    :arg handler: the password hash handler to register
    :param force: force override of existing handler (defaults to False)
    :param _attr:
        [internal kwd] if specified, ensures ``handler.name``
        matches this value, or raises :exc:`ValueError`.

    :raises TypeError:
        if the specified object does not appear to be a valid handler.

    :raises ValueError:
        if the specified object's name (or other required attributes)
        contain invalid values.

    :raises KeyError:
        if a (different) handler was already registered with
        the same name, and ``force=True`` was not specified.
    zpassword hash handlerr   z``bool(handler)`` must be Truez<handlers must be stored only under their own name (%r != %r)z&same %r handler already registered: %rNz/overriding previously registered %r handler: %rz2another %r handler has already been registered: %rzregistered %r handler: %r)r   r   AssertionErrorr<   r=   r7   	_handlersgetrE   rF   warningKeyError)r   forcer   r<   otherr   r   r   r      s0   
r   c                 C   sB  |  dr|tu rtd| f |S zt|  W S  ty    Y nw t| ts*J d| dd }|| krRtd| |f t	dd |} zt|  W S  tyQ   Y nw t
| }|rd|v re|d\}}n|| }}t||gd	d
}t| }|rt|sJ d| |f |S t||}t|| d |S |tu rtd| f |S )a'  return handler for specified password hash scheme.

    this method looks up a handler for the specified scheme.
    if the handler is not already loaded,
    it checks if the location is known, and loads it first.

    :arg name: name of handler to return
    :param default: optional default value to return if no handler with specified name is found.

    :raises KeyError: if no handler matching that name is found, and no default specified, a KeyError will be raised.

    :returns: handler attached to name, or default value (if specified).
    r   zinvalid handler name: %rzname must be string instance-zThandler names should be lower-case, and use underscores instead of hyphens: %r => %r   )
stacklevelr?   r   )fromlistlevelz$unexpected object: name=%r object=%rr   z(no crypt handler found for algorithm: %r)r   _UNSETrL   rI   
isinstancer
   replacer8   r   r   r&   rJ   split
__import__r   getattrr   )r<   r3   ZaltrG   modnameZmodattrmodr   r   r   r   r   *  sP   






r   c                 C   s(   t t}| s|t tdd |D S )zreturn 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
    c                 s   s    | ]
}| d s|V  qdS )r   N)r   .0r<   r   r   r   	<genexpr>  s    z&list_crypt_handlers.<locals>.<genexpr>)r!   rI   r$   r&   r'   )loaded_onlynamesr   r   r   r   u  s   
r   c                 C   s   | t v p
| o
| tv S )aA  check 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
    rI   r&   )r<   r_   r   r   r   _has_crypt_handler  s   rb   Tc                 C   s,   | t v rt | = |r| tv rt| = dS dS dS )a  unloads 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)
    Nra   )r<   	locationsr   r   r   _unload_handler_name  s
   
rd   r   c                 C   s,   t | r| S t| trt| S t| t|)z>
    internal helper to resolve argument to hasher object
    )r   rU   r
   r   r   r   )hasherparamr   r   r   _resolve  s
   
rg   anybuiltinZos_cryptc                 C   s   t | } |tkr"t| dsdS z|   W dS  tjy!   Y dS w t| dr5|r0|| jvr0dS | |S |tkr;dS |r?dS t	| |)a  
    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.
    get_backendTFhas_backendN)
rg   ANYhasattrrj   r   ZMissingBackendErrorbackendsrk   BUILTINZUnknownBackendError)re   backendsafer   r   r   rk     s&   


rk   c                  C   sF   t sdS tdd tD } | s!ddl}td| | f tj | S )zN
    return tuple of schemes which :func:`crypt.crypt` natively supports.
    r   c                 s   s"    | ]}t |tr|V  qd S r    )r   rk   OS_CRYPTr\   r   r   r   r^     s    z1get_supported_os_crypt_schemes.<locals>.<genexpr>r   Nzkcrypt.crypt() function is present, but doesn't support any formats known to passlib! (system=%r release=%r))	os_crypt_presenttupleos_crypt_schemesplatformr   systemreleaser   ZPasslibRuntimeWarning)cacherv   r   r   r   get_supported_os_crypt_schemes   s   rz   c                 C   s   t ot| tddS )a  
    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.
    T)rq   )rs   rk   rr   )re   r   r   r   has_os_crypt_support  s   r{   r   )FN)F)T)r   )4r-   relogging	getLoggerr*   rE   warningsr   Zpasslibr   Zpasslib.excr   r   Zpasslib.ifcr   Zpasslib.utilsr   r   rs   r	   ru   Zpasslib.utils.compatr
   Zpasslib.utils.decorr   __all__r   r   _proxyrT   r%   rI   dictr&   compiler9   	frozensetr;   r=   r   r   r   r   rb   rd   rg   rl   ro   rr   rk   rz   r{   r   r   r   r   <module>   sv   
)	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO
S
*5
K


>
