%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/cred/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/cred/__pycache__/checkers.cpython-312.pyc

�

Ϫ�f�,��>�UdZddlZddlmZmZmZmZmZddlm	Z	m
Z
mZddlm
Z
ddlmZmZmZddlmZddlmZdd	lmZdd
lmZdZeded<Gd
�de
�Zee�Gd�d��Zee�Gd�d��Zee�Gd�d��ZeZ y)zf
Basic credential checkers

@var ANONYMOUS: An empty tuple used to represent the anonymous avatar ID.
�N)�Any�Dict�Optional�Tuple�Union)�	Attribute�	Interface�implementer)�error)�
IAnonymous�IUsernameHashedPassword�IUsernamePassword)�defer)�Deferred)�Logger)�failure��	ANONYMOUSc�F�eZdZdZed�Zdedeee	e
dffd�Zy)�ICredentialsCheckerzE
    An object that can check sub-interfaces of L{ICredentials}.
    zNA list of sub-interfaces of L{ICredentials} which specifies which I may check.�credentials�returnrc��y)a
        Validate credentials and produce an avatar ID.

        @param credentials: something which implements one of the interfaces in
            C{credentialInterfaces}.

        @return: a L{Deferred} which will fire with a L{bytes} that identifies
            an avatar, an empty tuple to specify an authenticated anonymous
            user (provided as L{twisted.cred.checkers.ANONYMOUS}) or fail with
            L{UnauthorizedLogin}.  Alternatively, return the result itself.

        @see: L{twisted.cred.credentials}
        Nr)rs �7/usr/lib/python3/dist-packages/twisted/cred/checkers.py�requestAvatarIdz#ICredentialsChecker.requestAvatarId3s��N)�__name__�
__module__�__qualname__�__doc__r�credentialInterfacesrrr�bytesrrrrrrr)s?���%�	���

�S�
�X�e�E�5��9�<L�6M�-N�
rrc��eZdZdZefZd�Zy)�AllowAnonymousAccessz�
    A credentials checker that unconditionally grants anonymous access.

    @cvar credentialInterfaces: Tuple containing L{IAnonymous}.
    c�4�tjt�S)z�
        Succeed with the L{ANONYMOUS} avatar ID.

        @return: L{Deferred} that fires with L{twisted.cred.checkers.ANONYMOUS}
        )r�succeedr��selfrs  rrz$AllowAnonymousAccess.requestAvatarIdMs���}�}�Y�'�'rN)rrrr rr!rrrrr$r$Cs���'�=��(rr$c�H�eZdZdZeefZdeddfd�Zdededdfd�Z	d	�Z
