U
    �Acj�  ã                   @   sX   d Z ddlmZmZ ddgZG dd„ dƒZG dd„ dƒZG dd	„ d	ƒZG d
d„ dƒZdS )zM
L{twisted.python.fakepwd} provides a fake implementation of the L{pwd} API.
é    )ÚListÚOptionalÚUserDatabaseÚShadowDatabasec                	   @   sB   e Zd ZdZeeeeeeeddœdd„Zedœdd„Zd	d
„ ZdS )Ú_UserRecordzÉ
    L{_UserRecord} holds the user data for a single user in L{UserDatabase}.
    It corresponds to the C{passwd} structure from the L{pwd} module.
    See that module for attribute documentation.
    N)ÚnameÚpasswordÚuidÚgidÚgecosÚhomeÚshellÚreturnc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S ©N©Úpw_nameÚ	pw_passwdÚpw_uidÚpw_gidÚpw_gecosÚpw_dirÚpw_shell)Úselfr   r   r	   r
   r   r   r   © r   ú:/tmp/pip-unpacked-wheel-nrvc_22y/twisted/python/fakepwd.pyÚ__init__   s    
z_UserRecord.__init__©r   c                 C   s   dS )Né   r   ©r   r   r   r   Ú__len__'   s    z_UserRecord.__len__c                 C   s$   | j | j| j| j| j| j| jf| S r   r   ©r   Úindexr   r   r   Ú__getitem__*   s    ùøz_UserRecord.__getitem__©	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚintr   r   r"   r   r   r   r   r      s   ÷r   c                
   @   sœ   e Zd ZU dZee ed< dZeed< dZ	eed< ddœd	d
„Z
deeee ee eeeddœdd„Zeedœdd„Zeedœdd„Zee dœdd„ZdS )r   zí
    L{UserDatabase} holds a traditional POSIX user data in memory and makes it
    available via the same API as L{pwd}.

    @ivar _users: A C{list} of L{_UserRecord} instances holding all user data
        added to this database.
    Ú_usersiu'  Ú_lastUIDiêN  Ú_lastGIDNr   c                 C   s
   g | _ d S r   ©r*   r   r   r   r   r   C   s    zUserDatabase.__init__r   Ú ú/bin/sh)Úusernamer   r	   r
   r   r   r   r   c           	      C   s\   |dkr| j }|  j d7  _ |dkr8| j}|  jd7  _t|||||||ƒ}| j |¡ dS )aâ  
        Add a new user record to this database.

        @param username: The value for the C{pw_name} field of the user
            record to add.

        @param password: The value for the C{pw_passwd} field of the user
            record to add.

        @param uid: The value for the C{pw_uid} field of the user record to
            add.

        @param gid: The value for the C{pw_gid} field of the user record to
            add.

        @param gecos: The value for the C{pw_gecos} field of the user record
            to add.

        @param home: The value for the C{pw_dir} field of the user record to
            add.

        @param shell: The value for the C{pw_shell} field of the user record to
            add.
        Né   )r+   r,   r   r*   Úappend)	r   r0   r   r	   r
   r   r   r   ZnewUserr   r   r   ÚaddUserF   s    "zUserDatabase.addUser)r	   r   c                 C   s(   | j D ]}|j|kr|  S qtƒ ‚dS )zH
        Return the user record corresponding to the given uid.
        N)r*   r   ÚKeyError)r   r	   Úentryr   r   r   Úgetpwuidq   s    


zUserDatabase.getpwuid)r   r   c                 C   sD   t |tƒstdt|ƒ› �ƒ‚| jD ]}|j|kr"|  S q"tƒ ‚dS )zM
        Return the user record corresponding to the given username.
        z%getpwuam() argument must be str, not N)Ú
isinstancer(   Ú	TypeErrorÚtyper*   r   r4   )r   r   r5   r   r   r   Úgetpwnamz   s    



zUserDatabase.getpwnamc                 C   s   | j S )z4
        Return a list of all user records.
        r-   r   r   r   r   Úgetpwall…   s    zUserDatabase.getpwall)r   NNr.   r.   r/   )r$   r%   r&   r'   r   r   Ú__annotations__r+   r)   r,   r   r(   r   r3   r6   r:   r;   r   r   r   r   r   6   s0   
      ø÷+	c                   @   sF   e Zd ZdZeeeeeeeeeddœ
dd„Zedœdd„Zd	d
„ ZdS )Ú_ShadowRecordzº
    L{_ShadowRecord} holds the shadow user data for a single user in
    L{ShadowDatabase}.  It corresponds to C{spwd.struct_spwd}.  See that class
    for attribute documentation.
    N©
r0   r   Ú
lastChangeÚminÚmaxÚwarnÚinactÚexpireÚflagr   c
           
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r   ©	Úsp_namZsp_pwdZ	sp_lstchgZsp_minZsp_maxZsp_warnZsp_inactZ	sp_expireZsp_flag©
r   r0   r   r?   r@   rA   rB   rC   rD   rE   r   r   r   r   “   s    z_ShadowRecord.__init__r   c                 C   s   dS )Né	   r   r   r   r   r   r   ©   s    z_ShadowRecord.__len__c              	   C   s,   | j | j| j| j| j| j| j| j| jf	| S r   rF   r    r   r   r   r"   ¬   s    ÷
öz_ShadowRecord.__getitem__r#   r   r   r   r   r=   Œ   s   õr=   c                   @   sd   e Zd ZU dZee ed< ddœdd„Zeee	e	e	e	e	e	e	ddœ
dd	„Z
eed
œdd„Zdd„ ZdS )r   zý
    L{ShadowDatabase} holds a shadow user database in memory and makes it
    available via the same API as C{spwd}.

    @ivar _users: A C{list} of L{_ShadowRecord} instances holding all user data
        added to this database.

    @since: 12.0
    r*   Nr   c                 C   s
   g | _ d S r   r-   r   r   r   r   r   Ç   s    zShadowDatabase.__init__r>   c
           
      C   s$   | j  t|||||||||	ƒ	¡ dS )a‘  
        Add a new user record to this database.

        @param username: The value for the C{sp_nam} field of the user record to
            add.

        @param password: The value for the C{sp_pwd} field of the user record to
            add.

        @param lastChange: The value for the C{sp_lstchg} field of the user
            record to add.

        @param min: The value for the C{sp_min} field of the user record to add.

        @param max: The value for the C{sp_max} field of the user record to add.

        @param warn: The value for the C{sp_warn} field of the user record to
            add.

        @param inact: The value for the C{sp_inact} field of the user record to
            add.

        @param expire: The value for the C{sp_expire} field of the user record
            to add.

        @param flag: The value for the C{sp_flag} field of the user record to
            add.
        N)r*   r2   r=   rH   r   r   r   r3   Ê   s    (        ÿÿzShadowDatabase.addUser)r0   r   c                 C   sF   t |tƒstdt|ƒ› �ƒ‚| jD ]}|j|kr"|  S q"t|ƒ‚dS )zT
        Return the shadow user record corresponding to the given username.
        z%getspnam() argument must be str, not N)r7   r(   r8   r9   r*   rG   r4   )r   r0   r5   r   r   r   Úgetspnamø   s    



zShadowDatabase.getspnamc                 C   s   | j S )z;
        Return a list of all shadow user records.
        r-   r   r   r   r   Úgetspall  s    zShadowDatabase.getspall)r$   r%   r&   r'   r   r=   r<   r   r(   r)   r3   rJ   rK   r   r   r   r   r   º   s    

õ.N)	r'   Útypingr   r   Ú__all__r   r   r=   r   r   r   r   r   Ú<module>   s   (V.