VL i0>ddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z e Z ddl Z ddlmZej*Zej.Zej2Zej4j6Zej8Zej:Zej4j<Zej4j>Zej@Z ej4jBZ!ej4jDZ"ej4jFZ#ejHZ$ejJZ%ejLZ&ejNZ'dZ(dZ)dd l*m+Z+m,Z,Gd d Z-d Z.dd Z/dZ0ddZ1ddZ2ddZ3dZ4dZ5GddZ6GddZ7y#e$rddlmZmZeZddZY`wxYw)N)BytesIO)StaticWindowMapManagerSlidingWindowMapManagerSlidingWindowMapBuffer) unpack_from)unpackcalcsizec t|}t|||||zS#t$rt|}|t|<Y1wxYwN)__calcsize_cacheKeyErrorr r)fmtdataoffsetsizes P/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/gitdb/util.pyrr!sP )#C(D c4 677  )C=D$( S ! )s ==ctjdk(r"tdD] } ||i|cS||i|S||i|S#t$rt j dY?wxYw)Nwin32 g?)sysplatformrange Exceptiontimesleep)funcargskwargs_s r_retryr Dsv ||wr A T,V,, T$V$$T$V$$   3 s>AAc<ttjg|i|Sr )r osremove)rrs rr#r#Rs ")) -d -f --) NULL_BIN_SHA NULL_HEX_SHAc4eZdZdZdZd dZdZdZdZdZ y) _RandomAccessBytesIOzWrapper to provide required functionality in case memory maps cannot or may not be used. This is only really required in python 2.4_sioc$t||_yr )rr))selfbufs r__init__z_RandomAccessBytesIO.__init__gs CL r$c.t|j|Sr )getattrr)r+attrs r __getattr__z _RandomAccessBytesIO.__getattr__jstyy$''r$c4t|jSr )lengetvaluer+s r__len__z_RandomAccessBytesIO.__len__ms4==?##r$c(|j|Sr r5)r+is r __getitem__z _RandomAccessBytesIO.__getitem__ps}}q!!r$c(|j||Sr r9)r+startends r __getslice__z!_RandomAccessBytesIO.__getslice__ss}}uS))r$N)) __name__ __module__ __qualname____doc__ __slots__r-r2r7r;r?r$rr(r(as%?I!($"*r$r(c< t|S#t$r|cYSwxYw)z Return the integer representation of the byte string. This supports Python 3 byte arrays as well as standard strings. )ord TypeError)bs rbyte_ordrKws$ 1v s cz tj|S#t$rddl}|j|}|cYSwxYw)z`A python2.4 workaround for the sha/hashlib module fiasco **Note** From the dulwich project rN)hashlibsha1 NameErrorsha)sourcerPrNs rmake_sharRs:||F## wwv s  ::c|dk(r tdS tjd|S#t$rtd|zcYSwxYw)zB:return: a file-protocol accessible memory block of the given sizerr$)r(mmapOSError)rs rallocate_memoryrXsJ qy#C((2yyT"" 2 $EDL11 2s(AAc |r' tj|dtjS tj |tj|j }|r t|S|S#t$rFtj|tj|j tjcYSwxYw#t$rYwxYw)a:return: read-only contents of the file represented by the file descriptor fd :param fd: file descriptor opened for reading :param stream: if False, random access is provided, otherwise the stream interface is provided. :param allow_mmap: if True, its allowed to map the contents into memory, which allows large files to be handled and accessed efficiently. The file-descriptor will change its position if this is Falser)access)rV ACCESS_READrWr"fstatst_sizereadr()fdstream allow_mmapcontentss rfile_contents_rorcs   TyyQt/?/?@@ wwr288B<//0H #H-- O TyyRXXb\%9%9$BRBRSS T    s/C%A..A B=:C<B==C C  C c tj|tjttddz|z} t |||t |S#t |wxYw)a<Get the file contents at filepath as fast as possible :return: random access compatible memory of the given filepath :param stream: see ``file_contents_ro`` :param allow_mmap: see ``file_contents_ro`` :param flags: additional flags to pass to os.open :raise OSError: If the file could not be opened **Note** for now we don't try to use O_NOATIME directly as the right value needs to be shared per database in fact. It only makes a real difference for loose object databases anyway, and they use it with the help of the ``flags`` parameterO_BINARYr)r"openO_RDONLYr/rcclose)filepathr`raflagsr_s rfile_contents_ro_filepathrksK 2;;Z)CCeK LBFJ7 b b s A A cBttj||S)z :return: a buffer compatible object which uses our mapped memory manager internally ready to read the whole given filepath)rj)rmman make_cursor)rirjs rsliding_ro_bufferros "$"2"28"|j|jyyr )rrollbackr6s r__del__zLockedFD.__del__$s 88  MMO r$c d|jzS)Nz%s.lock)rr6s r _lockfilepathzLockedFD._lockfilepath)s4>>))r$c|jtd|jz||_ttdd}tj tj ztjz|z} t j|j|tdd}|st j|n||_ |j7 t j|jtj|z|_ |rddlm}||jS|jS#t$r"}td|jz|d}~wwxYw#t|jxYw) a Open the file descriptor for reading or writing, both in binary mode. :param write: if True, the file descriptor will be opened for writing. Other wise it will be opened read-only. :param stream: if True, the file descriptor will be wrapped into a simple stream object which supports only reading or writing :return: fd to read from or write to. It is still maintained by this instance and must not be closed directly :raise IOError: if the lock could not be retrieved :raise OSError: If the actual file could not be opened for reading **note** must only be called onceNzCalled %s multiple timesrer600z Lock at %r could not be obtained)FDStream)rAssertionErrorrfr/r"O_WRONLYO_CREATO_EXCLrintrhrrWrrgr# gitdb.streamr)r+writer`binarylockmoder_ers rrfz LockedFD.open,s1 ;; " !;dii!GH H Z+;;+bii7&@ \++-xUAGB  88  774>>2;;3GH  -DHH% %88O+ \>* IIh / $..#eQ- 0 8 r$N)FF)T) rArBrCrDrEr-rrrfrrrrFr$rrr s3 B/I  *2j+,r$r)r)r$)FT)FTr)8binasciir"rVrrerrnoiorsmmaprrrrmrMstructr ImportErrorrr dictr a2b_hexrwb2a_hexrrENOENTpathexistsmkdirrisdirrrdirnamebasenamejoinr^rrhfsyncr r# gitdb.constr%r&r(rKrRrXrcrkrortrxrzrrFr$rrsl    8"$               ''// 77   ww|| ww    %. **,  2":(K  @~~a 8'v8 8sFFF