
    )                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r
  SSKJr  SS	KJr  SSKJr   " S
 S\5      rSrSrS r " S S\R(                  5      r " S S\R(                  5      rg)z9This package provides compatibility interfaces for v1/v2.    )absolute_import)division)print_functionN)docker_image)util)docker_digest)docker_httpc                       \ rS rSrSrSrg)BadDigestException   z)Exceptions when a bad digest is supplied. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       ;lib/third_party/containerregistry/client/v2_2/v2_compat_.pyr   r      s    1r   r   zGsha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4s      	n b`X   .   c                 l   0 n/ nU  H^  nUn0 nSU;   a2  UR                  S5      nUR                  S5      (       a  US   S   US'   SU;   a  UR                  S5      US'   X5/-  nM`     UUSS.S.nS	 H  nX;   d  M
  X(   Xx'   M     SU;   a  UR                  S5      US'   [        R                  " US
S9$ )z<Compute the v2.2 config file given the history and diff ids.container_configCmdr   
created_bycreatedlayers)diff_idstype)historyrootfs)architectureconfig	containerr   docker_versionosT	sort_keys)getjsondumps)	
v1_compatsr   v1_compatibility	histories	v1_compatr   r   r!   keys	            r   config_filer/   .   s    
 )i  G--)--.@A			e	$	$ 0 7 :$$+//	:giI " &c $)fk ""(,,Y7F9	Fd	++r   c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)	V22FromV2Z   GThis compatibility interface serves the v2 interface from a v2_2 image.c                 0    Xl         U R                  5         g)zConstructor.

Args:
  v2_img: a v2 DockerImage on which __enter__ has already been called.

Raises:
  ValueError: an incorrectly typed argument was supplied.
N)	_v2_image_ProcessImage)selfv2_imgs     r   __init__V22FromV2.__init__]   s     Nr   c                 r   U R                   R                  5       n[        R                  " U5      n[	        [        UR                  S/ 5      5       Vs/ s H)  n[        R                  " UR                  SS5      5      PM+     sn[        U R                   R                  5       5       Vs/ s H  nU R                  U5      PM     sn5      U l	        U R                  R                  S5      n[        R                  [        U5      [        R                  " U5      S.nS[        R                   U[        U R                   R                  5       5       Vs/ s H0  n[        R"                  U R                   R%                  U5      US.PM2     snS.n[        R&                  " USS	9U l        g
s  snf s  snf s  snf )z4Constructs schema 2 manifest from schema 1 manifest.r   v1Compatibilityz{}utf8)	mediaTypesizedigest   )schemaVersionr>   r!   r   Tr%   N)r5   manifestr(   loadsr/   reversedr'   	fs_layers
_GetDiffId_config_fileencoder	   CONFIG_JSON_MIMElenr   SHA256MANIFEST_SCHEMA2_MIME
LAYER_MIME	blob_sizer)   	_manifest)r7   raw_manifest_schema1manifest_schema1r   r@   config_bytesconfig_descriptormanifest_schema2s           r   r6   V22FromV2._ProcessImagei   s|   >>224zz"67# 0 4 4Y CD%DG 	

7;;0$78D%
 t~~779::F 	:D $$++F3L 11L!&&|4  66# #4>>#;#;#=>
 ?	 )33008 
 ?
	 ZZ 0DADN9% 
