
Lac           @  s  d  Z  d d l m Z d d l Z e j e  Z d d l Z d d l m	 Z	 d d l
 m Z m Z d d l m Z d d l 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 m Z m Z m Z d d g Z e   Z  d Z! d Z" d Z# d Z$ d Z% d e f d     YZ& e'   Z( d   Z) e)   Z* d   Z+ e+   Z, d e& f d     YZ- d e& f d     YZ. d S(   s(   passlib.apache - apache password supporti(   t   with_statementN(   t   warn(   t   exct   registry(   t   CryptContext(   t   ExpectedStringError(   t   htdigest(   t   render_bytest   to_bytest   is_ascii_codec(   t   deprecated_method(   t
   join_bytest   unicodet   BytesIOt   PY3t   HtpasswdFilet   HtdigestFilet   :t   #s   :
	 t   skippedt   recordt   _CommonFilec           B  s=  e  Z d  Z d Z d Z d Z d Z e Z	 d Z
 d Z e d    Z e d    Z d e e e d e d  Z d   Z e d    Z e j d    Z e d    Z d	   Z d e d
  Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z  d   Z! d   Z" d   Z# d d  Z$ d   Z% RS(   s0   common framework for HtpasswdFile & HtdigestFilec         K  s8   d | k r t  d   n  |  |   } | j |  | S(   s   create new object from raw string.

        :type data: unicode or bytes
        :arg data:
            database to load, as single string.

        :param \*\*kwds:
            all other keywords are the same as in the class constructor
        t   paths$   'path' not accepted by from_string()(   t	   TypeErrort   load_string(   t   clst   datat   kwdst   self(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   from_stringK   s
    c         K  s   |  |   } | j  |  | S(   s   create new object from file, without binding object to file.

        :type path: str
        :arg path:
            local filepath to load from

        :param \*\*kwds:
            all other keywords are the same as in the class constructor
        (   t   load(   R   R   R   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt	   from_path\   s    s   utf-8c         C  s   | s( t  d t d d d } t } n t |  sC t d   n  | |  _ | |  _ | |  _ | |  _ d |  _	 | s t  d t d d t
 } n  | r | r |  j   n i  |  _ g  |  _ d  S(   Ns   ``encoding=None`` is deprecated as of Passlib 1.6, and will cause a ValueError in Passlib 1.8, use ``return_unicode=False`` instead.t
   stackleveli   s   utf-8s'   encoding must be 7-bit ascii compatiblei    sp   ``autoload=False`` is deprecated as of Passlib 1.6, and will be removed in Passlib 1.8, use ``new=True`` instead(   R   t   DeprecationWarningt   FalseR	   t
   ValueErrort   encodingt   return_unicodet   autosavet   _patht   _mtimet   TrueR   t   _recordst   _source(   R   R   t   newt   autoloadR&   R$   R%   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   __init__n   s(    								c         C  sy   d } |  j  r | d 7} n  |  j r9 | d |  j 7} n  |  j d k r\ | d |  j 7} n  d |  j j t |   | f S(   Nt    s    autosave=Trues    path=%rs   utf-8s    encoding=%rs   <%s 0x%0x%s>(   R&   R'   R$   t	   __class__t   __name__t   id(   R   t   tail(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   __repr__   s    		c         C  s   |  j  S(   N(   R'   (   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR      s    c         C  s(   | |  j  k r d |  _ n  | |  _  d  S(   Ni    (   R'   R(   (   R   t   value(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR      s    c         C  s   |  j  S(   s7   modify time when last loaded (if bound to a local file)(   R(   (   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   mtime   s    c         C  sU   |  j  s t d |    n  |  j rG |  j t j j |  j   k rG t S|  j   t S(   sB   Reload from ``self.path`` only if file has changed since last loads   %r is not bound to a local file(	   R'   t   RuntimeErrorR(   t   osR   t   getmtimeR"   R   R)   (   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   load_if_changed   s    	'
c         C  s   | d k	 r= t | d   } d |  _ |  j |  Wd QXn | ss t d t d |  j j  t d d |  j	   S|  j
 r t |  j
 d  , } t j j |  j
  |  _ |  j |  Wd QXn t d |  j j   t S(	   s  Load state from local file.
        If no path is specified, attempts to load from ``self.path``.

        :type path: str
        :arg path: local file to load from

        :type force: bool
        :param force:
            if ``force=False``, only load from ``self.path`` if file
            has changed since last load.

            .. deprecated:: 1.6
                This keyword will be removed in Passlib 1.8;
                Applications should use :meth:`load_if_changed` instead.
        t   rbi    Ns   %(name)s.load(force=False) is deprecated as of Passlib 1.6,and will be removed in Passlib 1.8; use %(name)s.load_if_changed() instead.t   nameR    i   s2   %s().path is not set, an explicit path is required(   t   Nonet   openR(   t   _load_linesR   t   dictR0   R1   R!   R:   R'   R8   R   R9   R7   R)   (   R   R   t   forcet   fh(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR      s     	
	c         C  s5   t  | |  j d  } d |  _ |  j t |   d S(   s@   Load state from unicode or bytes string, replacing current stateR   i    N(   R   R$   R(   R?   R   (   R   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR      s    	c         C  s'  |  j  } i  } g  } d } x t |  D] \ } } | j   } | sV | j t  rf | | 7} q( n  | | | d  \ }	 }
 |	 | k r t j d |	  | | 7} q( n  | r | j t | f  d } n  |
 | |	 <| j t	 |	 f  q( W| j
   r| j t | f  n  | |  _ | |  _ d S(   s   load from sequence of listsR/   i   s1   username occurs multiple times in source file: %rN(   t   _parse_recordt	   enumeratet   lstript
   startswitht   _BHASHt   logt   warningt   appendt   _SKIPPEDt   _RECORDt   rstripR*   R+   (   R   t   linest   parset   recordst   sourceR   t   idxt   linet   tmpt   keyR5   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR?      s.    	

	
	c         C  s   t  d   d S(   s)   parse line of file into (key, value) pairs!   should be implemented in subclassN(   t   NotImplementedError(   R   R   t   lineno(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRC     s    c         C  sB   |  j  } | | k } | | | <| s> |  j j t | f  n  | S(   s   
        helper for setting record which takes care of inserting source line if needed;

        :returns:
            bool if key already present
        (   R*   R+   RJ   RL   (   R   RU   R5   RP   t   existing(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _set_record  s    	
c         C  s#   |  j  r |  j r |  j   n  d S(   s0   subclass helper to call save() after any changesN(   R&   R'   t   save(   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt	   _autosave!  s    c         C  s   | d k	 r: t | d   } | j |  j    Wd QXnJ |  j rn |  j |  j  t j j |  j  |  _	 n t
 d |  j j   d S(   sh   Save current state to file.
        If no path is specified, attempts to save to ``self.path``.
        t   wbNs%   %s().path is not set, cannot autosave(   R=   R>   t
   writelinest   _iter_linesR'   RZ   R8   R   R9   R(   R7   R0   R1   (   R   R   RB   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRZ   &  s    	c         C  s   t  |  j    S(   s)   Export current state as a string of bytes(   R   R^   (   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt	   to_string4  s    c         c  s   |  j  } t |  } xq |  j D]f \ } } | t k r? | Vq | t k sQ t  | | k rc q n  |  j | | |  V| j |  q W| s t d | f   d S(   s#   iterator yielding lines of databases'   failed to write all records: missing=%rN(   R*   t   setR+   RK   RL   t   AssertionErrort   _render_recordt   remove(   R   RP   t   pendingt   actiont   content(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR^   @  s    	c         C  s   t  d   d S(   s,   given key/value pair, encode as line of files!   should be implemented in subclassN(   RV   (   R   RU   R5   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRb   [  s    c         C  s   |  j  | d  S(   s)   user-specific wrapper for _encode_field()t   user(   t   _encode_field(   R   Rg   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _encode_userb  s    c         C  s   |  j  | d  S(   s*   realm-specific wrapper for _encode_field()t   realm(   Rh   (   R   Rj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _encode_realmf  s    t   fieldc         C  s   t  | t  r$ | j |  j  } n! t  | t  sE t | |   n  t |  d k rp t d | | f   n  t d   | D  r t d | | f   n  | S(   s+  convert field to internal representation.

        internal representation is always bytes. byte strings are left as-is,
        unicode strings encoding using file's default encoding (or ``utf-8``
        if no encoding has been specified).

        :raises UnicodeEncodeError:
            if unicode value cannot be encoded using default encoding.

        :raises ValueError:
            if resulting byte string contains a forbidden character,
            or is too long (>255 bytes).

        :returns:
            encoded identifer as bytes
        i   s%   %s must be at most 255 characters: %rc         s  s   |  ] } | t  k Vq d  S(   N(   t   _INVALID_FIELD_CHARS(   t   .0t   c(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pys	   <genexpr>  s    s"   %s contains invalid characters: %r(	   t
   isinstanceR   t   encodeR$   t   bytesR   t   lenR#   t   any(   R   R5   t   param(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRh   j  s    c         C  s<   t  | t  s t d   |  j r4 | j |  j  S| Sd S(   sW  decode field from internal representation to format
        returns by users() method, etc.

        :raises UnicodeDecodeError:
            if unicode value cannot be decoded using default encoding.
            (usually indicates wrong encoding set for file).

        :returns:
            field as unicode or bytes, as appropriate.
        s   expected value to be bytesN(   Rp   Rr   Ra   R%   t   decodeR$   (   R   R5   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _decode_field  s    	N(&   R1   t
   __module__t   __doc__R=   R$   R%   R'   R(   R"   R&   R*   R+   t   classmethodR   R   R)   R   R.   R4   t   propertyR   t   setterR6   R:   R   R   R?   RC   RY   R[   RZ   R_   R^   Rb   Ri   Rk   Rh   Rw   (    (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   ,   s>   "			$		*								c          C  s   d  }  x- d d g D] } t j |  r | }  Pq q Wt j d  rK d n d  } t j   | s t j d d d d d g  n  t d | p d d	 d d | p |  p d d
 |  p d d | p d d d  } | j d | d d | d  | S(   Nt   bcryptt   sha256_cryptt   portable_apache_24t   host_apache_24t   linux_apache_24t   portablet   hostt   apr_md5_cryptt   portable_apache_22t   host_apache_22t   linux_apache_22(   R=   R   t   has_os_crypt_supportt   has_backendt   _warn_no_bcryptt   cleart   updateR@   (   t	   host_bestR<   R}   t   defaults(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _init_default_schemes  s*    
		
c          C  s{   d d d d d d d g }  |  j  t j    |  d  d g |  } t t |   d	 | j }  t d
 |  d t d d d  S(   NR}   R~   t   sha512_cryptt	   des_cryptR   t	   ldap_sha1t	   plaintexti   RU   t   schemest   defaultR   t   bcrypt__identt   2y(   t   extendR   t   get_supported_os_crypt_schemest   sortedR`   t   indexR   t   htpasswd_defaults(   R   t	   preferred(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _init_htpasswd_context  s    	
c           B  s   e  Z d  Z d d e d  Z d   Z d   Z d   Z d   Z	 e
 d d d d	 d
 d  d    Z d   Z d   Z e
 d d d d	 d
 d  d    Z d   Z d   Z e
 d d d d	 d
 d  d    Z RS(   s  class for reading & writing Htpasswd files.

    The class constructor accepts the following arguments:

    :type path: filepath
    :param path:

        Specifies path to htpasswd file, use to implicitly load from and save to.

        This class has two modes of operation:

        1. It can be "bound" to a local file by passing a ``path`` to the class
           constructor. In this case it will load the contents of the file when
           created, and the :meth:`load` and :meth:`save` methods will automatically
           load from and save to that file if they are called without arguments.

        2. Alternately, it can exist as an independant object, in which case
           :meth:`load` and :meth:`save` will require an explicit path to be
           provided whenever they are called. As well, ``autosave`` behavior
           will not be available.

           This feature is new in Passlib 1.6, and is the default if no
           ``path`` value is provided to the constructor.

        This is also exposed as a readonly instance attribute.

    :type new: bool
    :param new:

        Normally, if *path* is specified, :class:`HtpasswdFile` will
        immediately load the contents of the file. However, when creating
        a new htpasswd file, applications can set ``new=True`` so that
        the existing file (if any) will not be loaded.

        .. versionadded:: 1.6
            This feature was previously enabled by setting ``autoload=False``.
            That alias has been deprecated, and will be removed in Passlib 1.8

    :type autosave: bool
    :param autosave:

        Normally, any changes made to an :class:`HtpasswdFile` instance
        will not be saved until :meth:`save` is explicitly called. However,
        if ``autosave=True`` is specified, any changes made will be
        saved to disk immediately (assuming *path* has been set).

        This is also exposed as a writeable instance attribute.

    :type encoding: str
    :param encoding:

        Optionally specify character encoding used to read/write file
        and hash passwords. Defaults to ``utf-8``, though ``latin-1``
        is the only other commonly encountered encoding.

        This is also exposed as a readonly instance attribute.

    :type default_scheme: str
    :param default_scheme:
        Optionally specify default scheme to use when encoding new passwords.

        This can be any of the schemes with builtin Apache support,
        OR natively supported by the host OS's :func:`crypt.crypt` function.

        * Builtin schemes include ``"bcrypt"`` (apache 2.4+), ``"apr_md5_crypt"`,
          and ``"des_crypt"``.

        * Schemes commonly supported by Unix hosts
          include ``"bcrypt"``, ``"sha256_crypt"``, and ``"des_crypt"``.

        In order to not have to sort out what you should use,
        passlib offers a number of aliases, that will resolve
        to the most appropriate scheme based on your needs:

        * ``"portable"``, ``"portable_apache_24"`` -- pick scheme that's portable across hosts
          running apache >= 2.4. **This will be the default as of Passlib 2.0**.

        * ``"portable_apache_22"`` -- pick scheme that's portable across hosts
          running apache >= 2.4. **This is the default up to Passlib 1.9**.

        * ``"host"``, ``"host_apache_24"`` -- pick strongest scheme supported by
           apache >= 2.4 and/or host OS.

        * ``"host_apache_22"`` -- pick strongest scheme supported by
           apache >= 2.2 and/or host OS.

        .. versionadded:: 1.6
            This keyword was previously named ``default``. That alias
            has been deprecated, and will be removed in Passlib 1.8.

        .. versionchanged:: 1.6.3

            Added support for ``"bcrypt"``, ``"sha256_crypt"``, and ``"portable"`` alias.

        .. versionchanged:: 1.7

            Added apache 2.4 semantics, and additional aliases.

    :type context: :class:`~passlib.context.CryptContext`
    :param context:
        :class:`!CryptContext` instance used to create
        and verify the hashes found in the htpasswd file.
        The default value is a pre-built context which supports all
        of the hashes officially allowed in an htpasswd file.

        This is also exposed as a readonly instance attribute.

        .. warning::

            This option may be used to add support for non-standard hash
            formats to an htpasswd file. However, the resulting file
            will probably not be usable by another application,
            and particularly not by Apache.

    :param autoload:
        Set to ``False`` to prevent the constructor from automatically
        loaded the file from disk.

        .. deprecated:: 1.6
            This has been replaced by the *new* keyword.
            Instead of setting ``autoload=False``, you should use
            ``new=True``. Support for this keyword will be removed
            in Passlib 1.8.

    :param default:
        Change the default algorithm used to hash new passwords.

        .. deprecated:: 1.6
            This has been renamed to *default_scheme* for clarity.
            Support for this alias will be removed in Passlib 1.8.

    Loading & Saving
    ================
    .. automethod:: load
    .. automethod:: load_if_changed
    .. automethod:: load_string
    .. automethod:: save
    .. automethod:: to_string

    Inspection
    ================
    .. automethod:: users
    .. automethod:: check_password
    .. automethod:: get_hash

    Modification
    ================
    .. automethod:: set_password
    .. automethod:: delete

    Alternate Constructors
    ======================
    .. automethod:: from_string

    Attributes
    ==========
    .. attribute:: path

        Path to local file that will be used as the default
        for all :meth:`load` and :meth:`save` operations.
        May be written to, initialized by the *path* constructor keyword.

    .. attribute:: autosave

        Writeable flag indicating whether changes will be automatically
        written to *path*.

    Errors
    ======
    :raises ValueError:
        All of the methods in this class will raise a :exc:`ValueError` if
        any user name contains a forbidden character (one of ``:\r\n\t\x00``),
        or is longer than 255 characters.
    c         K  s   d | k r1 t  d t d d | j d  } n  | r | t k rZ t  d | t j  n  t j | |  } | j d |  } n  | |  _	 t
 t |   j | |  d  S(   NR   s{   ``default`` is deprecated as of Passlib 1.6, and will be removed in Passlib 1.8, it has been renamed to ``default_scheem``.R    i   sP   HtpasswdFile: no bcrypt backends available, using fallback for default scheme %r(   R   R!   t   popR   R   t   PasslibSecurityWarningR   t   gett   copyt   contextt   superR   R.   (   R   R   t   default_schemeR   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR.     s    	c         C  s>   | j    j t  } t |  d k r: t d |   n  | S(   Ni   s/   malformed htpasswd file (error reading line %d)(   RM   t   splitt   _BCOLONRs   R#   (   R   R   RW   t   result(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRC     s
    c         C  s   t  d | |  S(   Ns   %s:%s
(   R   (   R   Rg   t   hash(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRb     s    c         C  s#   g  |  j  D] } |  j |  ^ q
 S(   s6   
        Return list of all users in database
        (   R*   Rw   (   R   Rg   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   users  s    c         C  s"   |  j  j |  } |  j | |  S(   s  Set password for user; adds user if needed.

        :returns:
            * ``True`` if existing user was updated.
            * ``False`` if user account was added.

        .. versionchanged:: 1.6
            This method was previously called ``update``, it was renamed
            to prevent ambiguity with the dictionary method.
            The old alias is deprecated, and will be removed in Passlib 1.8.
        (   R   R   t   set_hash(   R   Rg   t   passwordR   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   set_password  s    t
   deprecateds   1.6t   removeds   1.8t   replacementR   c         C  s   |  j  | |  S(   s   set password for user(   R   (   R   Rg   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    c         C  s1   y |  j  |  j |  SWn t k
 r, d SXd S(   s  Return hash stored for user, or ``None`` if user not found.

        .. versionchanged:: 1.6
            This method was previously named ``find``, it was renamed
            for clarity. The old name is deprecated, and will be removed
            in Passlib 1.8.
        N(   R*   Ri   t   KeyErrorR=   (   R   Rg   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   get_hash  s    c         C  sY   t  r* t | t  r* | j |  j  } n  |  j |  } |  j | |  } |  j   | S(   s   
        semi-private helper which allows writing a hash directly;
        adds user if needed.

        .. warning::
            does not (currently) do any validation of the hash string

        .. versionadded:: 1.7
        (   R   Rp   t   strRq   R$   Ri   RY   R[   (   R   Rg   R   RX   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    
R   c         C  s   |  j  |  S(   s   return hash for user(   R   (   R   Rg   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   find1  s    c         C  s:   y |  j  |  j |  =Wn t k
 r+ t SX|  j   t S(   s   Delete user's entry.

        :returns:
            * ``True`` if user deleted.
            * ``False`` if user not found.
        (   R*   Ri   R   R"   R[   R)   (   R   Rg   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   delete8  s    
c         C  s   |  j  |  } |  j j |  } | d k r1 d St | t  rU | j |  j  } n  |  j j	 | |  \ } } | r | d k	 r | |  j k s t
  | |  j | <|  j   n  | S(   sM  
        Verify password for specified user.
        If algorithm marked as deprecated by CryptContext, will automatically be re-hashed.

        :returns:
            * ``None`` if user not found.
            * ``False`` if user found, but password does not match.
            * ``True`` if user found and password matches.

        .. versionchanged:: 1.6
            This method was previously called ``verify``, it was renamed
            to prevent ambiguity with the :class:`!CryptContext` method.
            The old alias is deprecated, and will be removed in Passlib 1.8.
        N(   Ri   R*   R   R=   Rp   R   Rq   R$   R   t   verify_and_updateRa   R[   (   R   Rg   R   R   t   okt   new_hash(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   check_passwordF  s    R   c         C  s   |  j  | |  S(   s   verify password for user(   R   (   R   Rg   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   verifye  s    N(   R1   Rx   Ry   R=   t   htpasswd_contextR.   RC   Rb   R   R   R
   R   R   R   R   R   R   R   (    (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    								c           B  s  e  Z d  Z d Z d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d d  Z d e d	  Z e d
 d d d d d  d    Z d d  Z d e d  Z e d
 d d d d d  d    Z d d  Z d   Z d e d  Z e d
 d d d d d  d    Z RS(   s  class for reading & writing Htdigest files.

    The class constructor accepts the following arguments:

    :type path: filepath
    :param path:

        Specifies path to htdigest file, use to implicitly load from and save to.

        This class has two modes of operation:

        1. It can be "bound" to a local file by passing a ``path`` to the class
           constructor. In this case it will load the contents of the file when
           created, and the :meth:`load` and :meth:`save` methods will automatically
           load from and save to that file if they are called without arguments.

        2. Alternately, it can exist as an independant object, in which case
           :meth:`load` and :meth:`save` will require an explicit path to be
           provided whenever they are called. As well, ``autosave`` behavior
           will not be available.

           This feature is new in Passlib 1.6, and is the default if no
           ``path`` value is provided to the constructor.

        This is also exposed as a readonly instance attribute.

    :type default_realm: str
    :param default_realm:

        If ``default_realm`` is set, all the :class:`HtdigestFile`
        methods that require a realm will use this value if one is not
        provided explicitly. If unset, they will raise an error stating
        that an explicit realm is required.

        This is also exposed as a writeable instance attribute.

        .. versionadded:: 1.6

    :type new: bool
    :param new:

        Normally, if *path* is specified, :class:`HtdigestFile` will
        immediately load the contents of the file. However, when creating
        a new htpasswd file, applications can set ``new=True`` so that
        the existing file (if any) will not be loaded.

        .. versionadded:: 1.6
            This feature was previously enabled by setting ``autoload=False``.
            That alias has been deprecated, and will be removed in Passlib 1.8

    :type autosave: bool
    :param autosave:

        Normally, any changes made to an :class:`HtdigestFile` instance
        will not be saved until :meth:`save` is explicitly called. However,
        if ``autosave=True`` is specified, any changes made will be
        saved to disk immediately (assuming *path* has been set).

        This is also exposed as a writeable instance attribute.

    :type encoding: str
    :param encoding:

        Optionally specify character encoding used to read/write file
        and hash passwords. Defaults to ``utf-8``, though ``latin-1``
        is the only other commonly encountered encoding.

        This is also exposed as a readonly instance attribute.

    :param autoload:
        Set to ``False`` to prevent the constructor from automatically
        loaded the file from disk.

        .. deprecated:: 1.6
            This has been replaced by the *new* keyword.
            Instead of setting ``autoload=False``, you should use
            ``new=True``. Support for this keyword will be removed
            in Passlib 1.8.

    Loading & Saving
    ================
    .. automethod:: load
    .. automethod:: load_if_changed
    .. automethod:: load_string
    .. automethod:: save
    .. automethod:: to_string

    Inspection
    ==========
    .. automethod:: realms
    .. automethod:: users
    .. automethod:: check_password(user[, realm], password)
    .. automethod:: get_hash

    Modification
    ============
    .. automethod:: set_password(user[, realm], password)
    .. automethod:: delete
    .. automethod:: delete_realm

    Alternate Constructors
    ======================
    .. automethod:: from_string

    Attributes
    ==========
    .. attribute:: default_realm

        The default realm that will be used if one is not provided
        to methods that require it. By default this is ``None``,
        in which case an explicit realm must be provided for every
        method call. Can be written to.

    .. attribute:: path

        Path to local file that will be used as the default
        for all :meth:`load` and :meth:`save` operations.
        May be written to, initialized by the *path* constructor keyword.

    .. attribute:: autosave

        Writeable flag indicating whether changes will be automatically
        written to *path*.

    Errors
    ======
    :raises ValueError:
        All of the methods in this class will raise a :exc:`ValueError` if
        any user name or realm contains a forbidden character (one of ``:\r\n\t\x00``),
        or is longer than 255 characters.
    c         K  s&   | |  _  t t |   j | |  d  S(   N(   t   default_realmR   R   R.   (   R   R   R   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR.     s    	c         C  sY   | j    j t  } t |  d k r: t d |   n  | \ } } } | | f | f S(   Ni   s/   malformed htdigest file (error reading line %d)(   RM   R   R   Rs   R#   (   R   R   RW   R   Rg   Rj   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRC     s    c         C  s   | \ } } t  d | | |  S(   Ns	   %s:%s:%s
(   R   (   R   RU   R   Rg   Rj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRb     s    c         C  s7   | d  k r3 |  j } | d  k r3 t d   q3 n  | S(   NsG   you must specify a realm explicitly, or set the default_realm attribute(   R=   R   R   (   R   Rj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _require_realm  s
    	c         C  s   |  j  |  } |  j | d  S(   NRj   (   R   Rh   (   R   Rj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyRk     s    c         C  s   |  j  |  |  j |  f S(   N(   Ri   Rk   (   R   Rg   Rj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   _encode_key#  s    c         C  s9   t  d   |  j D  } g  | D] } |  j |  ^ q  S(   s%   Return list of all realms in databasec         s  s   |  ] } | d  Vq d S(   i   N(    (   Rn   RU   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pys	   <genexpr>,  s    (   R`   R*   Rw   (   R   t   realmsRj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   *  s    c         C  sF   |  j  |  } g  |  j D]) } | d | k r |  j | d  ^ q S(   s   Return list of all users in specified realm.

        * uses ``self.default_realm`` if no realm explicitly provided.
        * returns empty list if realm not found.
        i   i    (   Rk   R*   Rw   (   R   Rj   RU   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   /  s    c         C  s\   | t  k r d | } } n  |  j |  } t j | | | d |  j } |  j | | |  S(   s  Set password for user; adds user & realm if needed.

        If ``self.default_realm`` has been set, this may be called
        with the syntax ``set_password(user, password)``,
        otherwise it must be called with all three arguments:
        ``set_password(user, realm, password)``.

        :returns:
            * ``True`` if existing user was updated
            * ``False`` if user account added.
        R$   N(   t   _UNSETR=   R   R   R   R$   R   (   R   Rg   Rj   R   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   Q  s
    R   s   1.6R   s   1.8R   R   c         C  s   |  j  | | |  S(   s   set password for user(   R   (   R   Rg   Rj   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   d  s    c         C  sS   |  j  | |  } |  j j |  } | d k r4 d St rO | j |  j  } n  | S(   s  Return :class:`~passlib.hash.htdigest` hash stored for user.

        * uses ``self.default_realm`` if no realm explicitly provided.
        * returns ``None`` if user or realm not found.

        .. versionchanged:: 1.6
            This method was previously named ``find``, it was renamed
            for clarity. The old name is deprecated, and will be removed
            in Passlib 1.8.
        N(   R   R*   R   R=   R   Rv   R$   (   R   Rg   Rj   RU   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   j  s    c         C  sx   | t  k r d | } } n  t rF t | t  rF | j |  j  } n  |  j | |  } |  j | |  } |  j	   | S(   s  
        semi-private helper which allows writing a hash directly;
        adds user & realm if needed.

        If ``self.default_realm`` has been set, this may be called
        with the syntax ``set_hash(user, hash)``,
        otherwise it must be called with all three arguments:
        ``set_hash(user, realm, hash)``.

        .. warning::
            does not (currently) do any validation of the hash string

        .. versionadded:: 1.7
        N(
   R   R=   R   Rp   R   Rq   R$   R   RY   R[   (   R   Rg   Rj   R   RU   RX   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   }  s    
R   c         C  s   |  j  | |  S(   s   return hash for user(   R   (   R   Rg   Rj   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    c         C  sC   |  j  | |  } y |  j | =Wn t k
 r4 t SX|  j   t S(   s   Delete user's entry for specified realm.

        if realm is not specified, uses ``self.default_realm``.

        :returns:
            * ``True`` if user deleted,
            * ``False`` if user not found in realm.
        (   R   R*   R   R"   R[   R)   (   R   Rg   Rj   RU   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    	
c         C  sm   |  j  |  } |  j } g  | D] } | d | k r | ^ q } x | D] } | | =qH W|  j   t |  S(   s   Delete all users for specified realm.

        if realm is not specified, uses ``self.default_realm``.

        :returns: number of users deleted (0 if realm not found)
        i   (   Rk   R*   R[   Rs   (   R   Rj   RP   RU   t   keys(    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   delete_realm  s    	)
c         C  s   | t  k r d | } } n  |  j |  } |  j |  } |  j j | | f  } | d k rb d St j | | | | d |  j S(   s  Verify password for specified user + realm.

        If ``self.default_realm`` has been set, this may be called
        with the syntax ``check_password(user, password)``,
        otherwise it must be called with all three arguments:
        ``check_password(user, realm, password)``.

        :returns:
            * ``None`` if user or realm not found.
            * ``False`` if user found, but password does not match.
            * ``True`` if user found and password matches.

        .. versionchanged:: 1.6
            This method was previously called ``verify``, it was renamed
            to prevent ambiguity with the :class:`!CryptContext` method.
            The old alias is deprecated, and will be removed in Passlib 1.8.
        R$   N(	   R   R=   Ri   Rk   R*   R   R   R   R$   (   R   Rg   Rj   R   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    R   c         C  s   |  j  | | |  S(   s   verify password for user(   R   (   R   Rg   Rj   R   (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR     s    N(   R1   Rx   Ry   R=   R   R.   RC   Rb   R   Rk   R   R   R   R   R   R
   R   R   R   R   R   R   R   R   (    (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyR   r  s,   						"	(/   Ry   t
   __future__R    t   loggingt	   getLoggerR1   RH   R8   t   warningsR   t   passlibR   R   t   passlib.contextR   t   passlib.excR   t   passlib.hashR   t   passlib.utilsR   R   R	   t   passlib.utils.decorR
   t   passlib.utils.compatR   R   R   R   t   __all__t   objectR   R   RG   Rm   RK   RL   R   R`   R   R   R   R   R   R   R   (    (    (    sI   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/apache.pyt   <module>   s<    "		 		)		-	 b