
    h*                        S r SSKrSSKrSSKJr  SSKJr  S rSSKJr  \R                  " 5       (       d  SSKJ
r
JrJrJr  SrOS	r SSKrSS
KJr  SrSrS r
\rS rS rS r " S S5      rS rSS/rg! \ a    Sr
 N'f = f)z&
Filesystem-based interprocess mutex.
    N)time)platformc                  @    [        [        [        5       S-  5      5      $ )Ni  )strint_uniquefloat     ^/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/python/lockfile.pyuniquer      s    s<>D()**r
   )rename)killreadlinkremovesymlinkFT)OpenProcess   W   c                     [        SSU 5        [        S5      e! [        R                   aS  nUR                  S   [
        :X  a   S nAg UR                  S   [        :X  a  [        [        R                  S 5      ee S nAff = f)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Aq#& ##EFF ## 66!9 33VVAY"99!%++t44s    BA<
2A<<Bc                    US-   [        5       -   S-   n[        R                  R                  US5      n[        R                  " U5        Sn[        X45       nUR                  U 5        UR                  5         SSS5         [        X!5        g! , (       d  f       N= f! [         a.    [        R                  " U5        [        R                  " U5        e f = f)zr
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     nvx/*<WW\\+y9

 :$GGENGGI %	;) %$  	IIj!HH[!	s   "BB 
B8Cc                     [        [        R                  R                  U S5      S5      nU   UR	                  5       nSSS5        U$ ! , (       d  f       W$ = f! [
         aX  nUR                  [        R                  :X  d  UR                  [        R                  :X  a  [        UR                  S5      ee SnAff = f)zY
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  	ww%,,&!''UYY*>aggt,,	s#   *A A		
A
B=%AB88B=c                     [         R                  " [         R                  R                  U S5      5        [         R                  " U 5        g )Nr   )r%   r   r&   r'   r-   )r/   s    r   rmlinkr<   r   s)    
		"'',,x34
r
   c                   2    \ rS rSrSrSrSrS rS rS r	Sr
g)	FilesystemLockw   a  
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                     Xl         g )N)name)selfrA   s     r   __init__FilesystemLock.__init__   s    	r
   c                    Sn  [        [        [        R                  " 5       5      U R                  5        SU l        Xl        g! [
         Ga  n[        (       a3  UR                  [        R                  [        R                  4;   a   SnAgUR                  [        R                  :X  Ga<   [        U R                  5      nOm! [
         a`  nUR                  [        R                  :X  a
   SnA SnAM  [        (       a'  UR                  [        R                  :X  a	   SnA SnAge SnAff = f [        b  [        [        U5      S5        O! [
         a  nUR                  [        R                  :X  ad   [!        U R                  5        O@! [
         a3  nUR                  [        R                  :X  a   SnA SnA SnAGM  e SnAff = fSn SnA SnAGM  e SnAff = f SnAge SnAff = f)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%   getpidrA   r   _windowsr   EACCESr8   EEXISTr   r7   r   r   r   r<   lockedclean)rB   rK   r!   r   s       r   lockFilesystemLock.lock   se    ,BIIK($))4X DKJ[  *8ELL%))+D D !77ell*&tyy1" 77ell2 %H%X!''U\\*A $)5+ S1-" 77ekk1& &tyy 1#* &#$77ell#: %-H %& %*E$H  !U*s   2A G/9G*G*.CG*
D.D),G*6)D)G*(D))D..G*2EG*
G!G8FG
GG6G:G*GGGG*GG!!G*)G**G/c                     [        U R                  5      n[        U5      [        R                  " 5       :w  a  [        SU R                  < S35      e[        U R                  5        SU l        g)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   rA   r   r%   rF   
ValueErrorr<   rJ   )rB   r   s     r   unlockFilesystemLock.unlock   sP     tyy!s8ryy{"uTYYM1KLMMtyyr
   )rK   rJ   rA   )__name__
__module____qualname____firstlineno____doc__rK   rJ   rC   rL   rP   __static_attributes__r	   r
   r   r>   r>   w   s#    $ EF;zr
   r>   c                     [        U 5      nSn UR                  5       nU(       a  UR                  5         U(       + $ ! U(       a  UR                  5         f f = f)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>   rL   rP   )rA   lr:   s      r   isLockedrZ      sL     	tAFHHJ: HHJ s	   = ArZ   )rV   r   r%   r   r   twisted.python.runtimer   r   r   	isWindowsr   r   r   r<   r   rG   r   win32apir   r   r   ImportErroropenr)   r>   rZ   __all__r	   r
   r   <module>ra      s   
  	 % ++ <<HHG(  "$
	G E6$
c cL( Z
(K  s   
A6 6B B