Ë
    oj*  ã                   óü   — d Z ddlZddlZddlmZ ddlmZ d„ ZddlmZ  ej                  «       sddlm
Z
mZmZmZ dZnd	Z	 ddlZdd
lmZ dZdZd„ Z
eZd„ Zd„ Zd„ Z G d„ d«      Zd„ ZddgZy# e$ r dZ
Y Œ&w xY w)z&
Filesystem-based interprocess mutex.
é    N)Útime)Úplatformc                  ó@   — t        t        t        «       dz  «      «      S )Niè  )ÚstrÚintÚ_uniquefloat© ó    ú9/usr/lib/python3/dist-packages/twisted/python/lockfile.pyÚuniquer      s   € ÜŒs”<“> DÑ(Ó)Ó*Ð*r
   )Úrename)ÚkillÚreadlinkÚremoveÚsymlinkFT)ÚOpenProcessé   éW   c                 ó  — 	 t        dd| «       t        d«      ‚# t        j                  $ rQ}|j                  d   t
        k(  rY d }~y |j                  d   t        k(  rt        t        j                  d «      ‚‚ d }~ww xY w)Nr   z OpenProcess is required to fail.)
r   ÚRuntimeErrorÚ
pywintypesÚerrorÚargsÚERROR_ACCESS_DENIEDÚERROR_INVALID_PARAMETERÚOSErrorÚerrnoÚESRCH)ÚpidÚsignalÚes      r   r   r   4   ss   € ð	GÜ˜A˜q #Ô&ô #Ð#EÓFÐFøô ×#Ñ#ò Ø—6‘6˜!‘9Ô 3Ò3ÜØ—V‘V˜A‘YÔ"9Ò9Ü!¤%§+¡+¨tÓ4Ð4Øûðús   ‚ šA>­A9Á1A9Á9A>c                 ó¦  — |dz   t        «       z   dz   }t        j                  j                  |d«      }t        j                  |«       d}t        ||«      5 }|j                  | «       |j                  «        ddd«       	 t        ||«       y# 1 sw Y   ŒxY w# t        $ r, t        j                  |«       t        j                  |«       ‚ w xY w)zŠ
        Write a file at C{filename} with the contents of C{value}. See the
        above comment block as to why this is needed.
        ú.z.newlinkr   ÚwN)r   ÚosÚpathÚjoinÚmkdirÚ_openÚwriteÚflushr   ÚBaseExceptionr   Úrmdir)ÚvalueÚfilenameÚnewlinknameÚ
newvalnameÚmodeÚfs         r   r   r   E   s¯   € ð  ‘n¤v£xÑ/°*Ñ<ˆÜ—W‘W—\‘\ +¨yÓ9ˆ
Ü
�‰�Ôð ˆä�:˜tÓ$ð 	¨Ø�G‰G�EŒNØ�G‰GŒI÷	ð	Ü�; Õ)÷	ð 	ûô ò 	Ü�I‰I�jÔ!Ü�H‰H�[Ô!Øð	ús   Á"BÂB ÂBÂ5Cc                 óp  — 	 t        t        j                  j                  | d«      d«      }|5  |j	                  «       }ddd«       |S # 1 sw Y   S xY w# t
        $ rV}|j                  t        j                  k(  s|j                  t        j                  k(  rt        |j                  d«      ‚‚ d}~ww xY w)zq
        Read the contents of C{filename}. See the above comment block as to why
        this is needed.
        r   ÚrN)	r)   r%   r&   r'   Úreadr   r   ÚENOENTÚEIO)r/   ÚfObjÚresultr!   s       r   r   r   `   s�   € ð
		ÜœŸ™Ÿ™ h°	Ó:¸CÓ@ˆDð ñ %ØŸ™›�÷%àˆM÷%àˆMûô ò 	Ø�w‰wœ%Ÿ,™,Ò&¨!¯'©'´U·Y±YÒ*>Ü˜aŸg™g tÓ,Ð,Øûð	ús#   ‚*A ®A	Á	AÁ	B5ÁAB0Â0B5c                 ó”   — t        j                  t         j                  j                  | d«      «       t        j                  | «       y )Nr   )r%   r   r&   r'   r-   )r/   s    r   Úrmlinkr<   r   s)   € Ü
