o bL@sTdZddlmZddgZGdddZGdddZGdd d ZGd ddZd S) zM L{twisted.python.fakepwd} provides a fake implementation of the L{pwd} API. )List UserDatabaseShadowDatabasec@sPeZdZdZdededededededed d fd d Zd efd dZddZd 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. namepassworduidgidgecoshomeshellreturnNcCs.||_||_||_||_||_||_||_dSNpw_name pw_passwdpw_uidpw_gidpw_gecospw_dirpw_shell)selfrrrr r r r r8/usr/lib/python3/dist-packages/twisted/python/fakepwd.py__init__s  z_UserRecord.__init__cCdS)Nrrrrr__len__'z_UserRecord.__len__cCs$|j|j|j|j|j|j|jf|Srrrindexrrr __getitem__*sz_UserRecord.__getitem__ __name__ __module__ __qualname____doc__strintrrr"rrrrrs*  rc@seZdZUdZeeed<dddZdeded e d e d ed ed eddfddZ d e defddZ dedefddZ deefddZ dS)rz 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. _usersr NcC g|_dSrr*rrrrrA zUserDatabase.__init__usernamerrr r r r c Cs |jt|||||||dS)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*appendr)rr.rrr r r r rrraddUserDs"zUserDatabase.addUsercCs$|jD] }|j|kr|Sqt)zH Return the user record corresponding to the given uid. )r*rKeyError)rrentryrrrgetpwuidjs  zUserDatabase.getpwuidrcCs@t|tstdt||jD] }|j|kr|Sqt)zM Return the user record corresponding to the given username. z%getpwuam() argument must be str, not ) isinstancer( TypeErrortyper*rr1)rrr2rrrgetpwnamss   zUserDatabase.getpwnamcC|jS)z4 Return a list of all user records. r,rrrrgetpwall~zUserDatabase.getpwallr N)r$r%r&r'rr__annotations__rr(r)r0r3r7r9rrrrr6s0    &  c@sXeZdZdZdededededededed ed ed d fd dZd efddZddZd 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. r.r lastChangeminmaxwarninactexpireflagr Nc Cs:||_||_||_||_||_||_||_||_| |_dSr sp_namsp_pwd sp_lstchgsp_minsp_maxsp_warnsp_inact sp_expiresp_flag rr.rr>r?r@rArBrCrDrrrrs  z_ShadowRecord.__init__cCr)N rrrrrrrz_ShadowRecord.__len__c Cs,|j|j|j|j|j|j|j|j|jf |SrrEr rrrr"s z_ShadowRecord.__getitem__r#rrrrr=s2    r=c@steZdZUdZeeed<dddZdeded e d e d e d e d e de de ddfddZ dedefddZ ddZ dS)rz 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*r NcCr+rr,rrrrrr-zShadowDatabase.__init__r.rr>r?r@rArBrCrDc Cs$|jt||||||||| dS)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*r/r=rOrrrr0s (zShadowDatabase.addUsercCsBt|tstdt||jD] }|j|kr|Sqt|)zT Return the shadow user record corresponding to the given username. z%getspnam() argument must be str, not )r4r(r5r6r*rFr1)rr.r2rrrgetspnams   zShadowDatabase.getspnamcCr8)z; Return a list of all shadow user records. r,rrrrgetspallr:zShadowDatabase.getspallr;) r$r%r&r'rr=r<rr(r)r0rQrRrrrrrs6     . N)r'typingr__all__rrr=rrrrrs (O.