
    .Ph                         d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
 g dZ G d de          Z G d d          Z G d	 d
          Zdee         dee	eeef                  fdZdS )zGProvides an object-oriented model for handling :pep:`376` RECORD files.    N)IterableIteratorOptionalTuplecast)HashRecordEntryInvalidRecordEntryparse_record_filec                   (     e Zd ZdZ fdZd Z xZS )r
   zPRaised when a RecordEntry is not valid, due to improper element values or count.c                     t                                          d                    |                     || _        || _        d S )Nz, )super__init__joinissueselements)selfr   r   	__class__s      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/installer/records.pyr   zInvalidRecordEntry.__init__   s9    6**+++     c                 B    d                     | j        | j                  S )Nz.InvalidRecordEntry(elements={!r}, issues={!r}))formatr   r   r   s    r   __repr__zInvalidRecordEntry.__repr__   s#    ?FFM4;
 
 	
r   )__name__
__module____qualname____doc__r   r   __classcell__r   s   @r   r
   r
      sM        ZZ! ! ! ! !

 
 
 
 
 
 
r   r
   c                   t    e Zd ZdZdededdfdZdefdZdefdZd	 Zd
e	de
fdZededd fd            ZdS )r   z/Represents the "hash" element of a RecordEntry.namevaluereturnNc                 "    || _         || _        dS )a  Construct a ``Hash`` object.

        Most consumers should use :py:meth:`Hash.parse` instead, since no
        validation or parsing is performed by this constructor.

        :param name: name of the hash function
        :param value: hashed value
        Nr"   r#   )r   r"   r#   s      r   r   zHash.__init__"   s     	


r   c                 $    | j          d| j         S )N=r&   r   s    r   __str__zHash.__str__.   s    )**dj***r   c                 (    d| j         d| j        dS )Nz
Hash(name=z, value=)r&   r   s    r   r   zHash.__repr__1   s    @DI@@@@@@r   c                 z    t          |t                    st          S | j        |j        k    o| j        |j        k    S N)
isinstancer   NotImplementedr#   r"   r   others     r   __eq__zHash.__eq__4   s7    %&& 	"!!zU[(DTY%*-DDr   datac                     t          j        | j        |                                          }t	          j        |                              d                              d          }| j        |k    S )zValidate that ``data`` matches this instance.

        :param data: Contents of the file.
        :return: Whether ``data`` matches the hashed value.
        asciir(   )	hashlibnewr"   digestbase64urlsafe_b64encodedecoderstripr#   )r   r3   r8   r#   s       r   validatezHash.validate9   s\     TY--4466(0077@@GGLLzU""r   hc                 L    |                     dd          \  }} | ||          S )a<  Build a Hash object, from a "name=value" string.

        This accepts a string of the format for the second element in a record,
        as described in :pep:`376`.

        Typical usage::

            Hash.parse("sha256=Y0sCextp4SQtQNU-MSs7SsdxD1W-gfKJtUlEbvZ3i-4")

        :param h: a name=value string
        r(      )split)clsr>   r"   r#   s       r   parsez
Hash.parseC   s+     ggc1ooes4r   )r   r   r   r   strr   r)   r   r2   bytesboolr=   classmethodrC    r   r   r   r      s        99
S 
 
 
 
 
 
+ + + + +A# A A A AE E E
#U #t # # # #  c  f       [     r   r   c            	            e Zd ZdZdedee         dee         ddf fdZddee         de	eeef         fd	Z
defd
Zd ZdedefdZededededd fd            Z xZS )r	   zRepresents a single record in a RECORD file.

    A list of :py:class:`RecordEntry` objects fully represents a RECORD file.
    pathhash_sizer$   Nc                 r    t                                                       || _        || _        || _        dS )a=  Construct a ``RecordEntry`` object.

        Most consumers should use :py:meth:`RecordEntry.from_elements`, since no
        validation or parsing is performed by this constructor.

        :param path: file's path
        :param hash\_: hash of the file's contents
        :param size: file's size in bytes
        N)r   r   rJ   rK   rL   )r   rJ   rK   rL   r   s       r   r   zRecordEntry.__init__Z   s4     		
			r   path_prefixc                    |"|                     d          sJ || j        z   }n| j        }t          j        dk    r|                    dd          }|t          | j        pd          | j        t          | j                  ndfS )zConvert this into a 3-element tuple that can be written in a RECORD file.

        :param path_prefix: A prefix to attach to the path -- must end in `/`
        :return: a (path, hash, size) row
        N/\ )endswithrJ   ossepreplacerD   rK   rL   )r   rN   rJ   s      r   to_rowzRecordEntry.to_rowj   s     "'',,,,,*DD9D 6T>><<c**D 
 b!!"i3C	NNN
 	