�	‰	”"—'‘'—,‘,˜x¨Ó3Ô4Ü
�‰�Õr
   c                   ó*   — e Zd ZdZdZdZd„ Zd„ Zd„ Zy)ÚFilesystemLocka  
    A mutex.

    This relies on the filesystem property that creating
    a symlink is an atomic operation and that it will
    fail if the symlink already exists.  Deleting the
    symlink will release the lock.

    @ivar name: The name of the file associated with this lock.

    @ivar clean: Indicates whether this lock was released cleanly by its
        last owner.  Only meaningful after C{lock} has been called and
        returns True.

    @ivar locked: Indicates whether the lock is currently held by this
        object.
    NFc                 ó   — || _         y )N)Úname)Úselfr@   s     r   Ú__init__zFilesystemLock.__init__�   s	   € Øˆ�	r
   c                 ó²  — d}	 	 t        t        t        j                  «       «      | j                  «       d| _        || _        y# t
        $ �r‡}t        r1|j                  t        j                  t        j                  fv rY d}~y|j                  t        j                  k(  �r,	 t        | j                  «      }nd# t
        $ rX}|j                  t        j                  k(  r	Y d}~Y d}~Œçt        r&|j                  t        j                  k(  r	Y d}~Y d}~y‚ d}~ww xY w	 t        �t        t        |«      d«       n�# t
        $ rƒ}|j                  t        j                  k(  r`	 t!        | j                  «       n=# t
        $ r1}|j                  t        j                  k(  rY d}~Y d}~Y d}~�Œª‚ d}~ww xY wd}Y d}~Y d}~�Œ¿‚ d}~ww xY wY d}~y‚ d}~ww xY w)zç
        Acquire this lock.

        @rtype: C{bool}
        @return: True if the lock is acquired, false otherwise.

        @raise OSError: Any exception L{os.symlink()} may raise,
            other than L{errno.EEXIST}.
        TNFr   )r   r   r%   Úgetpidr@   r   Ú_windowsr   ÚEACCESr8   ÚEEXISTr   r7   r   r   r   r<   ÚlockedÚclean)rA   rI   r!   r   s       r   ÚlockzFilesystemLock.lock�   sc  € ð ˆØð,ÜœœBŸI™I›KÓ(¨$¯)©)Ô4ðX ˆDŒKØˆDŒJØøô[ ó *Ý §¡¬E¯L©L¼%¿)¹)Ð+DÑ Dô !Ø—7‘7œeŸl™lÓ*ðÜ& t§y¡yÓ1™øÜ"ò ØŸ7™7¤e§l¡lÒ2÷ %˜HÝ%¨!¯'©'´U·\±\Ò*A÷ $) 5ØûðúðÜÐ+Ü ¤ S£¨1Ô-ùÜ"ò ØŸ7™7¤e§k¡kÒ1ð&Ü & t§y¡yÕ 1øÜ#*ò &Ø#$§7¡7¬e¯l©lÒ#:÷ %-¥HØ %ûð&úð %*˜Eß$™HØûðúô  !ØûðU*úsÅ   …1A Á
GÁ2GÂGÂ%B;Â:GÂ;	DÃDÃ!GÃ*#DÄGÄDÄDÄGÄ D<Ä;GÄ<	GÅGÅ#E9Å8GÅ9	F3ÆF.ÆGÆ#GÆ-F.Æ.F3Æ3GÆ8GÇGÇGÇGÇGÇGc                 óØ   — t        | j                  «      }t        |«      t        j                  «       k7  rt        d| j                  ›d�«      ‚t        | j                  «       d| _        y)zå
        Release this lock.

        This deletes the directory with the given name.

        @raise OSError: Any exception L{os.readlink()} may raise.
        @raise ValueError: If the lock is not owned by this process.
        zLock z not owned by this processFN)r   r@   r   r%   rD   Ú
ValueErrorr<   rH   )rA   r   s     r   ÚunlockzFilesystemLock.unlockÍ   sP   € ô �t—y‘yÓ!ˆÜˆs‹8”r—y‘y“{Ò"Ü˜u T§Y¡Y MÐ1KÐLÓMÐMÜˆt�y‰yÔØˆ�r
   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rI   rH   rB   rJ   rM   r	   r
   r   r>   r>   w   s#   „ ñð$ €EØ€Fòò;ózr
   r>   c                 ó˜   — t        | «      }d}	 |j                  «       }|r|j                  «        | S # |r|j                  «        w w xY w)zß
    Determine if the lock of the given name is held or not.

    @type name: C{str}
    @param name: The filesystem path to the lock to test

    @rtype: C{bool}
    @return: True if the lock is held, False otherwise.
    N)r>   rJ   rM   )r@   Úlr:   s      r   ÚisLockedrT   Ý   sL   € ô 	�tÓ€AØ€FðØ—‘“ˆáØ�H‰HŒJØˆ:Ðøñ Ø�H‰H�Jð ús	   �4 ´A	rT   )rQ   r   r%   r   r   Útwisted.python.runtimer   r   r   Ú	isWindowsr   r   r   r<   r   rE   r   Úwin32apir   r   r   ÚImportErrorÚopenr)   r>   rT   Ú__all__r	   r
   r   ú<module>r[      s«   ðñó
 Û 	Ý %å +ò+õ à€x×ÑÔß<Ó<à�Hà€HðGÛÝ(ð  ÐØ"$Ðò
	Gð €Eòò6ò$÷
cñ còLð( ˜ZÐ
(�øðK ò ØŠðús   Á
A1 Á1A;Á:A;