
    Ϫf                     p    d Z ddlmZmZ ddgZ G d d      Z G d d      Z G d d	      Z G d
 d      Zy)zM
L{twisted.python.fakepwd} provides a fake implementation of the L{pwd} API.
    )ListOptionalUserDatabaseShadowDatabasec                   J    e Zd ZdZdededededededed	d
fdZd	efdZd Zy
)_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.
    namepassworduidgidgecoshomeshellreturnNc                 f    || _         || _        || _        || _        || _        || _        || _        y Npw_name	pw_passwdpw_uidpw_gidpw_gecospw_dirpw_shell)selfr	   r
   r   r   r   r   r   s           8/usr/lib/python3/dist-packages/twisted/python/fakepwd.py__init__z_UserRecord.__init__   s5     !    c                      y)N    r   s    r   __len__z_UserRecord.__len__'       r   c                     | j                   | j                  | j                  | j                  | j                  | j
                  | j                  f|   S r   r   r   indexs     r   __getitem__z_UserRecord.__getitem__*   sG    LLNNKKKKMMKKMM
  	r   	__name__
__module____qualname____doc__strintr   r#   r(   r!   r   r   r   r      sk      	
     
$ 	r   r   c                       e Zd ZU dZee   ed<   dZeed<   dZ	eed<   dd	Z
	 	 	 	 	 	 dded
edee   dee   dedededdfdZdedefdZdedefdZdee   fdZy)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'  _lastUIDiN  _lastGIDr   Nc                     g | _         y r   r1   r"   s    r   r   zUserDatabase.__init__C   	    r   r
   usernamer   r   r   r   r   c           	          |!| j                   }| xj                   dz  c_         |!| j                  }| xj                  dz  c_        t        |||||||      }| j                  j	                  |       y)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   )r2   r3   r   r1   append)	r   r7   r
   r   r   r   r   r   newUsers	            r   addUserzUserDatabase.addUserF   se    D ;--CMMQM;--CMMQMh#sE4O7#r   c                 ^    | j                   D ]  }|j                  |k(  s|c S  t               )zH
        Return the user record corresponding to the given uid.
        )r1   r   KeyError)r   r   entrys      r   getpwuidzUserDatabase.getpwuidq   s2     [[ 	E||s"	 jr   r	   c                     t        |t              st        dt        |             | j                  D ]  }|j
                  |k(  s|c S  t               )zM
        Return the user record corresponding to the given username.
        z%getpwuam() argument must be str, not )
isinstancer.   	TypeErrortyper1   r   r>   )r   r	   r?   s      r   getpwnamzUserDatabase.getpwnamz   sS     $$CDJ<PQQ[[ 	E}}$	 jr   c                     | j                   S )z4
        Return a list of all user records.
        r5   r"   s    r   getpwallzUserDatabase.getpwall        {{r   r   N)r
   NN rJ   z/bin/sh)r*   r+   r,   r-   r   r   __annotations__r2   r/   r3   r   r.   r   r<   r@   rE   rG   r!   r   r   r   r   6   s     HcHc #!!)$)$ )$ c]	)$
 c])$ )$ )$ )$ 
)$VC K 	S 	[ 	${+ r   c                   R    e Zd ZdZdededededededed	ed
eddfdZdefdZd Zy)_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.
    r7   r
   
lastChangeminmaxwarninactexpireflagr   Nc
                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y r   	sp_namsp_pwd	sp_lstchgsp_minsp_maxsp_warnsp_inact	sp_expiresp_flag
r   r7   r
   rN   rO   rP   rQ   rR   rS   rT   s
             r   r   z_ShadowRecord.__init__   sC     #r   c                      y)N	   r!   r"   s    r   r#   z_ShadowRecord.__len__   r$   r   c           	          | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  f	|   S r   rV   r&   s     r   r(   z_ShadowRecord.__getitem__   sU    KKKKNNKKKKLLMMNNLL

 
 
	r   r)   r!   r   r   rM   rM      s      	
       
, r   rM   c                   p    e Zd ZU dZee   ed<   ddZdedede	d	e	d
e	de	de	de	de	ddfdZ
dedefdZd Zy)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
    r1   r   Nc                     g | _         y r   r5   r"   s    r   r   zShadowDatabase.__init__   r6   r   r7   r
   rN   rO   rP   rQ   rR   rS   rT   c
                 \    | j                   j                  t        |||||||||		             y)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)r1   r:   rM   r`   s
             r   r<   zShadowDatabase.addUser   s2    P 	(JS$vt	
r   c                     t        |t              st        dt        |             | j                  D ]  }|j
                  |k(  s|c S  t        |      )zT
        Return the shadow user record corresponding to the given username.
        z%getspnam() argument must be str, not )rB   r.   rC   rD   r1   rW   r>   )r   r7   r?   s      r   getspnamzShadowDatabase.getspnam   sW     (C(CDNCSTUU[[ 	E||x'	 x  r   c                     | j                   S )z;
        Return a list of all shadow user records.
        r5   r"   s    r   getspallzShadowDatabase.getspall  rH   r   rI   )r*   r+   r,   r-   r   rM   rK   r   r.   r/   r<   rh   rj   r!   r   r   r   r      s     ,
,
 ,
 	,

 ,
 ,
 ,
 ,
 ,
 ,
 
,
\	! 	! 	!r   N)	r-   typingr   r   __all__r   r   rM   r   r!   r   r   <module>rm      sI   
 "+
,% %PS Sl+ +\M Mr   