o a @sdZddlZdZddZejdkrddlZddlmZmZm Z m Z m Z m Z m Z mZmZddlmZmZmZdZd Zd Zee ee krFe Zne Ze ZGd d d eZGd dde ZGdddeZeeZejjZee_eeeeeege_ ejj!Z!ee!_eeeeege!_ ddZ"ddZ#dSzddl$Z$e$jZe$jZe$jZWne%e&fydZZZddZ"ddZ#YdSwddZ"ddZ#dS)aw Portable file locking utilities. Based partially on an example by Jonathan Feignberg in the Python Cookbook [1] (licensed under the Python Software License) and a ctypes port by Anatoly Techtonik for Roundup [2] (license [3]). [1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203 [2] https://sourceforge.net/p/roundup/code/ci/default/tree/roundup/backends/portalocker.py [3] https://sourceforge.net/p/roundup/code/ci/default/tree/COPYING.txt Example Usage:: >>> from django.core.files import locks >>> with open('./file', 'wb') as f: ... locks.lock(f, locks.LOCK_EX) ... f.write('Django') N)LOCK_EXLOCK_SHLOCK_NBlockunlockcCst|dr |S|S)zCGet a filedescriptor from something which could be a file or an fd.fileno)hasattrrfr 9/usr/lib/python3/dist-packages/django/core/files/locks.py_fdsr nt) POINTER StructureUnionbyrefc_int64c_ulongc_void_psizeofwindll)BOOLDWORDHANDLEc@seZdZdefdefgZdS)_OFFSETOffset OffsetHighN)__name__ __module__ __qualname__r_fields_r r r r r2src@s"eZdZdgZdefdefgZdS) _OFFSET_UNION_offsetPointerN)r r!r" _anonymous_rPVOIDr#r r r r r$7s r$c@s.eZdZdgZdefdefdefdefgZdS) OVERLAPPED _offset_unionInternal InternalHighhEventN)r r!r"r' ULONG_PTRr$rr#r r r r r)=sr)cCs2tt|}t}t||dddt|}t|SNrl)msvcrt get_osfhandler r) LockFileExrbool)r flagshfile overlappedretr r r rOsrcCs0tt|}t}t|dddt|}t|Sr/)r0r1r r) UnlockFileExrr3)r r5r6r7r r r rUsrcCdS)NFr r r4r r r recCr9NTr r r r r rir;cCs,z tt||WdStyYdSw)NTF)fcntlflockr BlockingIOErrorr:r r r rms  cCstt|tjdSr<)r=r>r LOCK_UNr r r r rts)'__doc__os__all__r namer0ctypesrrrrrrrrrctypes.wintypesrrrrrrr.r(rr$r) LPOVERLAPPEDkernel32r2restypeargtypesr8rrr= ImportErrorAttributeErrorr r r r sN ,