s   0F**F/
7F4
c                 `    [         R                  " U R                  R                  U5      5      $ )z!Hash the uncompressed layer blob.)r   rL   r5   uncompressed_blobr7   r@   s     r   rG   V22FromV2._GetDiffId   s"     @ @ HIIr   c                     U R                   $ z	Override.rP   r7   s    r   rC   V22FromV2.manifest       >>r   c                     U R                   $ r\   )rH   r^   s    r   r/   V22FromV2.config_file   s    r   c                 8    U R                   R                  U5      $ r\   )r5   rX   rY   s     r   rX   V22FromV2.uncompressed_blob   s    >>++F33r   c                 8    U R                   R                  U5      $ r\   )r5   blobrY   s     r   rf   V22FromV2.blob   s    >>v&&r   c                     U $ Nr   r^   s    r   	__enter__V22FromV2.__enter__       Kr   c                     g ri   r   r7   unused_typeunused_valueunused_tracebacks       r   __exit__V22FromV2.__exit__       r   )rH   rP   r5   N)r   r   r   r   r   r9   r6   rG   rC   r/   rX   rf   rj   rr   r   r   r   r   r1   r1   Z   s5    O
!BFJ4'
	r   r1   c                   t   ^  \ rS rSrSrS rS r SS jrS rS r	S r
S	 rU 4S
 jrS rS rS rS rSrU =r$ )	V2FromV22   r3   c                 0    Xl         U R                  5         g)zConstructor.

Args:
  v2_2_img: a v2_2 DockerImage on which __enter__ has already been called.

Raises:
  ValueError: an incorrectly typed argument was supplied.
N)_v2_2_imager6   )r7   v2_2_imgs     r   r9   V2FromV22.__init__   s      r   c                    [         R                  " U R                  R                  5       5      nU R                  R	                  5       n[         R                  " U5      nSnUR                  S0 5      n[        U5      nSnUR                  S0 5      n/ n	/ n
[        U5       H|  u  pU R                  XX5      u  pnXS-
  :w  a$  U R                  X5      nU R                  XU5      nO$U R                  XU5      nU R                  XX5      nUnXS./U	-   n	SU0/U
-   n
M~     SSSU	U
S	.nS
U;   a  US
   US
'   [        R                  " [         R                  " USS95      U l        g)zDConstructs schema 1 manifest from schema 2 manifest and config file. r   r   r      )blobSumr>   r<   unused)rB   nametagfsLayersr   r    Tr%   N)r(   rD   ry   rC   r/   r'   rK   	enumerate_GetSchema1LayerDigest_GenerateV1LayerId_BuildV1Compatibility _BuildV1CompatibilityForTopLayerv2_utilSignr)   rP   )r7   rU   
raw_configr!   parentr,   layer_countv2_layer_indexr   rF   v1_historiesv1_layer_indexr   r@   
media_typelayer_idr+   rR   s                     r   r6   V2FromV22._ProcessImage   s}   zz$"2"2";";"=>!!--/JZZ
#FF

9b)Ii.KN!!(B/F IL#,Y#7+/+F+F
>,;(f. 
?	***6:55hP**6:F@@g/f%?@9Li(*:;<|Kl $8   )/)?~&\\$**-="NODNr   c                     UR                  SS5      n[        U5      S:w  a  [        SU-  5      eUS   S-   U-   nU(       a  USU-   -  n[        R                  " UR                  S5      S5      $ )N:r~   rA   z=Invalid Digest: %s, must be in algorithm : blobSumHex format. r=   r}   )rsplitrK   r   r   rL   rI   )r7   r@   r   r   partsdatas         r   r   V2FromV22._GenerateV1LayerId   s     MM#q!E
5zQ  @CI K L L 8c>F"D
cJdF 3R88r   c                     SU0nU(       a  X$S'   SU;   a  SUS'   SU;   a  SUS   /0US'   S	 H  nXS;   d  M
  X5   XE'   M     [         R                  " USS
9$ )Nidr   empty_layerT	throwawayr   r   r   )r   commentauthorr%   r(   r)   )r7   r   r   r   r+   r.   s         r   r   V2FromV22._BuildV1Compatibility   sz    h'#)x &*{#w.3gl6K5L-M)*/	 ' 0 ::&$77r   c                     SU0nU(       a  X%S'   SU;   a  SUS'   S H  nXd;   d  M
  XF   XV'   M     [         R                  " USS9$ )Nr   r   r   Tr   )r    r"   r#   r$   r!   r   r   r%   r   )r7   r   r   r   r!   r+   r.   s          r   r   *V2FromV22._BuildV1CompatibilityForTopLayer  s_     h'#)x &*{# 
 & ::&$77r   c                 `    SU;   a  [         [        R                  U4$ X$   S   X$   S   US-   4$ )Nr   r@   r>   r~   )EMPTY_TAR_DIGESTr	   rN   )r7   r   r   r   r   s        r   r    V2FromV22._GetSchema1LayerDigest  sI      6 6GG 
 
*

 
-
1
 r   c                     U R                   $ r\   r]   r^   s    r   rC   V2FromV22.manifest#  r`   r   c                 |   > U[         :X  a  [        [        U ]  [         5      $ U R                  R                  U5      $ r\   )r   superrv   rX   ry   )r7   r@   	__class__s     r   rX   V2FromV22.uncompressed_blob'  s6    !!9d56FGG--f55r   c                 8    U R                   R                  U5      $ )zGets v22 diff_id.)ry   digest_to_diff_idrY   s     r   diff_idV2FromV22.diff_id.  s    --f55r   c                 X    U[         :X  a  [        $ U R                  R                  U5      $ r\   )r   EMPTY_TAR_BYTESry   rf   rY   s     r   rf   V2FromV22.blob2  s*    !!
   ((r   c                     U $ ri   r   r^   s    r   rj   V2FromV22.__enter__=  rl   r   c                     g ri   r   rn   s       r   rr   V2FromV22.__exit__@  rt   r   )rP   ry   ri   )r   r   r   r   r   r9   r6   r   r   r   r   rC   rX   r   rf   rj   rr   r   __classcell__)r   s   @r   rv   rv      sN    O
(PZ '+98&8(
66)	 	r   rv   )r   
__future__r   r   r   r(   containerregistry.client.v2r   v2_imager   r   containerregistry.client.v2_2r   r	   
v2_2_image	Exceptionr   r   r   r/   DockerImager1   rv   r   r   r   <module>r      sr    @ &  %  @ 7 7 5 D2 2 ]  E),XK	
&& K	\Y	$$ Y	r   