
    che#                         S r SSKJrJrJr  SSKJr  SSKJrJ	r	  SSK
Jr  SSKJr  Sr " S S	5      r " S
 S5      r " S S5      r " S S5      rS r " S S\\\5      rg)z8Contains implementations of database retrieveing objects    )join	LazyMixin
hex_to_bin)
force_text)	BadObjectAmbiguousObjectName)chain)reduce)	ObjectDBR	ObjectDBW
FileDBBase
CompoundDB	CachingDBc                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)r      zgDefines an interface for object database lookup.
Objects are identified either by their 20 byte bin shac                     U R                   $ N)has_objselfshas     `C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\gitdb/db/base.py__contains__ObjectDBR.__contains__   s    ||    c                     [        S5      e)z
Whether the object identified by the given 20 bytes
    binary sha is contained in the database

:return: True if the object identified by the given 20 bytes
    binary sha is contained in the databaseTo be implemented in subclassNotImplementedErrorr   s     r   
has_objectObjectDBR.has_object"   s     ""ABBr   c                     [        S5      e)zF:return: OInfo instance
:param sha: bytes binary sha
:raise BadObject:r   r   r   s     r   infoObjectDBR.info+        ""ABBr   c                     [        S5      e)zK:return: OStream instance
:param sha: 20 bytes binary sha
:raise BadObject:r   r   r   s     r   streamObjectDBR.stream1   r%   r   c                     [        5       e)z+:return: amount of objects in this databaser   r   s    r   sizeObjectDBR.size7       !##r   c                     [        5       e)zGReturn iterator yielding 20 byte shas for all objects in this data baser   r*   s    r   sha_iterObjectDBR.sha_iter;   r-   r    N)__name__
__module____qualname____firstlineno____doc__r   r    r#   r'   r+   r/   __static_attributes__r1   r   r   r   r      s(    >CCC$$r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   B   z6Defines an interface to create objects in the databasec                     S U l         g r   _ostream)r   argskwargss      r   __init__ObjectDBW.__init__F   s	    r   c                 *    U R                   nXl         U$ )a:  
Adjusts the stream to which all data should be sent when storing new objects

:param stream: if not None, the stream to use, if None the default stream
    will be used.
:return: previously installed stream, or None if there was no override
:raise TypeError: if the stream doesn't have the supported functionalityr;   )r   r'   cstreams      r   set_ostreamObjectDBW.set_ostreamJ   s     --r   c                     U R                   $ )z
Return the output stream

:return: overridden output stream this instance will write to, or None
    if it will write to the default streamr;   r*   s    r   ostreamObjectDBW.ostreamV   s     }}r   c                     [        S5      e)a  
Create a new object in the database
:return: the input istream object with its sha set to its corresponding value

:param istream: IStream compatible instance. If its sha is already set
    to a value, the object will just be stored in the our database format,
    in which case the input stream is expected to be in object format ( header + contents ).
:raise IOError: if data could not be writtenr   r   )r   istreams     r   storeObjectDBW.store^   s     ""ABBr   r;   N)
r2   r3   r4   r5   r6   r?   rC   rF   rJ   r7   r1   r   r   r   r   B   s    @
	Cr   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )r   l   zyProvides basic facilities to retrieve files of interest, including
caching facilities to help mapping hexsha's to objectsc                 .   > [         TU ]  5         Xl        g)a1  Initialize this instance to look for its files at the given root path
All subsequent operations will be relative to this path
:raise InvalidDBRoot:
**Note:** The base will not perform any accessablity checking as the base
    might not yet be accessible, but become accessible before the first
    access.N)superr?   
_root_path)r   	root_path	__class__s     r   r?   FileDBBase.__init__q   s     	#r   c                     U R                   $ )z':return: path at which this db operatesrP   r*   s    r   rQ   FileDBBase.root_path|   s    r   c                 @    [        U R                  [        U5      5      $ )zn
:return: the given relative path relative to our database root, allowing
    to pontentially access datafiles)r   rP   r   )r   	rela_paths     r   db_pathFileDBBase.db_path   s     DOOZ	%:;;r   rU   )
r2   r3   r4   r5   r6   r?   rQ   rY   r7   __classcell__rR   s   @r   r   r   l   s    >$< <r   r   c                   "    \ rS rSrSrSS jrSrg)r      z/A database which uses caches to speed-up accessc                     g)aJ  
Call this method if the underlying data changed to trigger an update
of the internal caching structures.

:param force: if True, the update must be performed. Otherwise the implementation
    may decide not to perform an update if it thinks nothing has changed.
:return: True if an update was performed as something change indeedNr1   )r   forces     r   update_cacheCachingDB.update_cache   s    r   r1   NF)r2   r3   r4   r5   r6   ra   r7   r1   r   r   r   r      s    9Or   r   c                     [        U [        5      (       aD  U R                  5       nUR                  S U 5       5        S U 5        H  n[	        X15        M     gUR                  U 5        g)zbFill output list with database from db, in order. Deals with Loose, Packed
and compound databases.c              3   T   #    U  H  n[        U[        5      (       a  M  Uv   M      g 7fr   
isinstancer   .0dbs     r   	<genexpr>'_databases_recursive.<locals>.<genexpr>   s     I3RjZ.Hbb3   (	(c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   rf   rh   s     r   rk   rl      s     C2
2z(BBBrm   N)rg   r   	databasesextend_databases_recursiveappend)databaseoutputdbscdbs       r   rq   rq      sW     (J''  "I3IICCC - D 	hr   c                   f   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rSS jrS rSrU =r$ )r      zA database which delegates calls to sub-databases.

Databases are stored in the lazy-loaded _dbs attribute.
Define _set_cache_ to update it with your databasesc                 |   > US:X  a  [        5       U l        g US:X  a  [        5       U l        g [        TU ]  U5        g )N_dbs	_db_cache)listrz   dictr{   rO   _set_cache_)r   attrrR   s     r   r~   CompoundDB._set_cache_   s1    6>DI[ !VDNG%r   c                      U R                   U   $ ! [         a     Of = fU R                   H+  nUR                  U5      (       d  M  X R                   U'   Us  $    [	        U5      e)zD:return: database containing the given 20 byte sha
:raise BadObject:)r{   KeyErrorrz   r    r   )r   r   rj   s      r   	_db_queryCompoundDB._db_query   sd    
	>>#&& 		 ))B}}S!!&(s#	 
 ns    
c                 H     U R                  U5        g! [         a     gf = f)NTF)r   r   r   s     r   r    CompoundDB.has_object   s(    	NN3 		s    
!!c                 B    U R                  U5      R                  U5      $ r   )r   r#   r   s     r   r#   CompoundDB.info   s    ~~c"'',,r   c                 B    U R                  U5      R                  U5      $ r   )r   r'   r   s     r   r'   CompoundDB.stream   s    ~~c"))#..r   c                 @    [        S S U R                   5       S5      $ )z.:return: total size of all contained databasesc                 
    X-   $ r   r1   )xys     r   <lambda>!CompoundDB.size.<locals>.<lambda>   s    15r   c              3   @   #    U  H  oR                  5       v   M     g 7fr   )r+   rh   s     r   rk   "CompoundDB.size.<locals>.<genexpr>   s     *Iy7799y   r   )r
   rz   r*   s    r   r+   CompoundDB.size   s    (*Ityy*I1MMr   c                 4    [        S U R                   5       6 $ )Nc              3   @   #    U  H  oR                  5       v   M     g 7fr   )r/   rh   s     r   rk   &CompoundDB.sha_iter.<locals>.<genexpr>   s     9y{{}}yr   )r	   rz   r*   s    r   r/   CompoundDB.sha_iter   s    9tyy9::r   c                 ,    [        U R                  5      $ )z7:return: tuple of database instances we use for lookups)tuplerz   r*   s    r   ro   CompoundDB.databases   s    TYYr   c                     U R                   R                  5         SnU R                   H-  n[        U[        5      (       d  M  X#R                  U5      -  nM/     U$ )NF)r{   clearrz   rg   r   ra   )r   r`   statrj   s       r   ra   CompoundDB.update_cache   sJ    ))B"i((.. 
 r   c                    [        5       n[        X5        [        U5      n[        U5      nUS-  S:w  a  [	        US-   5      nO[	        U5      nSnU H]  nSn [        US5      (       a  UR                  U5      nOUR                  XC5      n U(       d  MD  U(       a  XW:w  a  [        U5      eUnM_     U(       d  [        U5      eU$ ! [         a     M  f = f)z
:return: 20 byte binary sha1 from the given less-than-40 byte hexsha (bytes or str)
:param partial_hexsha: hexsha with less than 40 byte
:raise AmbiguousObjectName:    r   0Npartial_to_complete_sha_hex)
r|   rq   r   lenr   hasattrr   partial_to_complete_shar   r   )r   partial_hexsharo   len_partial_hexshapartial_binsha	candidaterj   full_bin_shas           r   r   &CompoundDB.partial_to_complete_sha_hex   s    
 F	T-#N3 0!Q&'(<=N'7N 	BL2<==#%#A#A.#QL#%#=#=n#aL
 |!:-n==(	 " N++  s   "C<C
CC)r{   rz   rc   )r2   r3   r4   r5   r6   r~   r   r    r#   r'   r+   r/   ro   ra   r   r7   r[   r\   s   @r   r   r      s@    ;
&(-/N; 	# #r   r   N)r6   
gitdb.utilr   r   r   gitdb.utils.encodingr   	gitdb.excr   r   	itertoolsr	   	functoolsr
   __all__r   r   r   r   rq   r   r1   r   r   <module>r      ss   
 ?  ,
   N$$ $$R%C %CT< <8O O"	 nIy nr   