B
    d-                 @   s   U d dl Z d dlZd dlZd dlZd dlZd dlZejr8dZdZ	e
dd ejejjgD Zeje ed< eeddd	Zeeeejeef d
ddZdeeeedddZeeedddZeeeje dddZdS )    NZ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789i c             c   s"   | ]}|d k	r|dkr|V  qd S )N/ ).0sepr   r   C/var/www/html/venv/lib/python3.7/site-packages/werkzeug/security.py	<genexpr>   s    r   _os_alt_seps)lengthreturnc             C   s(   | dkrt dddd t| D S )zAGenerate a random string of SALT_CHARS with specified ``length``.r   zSalt length must be positive c             s   s   | ]}t tV  qd S )N)secretschoice
SALT_CHARS)r   _r   r   r   r      s    zgen_salt.<locals>.<genexpr>)
ValueErrorjoinrange)r	   r   r   r   gen_salt   s    r   )methodsaltpasswordr
   c             C   s   | dkr|| fS | d}| d}| dr|s:td| dd d}t|dkr`td	|d
} |r~t|d
 pzd
nt}t	| |||
 d|  d| fS |rt|||  | fS t| | | fS )zInternal password hash helper.  Supports plaintext without salt,
    unsalted and salted passwords.  In case salted passwords are used
    hmac is used.
    plainzutf-8zpbkdf2:zSalt is required for PBKDF2   N:)      z&Invalid number of arguments for PBKDF2r   )encode
startswithr   splitlenpopintDEFAULT_PBKDF2_ITERATIONShashlibpbkdf2_hmachexhmacnew	hexdigest)r   r   r   argsZ
iterationsr   r   r   _hash_internal   s"    



r*   pbkdf2:sha256   )r   r   salt_lengthr
   c             C   s8   |dkrt |nd}t||| \}}| d| d| S )a  Hash a password with the given method and salt with a string of
    the given length. The format of the string returned includes the method
    that was used so that :func:`check_password_hash` can check the hash.

    The format for the hashed string looks like this::

        method$salt$hash

    This method can **not** generate unsalted passwords but it is possible
    to set param method='plain' in order to enforce plaintext passwords.
    If a salt is used, hmac is used internally to salt the password.

    If PBKDF2 is wanted it can be enabled by setting the method to
    ``pbkdf2:method:iterations`` where iterations is optional::

        pbkdf2:sha256:80000$salt$hash
        pbkdf2:sha256$salt$hash

    :param password: the password to hash.
    :param method: the hash method to use (one that hashlib supports). Can
                   optionally be in the format ``pbkdf2:method:iterations``
                   to enable PBKDF2.
    :param salt_length: the length of the salt in letters.
    r   r   $)r   r*   )r   r   r-   r   hZactual_methodr   r   r   generate_password_hash<   s    r0   )pwhashr   r
   c             C   s<   |  ddk rdS | dd\}}}tt|||d |S )a  Check a password against a given salted and hashed password value.
    In order to support unsalted legacy passwords this method supports
    plain text passwords, md5 and sha1 hashes (both salted and unsalted).

    Returns `True` if the password matched, `False` otherwise.

    :param pwhash: a hashed string like returned by
                   :func:`generate_password_hash`.
    :param password: the plaintext password to compare against the hash.
    r.   r   Fr   )countr   r&   compare_digestr*   )r1   r   r   r   Zhashvalr   r   r   check_password_hash\   s    r4   )	directory	pathnamesr
   c                sz   | sd} | g}x`|D ]X  dkr*t   t fddtD s^tj s^ dks^ drbdS |  qW t j	| S )a2  Safely join zero or more untrusted path components to a base
    directory to avoid escaping the base directory.

    :param directory: The trusted base directory.
    :param pathnames: The untrusted path components relative to the
        base directory.
    :return: A safe path, otherwise ``None``.
    .r   c             3   s   | ]}| kV  qd S )Nr   )r   r   )filenamer   r   r      s    zsafe_join.<locals>.<genexpr>z..z../N)
	posixpathnormpathanyr   ospathisabsr   appendr   )r5   r6   partsr   )r8   r   	safe_joinn   s    	


rA   )r+   r,   )r#   r&   r<   r9   r   typingtTYPE_CHECKINGr   r"   listr   r=   altsepr   Liststr__annotations__r!   r   Tupler*   r0   boolr4   OptionalrA   r   r   r   r   <module>   s"    ("