
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZ edg d      Z	 G d d	e	      Z
d
 Zd Zd Zd Z	 	 	 ddZy)z/This package manipulates Docker image metadata.    )absolute_import)print_function)
namedtupleN
OverridesT)nameparentsize
entrypointcmdenvlabelsportsvolumesworkdiruserc                   :     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 d fd	Z xZS )	Overridesz$Docker image layer metadata options.c                 B    t         t        |   | |||||||||	|
|      S )zConstructor.)r   r   r	   r
   r   r   r   r   r   r   r   )superr   __new__)clsr   r   r	   r
   r   r   r   r   r   r   r   	__class__s               ;lib/third_party/containerregistry/transform/v1/metadata_.pyr   zOverrides.__new__"   sB     C( )      )NNNNNNNNNNN)__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s3    ,  r   r   c                     t         j                  }	 |t         _        t         j                  j                  |       |t         _        S # |t         _        w xY w)z;Resolves environment variables embedded in the given value.)osenvironpath
expandvars)valueenvironment	outer_envs      r   _Resolver(   ?   s8    jj)BJ77e$BJBJs   )A Ac                     t        |       t        t                     k(  r%t        d t        j                  |       D              S t	        j
                  |       S )z$Do a deep copy, skipping null entry.c              3   R   K   | ]  \  }}|t        |      t        |      f ! y w)N)_DeepCopySkipNull).0kvs      r   	<genexpr>z$_DeepCopySkipNull.<locals>.<genexpr>M   s1      "/DAq= #1%'8';</s   %')typedictsix	iteritemscopydeepcopy)datas    r   r+   r+   J   sH    	$Z4< "MM$/" " " 
t	r   c                 \    t               }| D ]  }|j                  dd      \  }}|||<    |S )z=Converts an iterable object of key=value pairs to dictionary.=   )r1   split)pairdkvr-   r.   s        r   _KeyValueToDictr>   S   s7    
f!bXXc1FQAaD  
(r   c                 j    t        | j                               D cg c]  }|d| |    c}S c c}w )Nr8   )sortedkeys)r<   r-   s     r   _DictToKeyValuerB   \   s0    '-affh'7	8'7!Q!
'7	88	8s   0c                    t        |       }|j                  st        d      |j                  |d<   |j                  r|j                  |d<   n| rt        d| z        |j                  r|j                  |d<   nd|v r|d= d|vri |d<   |j
                  r|j
                  |d   d<   |j                  r|j                  |d   d<   |j                  r|j                  |d   d	<   ||d
<   ||d<   ||d<   |j                  ret        |d   j                  dg             }t        j                  |j                        D ]  \  }}t        ||      ||<    t        |      |d   d<   |j                  r[t        |d   j                  dg             }	t        j                  |j                        D ]
  \  }}||	|<    t        |	      |d   d<   |j                   r>d|d   vri |d   d<   |j                   D ]   }
d|
v ri |d   d   |
<   i |d   d   |
dz   <   " |j"                  r+d|d   vri |d   d<   |j"                  D ]  }
i |d   d   |
<    |j$                  r|j$                  |d   d<   d|v r|d= |S )a  Rewrite and return a copy of the input data according to options.

  Args:
    data: The dict of Docker image layer metadata we're copying and rewriting.
    options: The changes this layer makes to the overall image's metadata, which
             first appears in this layer's version of the metadata
    docker_version: The version of docker write in the metadata (default: 1.5.0)
    architecture: The architecture to write in the metadata (default: amd64)
    operating_system: The os to write in the metadata (default: linux)

  Returns:
    A deep copy of data, which has been updated to reflect the metadata
    additions of this layer.

  Raises:
    Exception: a required option was missing.
  zMissing required option: nameidr   z;Expected empty input object when parent is omitted, got: %sSizeconfig
EntrypointCmdUserdocker_versionarchitecturer!   EnvLabelExposedPorts/z/tcpVolumes
WorkingDircontainer_config)r+   r   	Exceptionr   r	   r
   r   r   r   r>   getr2   r3   r(   rB   r   r   r   r   )r6   optionsrJ   rK   operating_systemoutputenviron_dictr-   r.   
label_dictps              r   Overrider[   `   s   , T"&	
3
44&,^^~~F8
ELN N \\\\F6NvVF8%,%7%7F8\"[[%kkF8U\\&||F8V+&	'&!&,[["6(#3#7#7r#BCLgkk*1 L1l1o + .l;F8U^^ !1!5!5gr!BCJgnn-1jm . /
 ;F8W]]VH--)+fX~&]]	 /1x(+ 8:x(V4  __x(($&fXy!__')fXy!!$  __%,__F8\" 6!!"	-r   )z1.5.0amd64linux)r   
__future__r   r   collectionsr   r4   r!   r2   _OverridesTr   r(   r+   r>   rB   r[    r   r   <module>rb      sa    6 & % "  	 
  (  @9 &# '	hr   