r   c                 N    d                     | j        | j        | j                  S )Nz-RecordEntry(path={!r}, hash_={!r}, size={!r}))r   rJ   rK   rL   r   s    r   r   zRecordEntry.__repr__   s'    >EEItz49
 
 	
r   c                     t          |t                    st          S | j        |j        k    o| j        |j        k    o| j        |j        k    S r-   )r.   r	   r/   rJ   rK   rL   r0   s     r   r2   zRecordEntry.__eq__   sM    %-- 	"!!I# (
ek)(	UZ'	
r   r3   c                     | j         t          |          | j         k    rdS | j        r| j                            |          S dS )zValidate that ``data`` matches this instance.

        :param data: Contents of the file corresponding to this instance.
        :return: whether ``data`` matches hash and size.
        NFT)rL   lenrK   r=   )r   r3   s     r   r=   zRecordEntry.validate   sH     9 SYY$)%;%;5: 	-:&&t,,,tr   c                 z   g }|s|                     d           |rA	 t                              |          }n'# t          $ r |                     d           Y nw xY wd}|r6	 t	          |          }n'# t          $ r |                     d           Y nw xY wd}|rt          |||f|           | |||          S )a  Build a RecordEntry object, from values of the elements.

        Typical usage::

            for row in parse_record_file(f):
                record = RecordEntry.from_elements(row[0], row[1], row[2])

        Meaning of each element is specified in :pep:`376`.

        :param path: first element (file's path)
        :param hash\_: second element (hash of the file's contents)
        :param size: third element (file's size in bytes)
        :raises InvalidRecordEntry: if any element is invalid
        z`path` cannot be emptyz*`hash` does not follow the required formatNz`size` cannot be non-integerr   r   )rJ   rK   rL   )appendr   rC   
ValueErrorintr
   )rB   rJ   rK   rL   r   
hash_value
size_values          r   from_elementszRecordEntry.from_elements   s   "  	4MM2333 	L-1ZZ->->

 L L LJKKKKKL J 	>,/II

 > > ><=====> J 	R$tUD.A&QQQQsJZ@@@@s!   8 AA"A2 2BBr-   )r   r   r   r   rD   r   r   r`   r   r   rW   r   r2   rE   rF   r=   rG   rc   r   r    s   @r   r	   r	   T   s6        
S $ x} QU       
 
(3- 
5c3;O 
 
 
 
,
# 
 
 
 


 
 
U t     (A (AS (A (A (A (A (A [(A (A (A (A (Ar   r	   rowsr$   c              #     K   t          j        | ddd          }t          |          D ]\  }}t          |          dk    r5d                    |t          |                    }t          ||g          |d                             d	d
          |d<   t          t          t          t          t          f         t          |                    }|V  dS )zParse a :pep:`376` RECORD.

    Returns an iterable of 3-value tuples, that can be passed to
    :any:`RecordEntry.from_elements`.

    :param rows: iterator providing lines of a RECORD (no trailing newlines).
    ,"
)	delimiter	quotecharlineterminator   z)Row Index {}: expected 3 elements, got {}r]   r   rQ   rP   N)csvreader	enumerater[   r   r
   rV   r   r   rD   tuple)rd   rn   	row_indexr   messager#   s         r   r   r      s       Zs4PPPF(00  	8x==AAHH3x== G %hyIIII qk))$44U3S=)5??;; r   )r   r9   rm   r6   rT   typingr   r   r   r   r   __all__	Exceptionr
   r   r	   rD   r   rH   r   r   <module>rv      s6   M M  



  				 < < < < < < < < < < < < < <  
 
 
 
 
 
 
 
2  2  2  2  2  2  2  2 jqA qA qA qA qA qA qA qAhHSM huS#s]7K.L      r   