
    .Ph                     x    d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
  G d d          Zdd
ZddZdS )z!Generates tarballs for Git trees.    N)closing)BytesIO)SEEK_ENDc                   "    e Zd ZdZddZddZdS )ChunkedBytesIOa=  Turn a list of bytestrings into a file-like object.

    This is similar to creating a `BytesIO` from a concatenation of the
    bytestring list, but saves memory by NOT creating one giant bytestring
    first::

        BytesIO(b''.join(list_of_bytestrings)) =~= ChunkedBytesIO(
            list_of_bytestrings)
    returnNc                 "    || _         d| _        d S )N)r   r   )contentspos)selfr
   s     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/archive.py__init__zChunkedBytesIO.__init__-   s         c                 4   |dk     rt          d          }g }| j        \  }}|t          | j                  k     r|t          | j        |                   |z
  k     r:|                    | j        |         |||z                       ||z  }||f| _        np|                    | j        |         |d                     |t          | j        |                   |z
  z  }|dz  }d}||f| _        |t          | j                  k     d                    |          S )Nr   inf   r   )floatr   lenr
   appendjoin)r   maxbytesbufchunkcursors        r   readzChunkedBytesIO.read1   s   a<<U||Hvc$-((((#dmE233f<<<

4=/(9J0JKLLL("!6?

4=/8999Ce 455>>
!6? c$-(((( xx}}r   )r   N)N)__name__
__module____qualname____doc__r   r    r   r   r   r   "   sF                 r   r   r    c              #     K   t                      }t          t          j        dd| |                    5 }|dk    r|                    d           |                    d          dk    s
J d            |                    d           |                    t          j        d	|                     |                    dt                     t          | ||          D ]\  }}	 | |j                 }	n# t          $ r Y  w xY wt          |	j                  }
t          j                    }|                    d
d          |_        |	                                |_        |j        |_        ||_        |                    ||
           |                                V  |                    d           |                    d           	 ddd           n# 1 swxY w Y   |                                V  dS )aE  Generate a tar stream for the contents of a Git tree.

    Returns a generator that lazily assembles a .tar.gz archive, yielding it in
    pieces (bytestrings). To obtain the complete .tar.gz binary file, simply
    concatenate these chunks.

    Args:
      store: Object store to retrieve objects from
      tree: Tree object for the tree root
      mtime: UNIX timestamp that is assigned as the modification time for
        all files, and the gzip header modification time if format='gz'
      format: Optional compression format for tarball
    Returns:
      Bytestrings
    Nzw:gzr      s   zInvalid gzip header   z<Lzutf-8surrogateescape)r   r   tarfileopenseekr   writestructpackr   
_walk_treeshaKeyErrorr   chunkedTarInfodecodename
raw_lengthsizemodemtimeaddfilegetvaluetruncate)storetreer7   prefixformatr   tarentry_abspathentryblobdatainfos               r   
tar_streamrE   G   s       ))C	dMMM377	8	8  CT>> HHQKKK88A;;+---/D---HHQKKKIIfk$..///HHQ!!!$.udF$C$C 	 	 M5UY'     "$,//D?$$D%,,W6GHHDI))DI
DIDJKKd###,,..   LLOOOHHQKKKK'	                             B ,,..s7   B-G%C32G3
D =G?D  CGGGc              #      K   |                                 D ]^}t          j        ||j                  }t	          j        |j                  r#t          | | |j                 |          E d{V  X||fV  _dS )zfRecursively walk a dulwich Tree, yielding tuples of
    (absolute path, TreeEntry) along the way.
    N)		iteritems	posixpathr   pathstatS_ISDIRr6   r-   r.   )r;   r<   rootrA   r@   s        r   r-   r-   |   s       !! ) )!tUZ88<
## 	)!%uy)9=IIIIIIIIII %((((() )r   )r   r!   )r   )r   rH   rJ   r+   r'   
contextlibr   ior   osr   r   rE   r-   r    r   r   <module>rP      s   . ( '                         " " " " " " " "J2 2 2 2j	) 	) 	) 	) 	) 	)r   