
    qh1                     .   S r SSKrSSKrSSKrSSKrSSKrSSKJrJr  SSK	J
r
  SSKJr  SSKJr  SSKJr  SSKJrJr  \R(                  " \5      r\R.                  \R0                  -   S	-   r\" \5      R6                  rS
 rS rS rS r  " S S\5      r!g)zP
This module contains an C{L{OpenIDStore}} implementation backed by
flat files.
    N)EEXISTENOENT)mkstemp)Association)OpenIDStore)nonce)	cryptutiloidutil.c                     [         R                  " [        R                  " U 5      5      n[	        U5      nUR                  SS5      nUR                  SS5      nUR                  SS5      n[        U5      $ )N   +   _   /   .   =    )r
   toBase64r	   sha1	bytearrayreplacebytes)sh64s     H/var/www/html/env/lib/python3.13/site-packages/openid/store/filestore.py_safe64r      s^    


9>>!,
-C
C.C
++dD
!C
++dD
!C
++dC
 C:r   c                     / nU  HC  n[        U5      (       a  UR                  U5        M&  UR                  S[        U5      -  5        ME     SR                  U5      $ )Nz_%02X )_isFilenameSafeappendordjoin)r   filename_chunkscs      r   _filenameEscaper$   %   sR    O1""1%""7SV#34	 
 77?##r   c                      [         R                  " U 5        g! [         a  nUR                  [        :X  a   SnAge SnAff = f)zcAttempt to remove a file, returning whether the file existed at
the time of the call.

str -> bool
   Nr   )osunlinkOSErrorerrnor   )filenamewhys     r   _removeIfPresentr-   /   s<    

		(   99s    
A==Ac                      [         R                  " U 5        g! [         aC  nUR                  [        :w  d$  [         R
                  R                  U 5      (       d  e  SnAgSnAff = f)zCreate dir_name as a directory if it does not exist. If it
exists, make sure that it is, in fact, a directory.

Can raise OSError

str -> NoneType
N)r'   makedirsr)   r*   r   pathisdir)dir_namer,   s     r   
_ensureDirr3   B   sI    
H 99bggmmH&=&= '>s    
A&9A!!A&c                   j    \ rS rSrSrS rS rS rS rS r	SS	 jr
S
 rS rS rS rS rS rS rSrg)FileOpenIDStoreQ   a  
This is a filesystem-based store for OpenID associations and
nonces.  This store should be safe for use in concurrent systems
on both windows and unix (excluding NFS filesystems).  There are a
couple race conditions in the system, but those failure cases have
been set up in such a way that the worst-case behavior is someone
having to try to log in a second time.

Most of the methods of this class are implementation details.
People wishing to just use this store need only pay attention to
the C{L{__init__}} method.

