Ϫf*dZddlZddlZddlmZddlmZdZddlmZejsddlm Z m Z m Z mZdZnd Z ddlZdd lmZd Zd Zd Z eZdZdZ dZ GddZdZddgZy#e$rdZ Y&wxYw)z& Filesystem-based interprocess mutex. N)time)platformc@tttdzS)Ni)strint _uniquefloat9/usr/lib/python3/dist-packages/twisted/python/lockfile.pyuniquer s s<>D() **r )rename)killreadlinkremovesymlinkFT) OpenProcessWc tdd|td#tj$rQ}|jdt k(rYd}~y|jdt k(rttjdd}~wwxYw)Nrz OpenProcess is required to fail.) r RuntimeError pywintypeserrorargsERROR_ACCESS_DENIEDERROR_INVALID_PARAMETEROSErrorerrnoESRCH)pidsignales r rr4ss GAq#&##EFF## 66!9 33VVAY"99!%++t44  s A>A91A99A>c|dztzdz}tjj|d}tj|d}t ||5}|j ||jddd t||y#1swYxYw#t$r,tj|tj|wxYw)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.newlinkrwN) r ospathjoinmkdir_openwriteflushr BaseExceptionrrmdir)valuefilename newlinkname newvalnamemodefs r rrEs nvx/*< WW\\+y9   :t $  GGEN GGI   ; )      IIj ! HH[ !  s"B BB5Ccp ttjj|dd}|5|j }ddd|S#1swYSxYw#t $rV}|j t jk(s|j t jk(rt |j dd}~wwxYw)zq Read the contents of C{filename}. See the above comment block as to why this is needed. rrN) r)r%r&r'readrrENOENTEIO)r/fObjresultr!s r rr`s h :C@D  % %M %M ww%,,&!''UYY*>aggt,,  s#*AA  A B5AB00B5ctjtjj|dtj|y)Nr)r%rr&r'r-)r/s r rmlinkr<rs) "'',,x34 r c*eZdZdZdZdZdZdZdZy)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__zFilesystemLock.__init__s  r cd} tttj|jd|_||_y#t $r}t r1|jtjtjfvrYd}~y|jtjk(r, t|j}nd#t $rX}|jtjk(r Yd}~Yd}~t r&|jtjk(r Yd}~Yd}~yd}~wwxYw ttt|dn#t $r}|jtjk(r` t!|jn=#t $r1}|jtjk(rYd}~Yd}~Yd}~d}~wwxYwd}Yd}~Yd}~d}~wwxYwYd}~yd}~wwxYw)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)rrr%getpidr@r_windowsrEACCESr8EEXISTrr7rrrr<lockedclean)rArIr!rs r lockzFilesystemLock.locksc, BIIK($))4XDKDJ[* ELL%))+D D!77ell*&tyy1" 77ell2%H%!''U\\*A $)5 + S1-"77ekk1& &tyy 1#*&#$77ell#:%-H % &%*E$H !U* s1A G2GG%B;:G; DD!G*#D GDDG D<;G< GG#E98G9 F3F.G#G-F..F33G8GGGGGGct|j}t|tjk7rt d|jdt |jd|_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. zLock z not owned by this processFN)rr@rr%rD ValueErrorr<rH)rArs r unlockzFilesystemLock.unlocksPtyy! s8ryy{ "uTYYM1KLM Mtyy r ) __name__ __module__ __qualname____doc__rIrHrBrJrMr r r r>r>ws#$ E F;z r r>ct|}d} |j}|r|j| S#|r|jwwxYw)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>rJrM)r@lr:s r isLockedrTsL tA F  HHJ:  HHJ s 4A rT)rQrr%rrtwisted.python.runtimerr r isWindowsrrrr<rrErwin32apirrr ImportErroropenr)r>rT__all__r r r r[s   %++x<<HHG( "$ G E6$ ccL( Z (K s A11A;:A;