U
    
W[ú  ã                   @   s`   d Z ddlmZmZ ddgZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZG d
d„ deƒZ	dS )zM
L{twisted.python.fakepwd} provides a fake implementation of the L{pwd} API.
é    )Úabsolute_importÚdivisionÚUserDatabaseÚShadowDatabasec                   @   s(   e Zd ZdZdd„ Z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 L{pwd.struct_passwd}.  See that class for attribute
    documentation.
    c                 C   s.   || _ || _|| _|| _|| _|| _|| _d S ©N©Úpw_nameÚ	pw_passwdÚpw_uidÚpw_gidÚpw_gecosÚpw_dirÚpw_shell)ÚselfÚnameÚpasswordÚuidÚgidÚgecosÚhomeÚshell© r   ú8/usr/lib/python3/dist-packages/twisted/python/fakepwd.pyÚ__init__   s    z_UserRecord.__init__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__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r   r   r   r   r      s   
r   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Z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.
    c                 C   s
   g | _ d S r   ©Ú_usersr   r   r   r   r   1   s    zUserDatabase.__init__c              
   C   s    | j  t|||||||ƒ¡ 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.
        @type username: C{str}

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

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

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

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

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

        @param shell: The value for the C{pw_shell} field of the user record to
            add.
        @type shell: C{str}
        N)r'   Úappendr   )r   Úusernamer   r   r   r   r   r   r   r   r   ÚaddUser5   s           ÿzUserDatabase.addUserc                 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   ÚgetpwuidY   s    


zUserDatabase.getpwuidc                 C   s(   | j D ]}|j|kr|  S qtƒ ‚dS )zM
        Return the user record corresponding to the given username.
        N)r'   r	   r+   )r   r   r,   r   r   r   Úgetpwnamc   s    


zUserDatabase.getpwnamc                 C   s   | j S )z4
        Return a list of all user records.
        r&   r   r   r   r   Úgetpwallm   s    zUserDatabase.getpwallN)	r"   r#   r$   r%   r   r*   r-   r.   r/   r   r   r   r   r   )   s   $

c                   @   s(   e Zd ZdZdd„ Z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.
    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   r)   r   Z
lastChangeÚminÚmaxÚwarnZinactZexpireÚflagr   r   r   r   {   s    z_ShadowRecord.__init__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   r1   r   r   r   r   r    Œ   s          ýýz_ShadowRecord.__getitem__Nr!   r   r   r   r   r0   u   s   r0   c                   @   s0   e Zd ZdZdd„ Zdd„ Z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
    c                 C   s
   g | _ d S r   r&   r   r   r   r   r   ž   s    zShadowDatabase.__init__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.
        @type username: C{str}

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

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

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

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

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

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

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

        @param flag: The value for the C{sp_flag} field of the user record to
            add.
        @type flag: C{int}
        N)r'   r(   r0   r3   r   r   r   r*   ¢   s    '       þzShadowDatabase.addUserc                 C   s&   | j D ]}|j|kr|  S qt‚dS )zT
        Return the shadow user record corresponding to the given username.
        N)r'   r2   r+   )r   r)   r,   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.getspallN)r"   r#   r$   r%   r   r*   r9   r:   r   r   r   r   r   ”   s
   	,
N)
r%   Z
__future__r   r   Ú__all__Úobjectr   r   r0   r   r   r   r   r   Ú<module>   s   L