d
�Zy)�'InMemoryUsernamePasswordDatabaseDontUsea9
    An extremely simple credentials checker.

    This is only of use in one-off test programs or examples which don't
    want to focus too much on how credentials are verified.

    You really don't want to use this for anything else.  It is, at best, a
    toy.  If you need a simple credentials checker for a real application,
    see L{FilePasswordDB}.

    @cvar credentialInterfaces: Tuple of L{IUsernamePassword} and
    L{IUsernameHashedPassword}.

    @ivar users: Mapping of usernames to passwords.
    @type users: L{dict} mapping L{bytes} to L{bytes}
    �usersrNc��|j�D��cic]\}}|jd�|��c}}|_ycc}}w)a�
        Initialize the in-memory database.

        For example::

            db = InMemoryUsernamePasswordDatabaseDontUse(
                user1=b'sesame',
                user2=b'hunter2',
            )

        @param users: Usernames and passwords to seed the database with.
        Each username given as a keyword is encoded to L{bytes} as ASCII.
        Passwords must be given as L{bytes}.
        @type users: L{dict} of L{str} to L{bytes}
        �asciiN)�items�encoder+)r(r+�x�ys    r�__init__z0InMemoryUsernamePasswordDatabaseDontUse.__init__ns1�� 8=�{�{�}�E�t�q�!�a�h�h�w�'��*�E��
��Es�:�username�passwordc�"�||j|<y)z�
        Set a user's password.

        @param username: Name of the user.
        @type username: L{bytes}

        @param password: Password to associate with the username.
        @type password: L{bytes}
        N)r+)r(r3r4s   r�addUserz/InMemoryUsernamePasswordDatabaseDontUse.addUser�s�� (��
�
�8�rc�X�|r|Stjtj��S�N�r�Failurer�UnauthorizedLogin�r(�matchedr3s   r�_cbPasswordMatchz8InMemoryUsernamePasswordDatabaseDontUse._cbPasswordMatch��"����O��?�?�5�#:�#:�#<�=�=rc�6�|j|jvr[tj|j|j|j�j|j|j�Stjtj��Sr8)
r3r+r�
maybeDeferred�
checkPassword�addCallbackr>�failrr;r's  rrz7InMemoryUsernamePasswordDatabaseDontUse.requestAvatarId�st�����4�:�:�-��&�&��)�)�4�:�:�k�6J�6J�+K���k�$�/�/��1E�1E�F�
G��:�:�e�5�5�7�8�8r)rrrr rr
r!r"r2r6r>rrrrr*r*VsQ���$	����
F��F�$�F�$
(��
(��
(�4�
(�>�9rr*c��eZdZUdZdZdZeeeefe	d<dZ
ee	d<e�Z
						dd�Zd�Zd	�Zd
�Zdedeeeffd
�Zdedeeeedffd�Zy)�FilePasswordDBaz
    A file-based, text-based username/password database.

    Records in the datafile for this class are delimited by a particular
    string.  The username appears in a fixed field of the columns delimited
    by this string, as does the password.  Both fields are specifiable.  If
    the passwords are not stored plaintext, a hash function must be supplied
    to convert plaintext passwords to the form stored on disk and this
    CredentialsChecker will only be able to check L{IUsernamePassword}
    credentials.  If the passwords are stored plaintext,
    L{IUsernameHashedPassword} credentials will be checkable as well.
    FN�
_credCacher�_cacheTimestampc��||_||_||_||_||_||_||_|j
�ttf|_	ytf|_	y)a�
        @type filename: L{str}
        @param filename: The name of the file from which to read username and
        password information.

        @type delim: L{bytes}
        @param delim: The field delimiter used in the file.

        @type usernameField: L{int}
        @param usernameField: The index of the username after splitting a
        line on the delimiter.

        @type passwordField: L{int}
        @param passwordField: The index of the password after splitting a
        line on the delimiter.

        @type caseSensitive: L{bool}
        @param caseSensitive: If true, consider the case of the username when
        performing a lookup.  Ignore it otherwise.

        @type hash: Three-argument callable or L{None}
        @param hash: A function used to transform the plaintext password
        received over the network to a format suitable for comparison
        against the version stored on disk.  The arguments to the callable
        are the username, the network-supplied password, and the in-file
        version of the password.  If the return value compares equal to the
        version stored on disk, the credentials are accepted.

        @type cache: L{bool}
        @param cache: If true, maintain an in-memory cache of the
        contents of the password file.  On lookups, the mtime of the
        file will be checked, and the file will only be re-parsed if
        the mtime is newer than when the cache was generated.
        N)
�filename�delim�ufield�pfield�
caseSensitive�hash�cacherr
r!)r(rJrK�
usernameField�
passwordFieldrNrOrPs        rr2zFilePasswordDB.__init__�s`��X!��
���
�#���#���*�����	���
��9�9��"�'�)�D�%�*;�(<�D�%rc�b�tt|��}dD]}	||=�|S#t$rY�wxYw)N)rGrH)�dict�vars�KeyError)r(�d�ks   r�__getstate__zFilePasswordDB.__getstate__�sF����d����0�	�A�
��a�D�	�
����
��
�s�"�	.�.c�X�|r|Stjtj��Sr8r9r<s   rr>zFilePasswordDB._cbPasswordMatch�r?rc#�fK�	t|jd�5}|D]�}|j�}|j|j�}|j
t
|�k\s|jt
|�k\r�_|jr!||j
||jf����||j
j�||jf����	ddd�y#1swYyxYw#t$r6}|jjd|��tj��d}~wwxYw�w)a
        Loads the credentials from the configured file.

        @return: An iterable of C{username, password} couples.
        @rtype: C{iterable}

        @raise UnauthorizedLogin: when failing to read the credentials from the
            file.
        �rbNz$Unable to load credentials db: {e!r})�e)�openrJ�rstrip�splitrKrL�lenrMrN�lower�OSError�_logrr;)r(�f�line�partsr]s     r�_loadCredentialszFilePasswordDB._loadCredentials�s����	,��d�m�m�T�*�

M�a��	M�D��;�;�=�D� �J�J�t�z�z�2�E��{�{�c�%�j�0�D�K�K�3�u�:�4M� ��)�)�#�D�K�K�0�%����2D�D�D�#�D�K�K�0�6�6�8�%����:L�L�L�	M�

M�

M�

M���	,��I�I�O�O�B�a�O�H��)�)�+�+��	,�sL�D1�C/�B?C#�C/�"D1�#C,�(C/�+D1�,C/�/	D.�81D)�)D.�.D1r3rc���|js|j�}|jr�|j�6tj
j
|j�|jkDrLtj
j
|j�|_t|j��|_||j|fS|j�D]\}}||k(s�||fcSt|��)a�
        Look up the credentials for a username.

        @param username: The username to look up.
        @type username: L{bytes}

        @returns: Two-tuple of the canonicalicalized username (i.e. lowercase
        if the database is not case sensitive) and the associated password
        value, both L{bytes}.
        @rtype: L{tuple}

        @raises KeyError: When lookup of the username fails.
        )rNrbrPrG�os�path�getmtimerJrHrTrhrV)r(r3�u�ps    r�getUserzFilePasswordDB.getUsers����!�!��~�~�'�H��:�:����'��7�7�#�#�D�M�M�2�T�5I�5I�I�')�w�w�'7�'7��
�
�'F��$�"&�t�'<�'<�'>�"?����T�_�_�X�6�6�6��-�-�/�
 ���1���=��a�4�K�
 ��8�$�$rrrc�$�	|j|j�\}}t|d�}|jrj|�A|j|j|j|�}||k(rtj|�Stjtj��Stj|j|�j|j|�S#t$r*tjtj��cYSwxYwr8)ror3rrOr4rr&rDrr;rArBrCr>rV)r(rrmrn�up�hs      rrzFilePasswordDB.requestAvatarId7s���	��<�<�� 4� 4�5�D�A�q�#�;��5�B��y�y��>��	�	�"�+�+�r�{�{�A�>�A��A�v�$�}�}�Q�/�/��z�z�%�"9�"9�";�<�<��*�*�;�+D�+D�a�H�T�T��)�)�1�����	9��:�:�e�5�5�7�8�8�	9�s�C�0D�D)�:r�TNF)rrrr rPrGrrr"�__annotations__rH�floatrrdr2rYr>rhrrorrrrrrrrFrF�s����
�E�/3�J���e�U�l�+�,�3��O�U���8�D�
����
��>=�@�>�,�4%��%�%��u��*=�%�>�,��	�%��u�R�y�(�)�	*�rrF)!r rj�typingrrrrr�zope.interfacerr	r
�twisted.credr�twisted.cred.credentialsrr
r�twisted.internetr�twisted.internet.deferr�twisted.loggerr�twisted.pythonrrrurr$r*rF�OnDiskUsernamePasswordDatabaserrr�<module>r�s���
�
�4�4�<�<����
#�+�!�"��	�5��9���)��4
�
 �!�(�(�"�(�$
�
 �!�A9�A9�"�A9�H
�
 �!�m�m�"�m�d"0�r

Zerion Mini Shell 1.0