Methods of this object can raise OSError if unexpected filesystem
conditions, such as bad permissions or missing directories, occur.
c                    [         R                  R                  [         R                  R                  U5      5      n[         R                  R	                  US5      U l        [         R                  R	                  US5      U l        [         R                  R	                  US5      U l        SU l        U R                  5         g)z
Initializes a new FileOpenIDStore.  This initializes the
nonce and association directories, which are subdirectories of
the directory passed in.

@param directory: This is the directory to put the store
    directories in.

@type directory: C{str}
noncesassociationstempi`T  N)
r'   r0   normpathabspathr!   	nonce_dirassociation_dirtemp_dirmax_nonce_age_setup)self	directorys     r   __init__FileOpenIDStore.__init__b   s{     GG$$RWW__Y%?@	i:!ww||I~F Y7(r   c                     [        U R                  5        [        U R                  5        [        U R                  5        g)zQMake sure that the directories in which we store our data
exist.

() -> NoneType
N)r3   r=   r>   r?   rB   s    r   rA   FileOpenIDStore._setup|   s*     	4>>"4''(4==!r   c                     [        U R                  S9u  p [        R                  " US5      nX24$ !   [	        U5        e = f)a'  Create a temporary file on the same filesystem as
self.association_dir.

The temporary directory should not be cleaned if there are any
processes using the store. If there is no active process using
the store, it is safe to remove all of the files in the
temporary directory.

() -> (file, str)
)dirwb)r   r?   r'   fdopenr-   )rB   fdnamefile_objs       r   _mktempFileOpenIDStore._mktemp   sC     t}}-	yyT*H>!	T"s   1 ?c                 b   UR                  S5      S:X  a  [        SU-  5      eUR                  SS5      u  p4[        UR                  SS5      S   5      n[	        U5      nU(       a  [	        U5      nOSnU< SU< SU< SU< 3n[
        R                  R                  U R                  U5      $ )	a  Create a unique filename for a given server url and
handle. This implementation does not assume anything about the
format of the handle. The filename that is returned will
contain the domain name from the server URL for ease of human
inspection of the data directory.

(str, str) -> str
://zBad server URL: %rr&   /r   r   -)	find
ValueErrorsplitr$   r   r'   r0   r!   r>   )	rB   
server_urlhandleprotorestdomainurl_hashhandle_hashr+   s	            r   getAssociationFilename&FileOpenIDStore.getAssociationFilename   s     ??5!R'1J>?? &&ua0 C!3A!67:&!&/KK$)68[Iww||D00(;;r   c                    UR                  5       nU R                  XR                  5      nU R                  5       u  pV  UR	                  U5        [
        R                  " UR                  5       5        UR                  5          [
        R                  " Xd5        g! UR                  5         f = f! [         ay  nUR                  [        :w  a  e  [
        R                  " U5        O,! [         a  nUR                  [        :X  a   SnAO	e SnAff = f[
        R                  " Xd5         SnAgSnAff = f!   [        U5        e = f)zSStore an association in the association directory.

(str, Association) -> NoneType
N)	serializera   r[   rP   writer'   fsyncfilenocloserenamer)   r*   r   r(   r   r-   )rB   rZ   associationassociation_sr+   tmp_filetmpr,   s           r   storeAssociation FileOpenIDStore.storeAssociation   s    
 $--/..z;M;MN	!}-*+ )		#(    )99&
IIh' yyF*	 		#((#)$	 S!sr    5B 5D8 B2 B//D8 2
D5<D0C)(D0)
D3DD0DDD0+D8 0D55D8 8ENc                 V   Uc  SnU R                  X5      nU(       a  U R                  U5      $ [        R                  " U R                  5      n/ n[        R
                  R                  U5      nU H,  nUR                  U5      (       d  M  UR                  U5        M.     / nU H`  n[        R
                  R                  U R                  U5      n	U R                  U	5      n
U
c  MC  UR                  U
R                  U
45        Mb     UR                  5         U(       a	  US   u  pU$ g)zRetrieve an association. If no handle is specified, return
the association with the latest expiration.

(str, str or NoneType) -> Association or NoneType
Nr   rT   )ra   _getAssociationr'   listdirr>   r0   basename
startswithr   r!   issuedsort)rB   rZ   r[   r+   association_filesmatching_filesrN   association_filematching_associations	full_namerj   _assocs                r   getAssociationFileOpenIDStore.getAssociation   s    >F ..zB''11 "

4+?+? @N77##H-D$5 #..t44"))*:; %6 %'!&GGLL)=)=tD	"229=*)00$++[9;	 ' "&&( %226
r   c                     [        US5      n UR	                  5       nUR                  5          [        R                  " U5      nUR                  S:X  a  [        U5        g U$ ! [         a  nUR                  [        :X  a   S nAg e S nAff = f! UR                  5         f = f! [         a    [        U5         g f = f)Nrbr   )openIOErrorr*   r   readrh   r   deserializerX   r-   	expiresIn)rB   r+   
assoc_filer,   assoc_srj   s         r   rq   FileOpenIDStore._getAssociation  s    	h-J	 oo'G	%11':K   A%X&/  	yyF"	   	X&	s9   A$ B B% $
B.BBBB"%B=<B=c                 d    U R                  X5      nUc  gU R                  X5      n[        U5      $ )zSRemove an association if it exists. Do nothing if it does not.

(str, str) -> bool
r   )r~   ra   r-   )rB   rZ   r[   r}   r+   s        r   removeAssociation!FileOpenIDStore.removeAssociation!  s7    
 ##J7=22:FH#H--r   c                    [        U[        R                  " 5       -
  5      [        R                  :  a  gU(       a  UR	                  SS5      u  pEOSu  pE[        UR	                  SS5      S   5      n[        U5      n[        U5      nSX$XgU4-  n	[        R                  R                  U R                  U	5      n	 [        R                  " U	[        R                  [        R                  -  [        R                  -  S5      n
[        R                  " U
5        g	! [          a  nUR"                  [$        :X  a   S
nAge S
nAff = f)z1Return whether this nonce is valid.

str -> bool
FrS   r&   )r   r   rU   r   z%08x-%s-%s-%s-%s   TN)abstimer   SKEWrY   r$   r   r'   r0   r!   r=   r   O_CREATO_EXCLO_WRONLYrh   r)   r*   r   )rB   rZ   	timestampsaltr\   r]   r^   r_   	salt_hashr+   rM   r,   s               r   useNonceFileOpenIDStore.useNonce-  s   
 y499;&'%**4$**5!4KE4 !KE C!3A!67:&DM	%6)2)4 4 77<<9		2::		#9BKK#GOB HHRL  	yyF"		s   <AD 
E%D?>D??Ec                    / n[         R                  " U R                  5       Vs/ s H-  n[         R                  R	                  U R                  U5      PM/     nnU HZ  n [        US5      n UR                  5       nUR                  5          [        R                  " U5      nUR                  XG45        M\     U$ s  snf ! UR                  5         f = f! [         a    [        U5         M  f = f! [         aQ  nUR                  [        :X  a7  [         R#                  U< SU R$                  R&                  < S35         S nAM  e S nAff = f)Nr   z disappeared during z._allAssocs)r'   rr   r>   r0   r!   r   r   rh   r   r   r   rX   r-   r   r*   r   logger	exception	__class____name__)	rB   all_associationsr+   association_filenamesassociation_filenamery   r   rj   r,   s	            r   
_allAssocsFileOpenIDStore._allAssocsO  s:    JJt';';<!
< GGLL--x8< 	 !
 %: =#'(<d#C -.335G$**,="-"9"9'"BK %++-;=+ %:0  9!
" %**,
 " ;$%9:;  99&$$,dnn.E.E&G H H sB   4B=!C3.CCCC0/C03
E=AE	E		Ec                 D    U R                  5         U R                  5         g)zRemove expired entries from the database. This is
potentially expensive, so only run when it is acceptable to
take time.

() -> NoneType
N)cleanupAssociationscleanupNoncesrG   s    r   cleanupFileOpenIDStore.cleanupp  s     	  "r   c                     SnU R                  5        H'  u  p#UR                  S:X  d  M  [        U5        US-  nM)     U$ )Nr   r&   )r   r   r-   )rB   removedassoc_filenamer}   s       r   r   #FileOpenIDStore.cleanupAssociationsz  s?    %)__%6!N!# 01 &7 r   c                 ~   [         R                  " U R                  5      n[        R                  " 5       nSnU H  nUR	                  SS5      S   n[        US5      n[        XR-
  5      [        R                  :  d  ME  [         R                  R                  U R                  U5      n[        U5        US-  nM     U$ )Nr   rV   r&      )r'   rr   r=   r   rY   intr   r   r   r0   r!   r-   )rB   r8   nowr   nonce_fnamer   r+   s          r   r   FileOpenIDStore.cleanupNonces  s    DNN+iik!K#))#q1!4IIr*I9?#ejj077<<D *1 " r   )r>   r@   r=   r?   )N)r   
__module____qualname____firstlineno____doc__rD   rA   rP   ra   rn   r~   rq   r   r   r   r   r   r   __static_attributes__ r   r   r5   r5   Q   sL     4"&<0(T(T8
. D Br   r5   )"r   stringr'   os.pathr   loggingr*   r   r   tempfiler   openid.associationr   openid.store.interfacer   openid.storer   openidr	   r
   	getLoggerr   r   ascii_lettersdigits_filename_allowedset__contains__r   r   r$   r-   r3   r5   r   r   r   <module>r      s   
  	       * .  %			8	$((6==83> '(55$&~k ~r   