
    S`E'                     B   d dl Z d dlZd dlmZ ddlmZ d dlmZ d dl	m
Z
 d dl	mZ  e j                  e      Z G d d	      Zd
 Zd Zd Zd Z G d de      Z G d de      Z G d de      ZdZdZd Zd Zd Zd Zd Zd Zd Z d Z!d Z" G d d       Z# e#       Z$y)!    N)Template   )ConfigurationError)COMPOSEFILE_V1)parse_bytes)parse_nanoseconds_intc                       e Zd Zd Zd Zy)Interpolatorc                      || _         || _        y N)	templatermapping)selfr   r   s      >/usr/lib/python3/dist-packages/compose/config/interpolation.py__init__zInterpolator.__init__   s    "    c                     	 | j                  |      j                  | j                        S # t        $ r t	        |      w xY wr   )r   
substituter   
ValueErrorInvalidInterpolationr   strings     r   interpolatezInterpolator.interpolate   s?    	/>>&)44T\\BB 	/&v..	/s	   ), AN)__name__
__module____qualname__r   r    r   r   r
   r
      s    /r   r
   c           
          | t         k(  rt        t        |      nt        t        |      fd}|j	                         D ci c]  \  }}| |||xs i        c}}S c c}}w )Nc                 z    |xs i j                         D ci c]  \  }}|t        | ||       c}}S c c}}w r   )itemsinterpolate_value)nameconfig_dictkeyvalinterpolatorsections       r   process_itemz7interpolate_environment_variables.<locals>.process_item!   sJ     ).B557
S "4c7LII
 	
 
s   7)V1r
   r   TemplateWithDefaultsr    )versionconfigr'   environmentr(   r"   r#   r&   s     `    @r   !interpolate_environment_variablesr.      se    "}#Hk:#$8+F
 "(D+ 	l4!233  s   A"c                 (    dj                  |||       S )Nz{}/{}/{}format)
config_keyr'   r"   s      r   get_config_pathr3   -   s    WdJ77r   c           
         	 t        ||t        |||             S # t        $ r-}t        dj	                  || ||j
                              d }~wt        $ r.}t        dj	                  ||| ||j                              d }~ww xY w)NzXInvalid interpolation format for "{config_key}" option in {section} "{name}": "{string}")r2   r"   r'   r   zdMissing mandatory value for "{config_key}" option interpolating {value} in {section} "{name}": {err})r2   valuer"   r'   err)recursive_interpolater3   r   r   r1   r   UnsetRequiredSubstitutionr6   )r"   r2   r5   r'   r&   es         r   r!   r!   1   s    
$UL/*V]_c:dee " 006%xx	 17 1!" 	" % 
 ++16Z8=7;:A67ee	 ,2 ,=
 	

s     	B(AB)B  Bc                    d }t        | t              r%t        j                  ||j	                  |             S t        | t
              r6| j                         D ci c]  \  }}|t        || |||             c}}S t        | t              r| D cg c]  }t        |||       c}S t        j                  ||       S c c}}w c c}w )Nc                 &    dj                  | |      S )Nz{}/{}r0   )config_pathr$   s     r   appendz%recursive_interpolate.<locals>.appendH   s    ~~k3//r   )	
isinstancestr	converterconvertr   dictr    r7   list)objr&   r<   r=   r$   r%   s         r   r7   r7   G   s    0 #s  l.F.Fs.KLL#t  IIK
S &sL&c:RSS
 	
 #tQTU#%c<EUU[#..

 Vs   C Cc                   j    e Zd Zdj                   ej
                  d      dd      Zed        Zd Z	y)	r*   z
        {delim}(?:
            (?P<escaped>{delim}) |
            (?P<named>{id})      |
            {{(?P<braced>{bid})}}  |
            (?P<invalid>)
        )
        $z[_a-z][_a-z0-9]*z)[_a-z][_a-z0-9]*(?:(?P<sep>:?[-?])[^}]*)?)delimidbidc                    d|k(  r*| j                  d      \  }}}|j                  |      xs |S d|k(  r'| j                  d      \  }}}|j                  ||      S d|k(  r;| j                  d      \  }}}|j                  |      }|s|xs |}t        |      |S d|k(  r;| j                  d      \  }}}||v r|j                  |      S |xs |}t        |      y )Nz:--z:??)	partitiongetr8   )bracedsepr   var_defaultr6   results           r   process_braced_groupz)TemplateWithDefaults.process_braced_groupe   s    3;$..t4OCG;;s#.w.CZ$..s3OCG;;sG,,S[ **40KCC[[%FjS/44MCZ **3/KCCg~{{3''*C+C00 r   c                 ^      fd} j                   j                  | j                        S )Nc                    | j                  d      xs | j                  d      }| j                  d      }|&| j                  d      }|rj                  ||      S |7|   }t        |t              r|j	                  d      }dj                  |      S | j                  d      j                  S | j                  d      j                  |        t        dj                        )	NnamedrO   rP   zutf-8{}escapedinvalidz#Unrecognized named group in pattern)
grouprU   r>   bytesdecoder1   	delimiter_invalidr   pattern)morX   rO   rP   r%   r   r   s        r   rA   z0TemplateWithDefaults.substitute.<locals>.convert   s    HHW%;();EXXh'F!hhuo44VS'JJ enc5)**W-C{{3''xx	".~~%xx	".b!B!\\+ +r   )ra   subtemplate)r   r   rA   s   `` r   r   zTemplateWithDefaults.substitute}   s%    	+& ||77r   N)
r   r   r   r1   reescapera   staticmethodrU   r   r   r   r   r*   r*   W   sI     Fbiin8    1 1.8r   r*   c                       e Zd Zd Zy)r   c                     || _         y r   )r   r   s     r   r   zInvalidInterpolation.__init__   s	    r   Nr   r   r   r   r   r   r   r   r      s    r   r   c                       e Zd Zd Zy)r8   c                     || _         y r   )r6   )r   custom_err_msgs     r   r   z"UnsetRequiredSubstitution.__init__   s	    !r   Nrj   r   r   r   r8   r8      s    "r   r8   z[^/]+z.+c                  h    t        j                  dj                  dj                  |                   S )Nz^{}$/)re   compiler1   joinargss    r   re_pathrt      s"    ::fmmCHHTN344r   c                 $    t        | t        |      S r   rt   
PATH_JOKER)r'   r"   s     r   re_path_basicrx      s    7J--r   c                  $    t        dt        g|  S )Nservicerv   rr   s    r   service_pathr{      s    9j0400r   c                     t        | t              s| S | j                         } | dv ry| dv ryt        dj	                  |             )N)yyestrueonT)nnofalseoffFz!"{}" is not a valid boolean value)r>   r?   lowerr   r1   ss    r   
to_booleanr      sK    a		A&&	
)	)
8??B
CCr   c                     t        | t              s| S t        j                  d| j	                               rd| dd  z   } 	 t        | d      S # t        $ r t        dj                  |             w xY w)Nz	^0[0-9]+$0or   r   )basez"{}" is not a valid integer)r>   r?   re   matchstripintr   r1   r   s    r   to_intr      sp    a 
xxQWWY'1QR5LB11~ B6==a@AABs    A $A1c                     t        | t              s| S 	 t        |       S # t        $ r t        dj	                  |             w xY w)Nz"{}" is not a valid float)r>   r?   floatr   r1   r   s    r   to_floatr      sH    a@Qx @4;;A>??@s	   
 $Ac                 ^    t        | t        t        t        f      rdj	                  |       S | S )NrY   )r>   boolr   r   r1   )os    r   to_strr      s&    !dE3'({{1~Hr   c                 T    t        |       }|t        dj                  |             |S )Nz"{}" is not a valid byte value)r   r   r1   )r   vs     r   bytes_to_intr      s,    AAy9@@CDDHr   c                 T    t        | t              s| S t        t        |       dz        S )Ni  )r>   r?   r   r   )r   s    r   to_microsecondsr      s'    a$Q'$.//r   c            #          e Zd Zi  edd      e eddd      e edde      e ed      e ed      e ed      e ed	      e ed
      e ed      e edd      e edd      e edd      e edd      e	 edde
      e edd      e eddd      e edddd      ei  eddd      e eddd      e eddd      e eddd      e eddd      e ed      e ede      e ed      e	 ed       e ed!d"      e ed!d#      e ed$      e ed%e
      e ed%e
d&      e ed%e
d'      e ed(      e	 ed)      e	 ed*      e	 ed+      e	 ed,d)      e	 ed,d-d.      e	 ed,d/d0      e ed1d2      e	 ed1d3      e	 ed1d4      e	 ed1e
de      e ed-d3      e	 ed-e
de      e ed5d3      e	 ed5e
de      e ed6d3      e	 ed6e
de      eiZd7 Zy8)9ConversionMapblkio_configweightweight_devicebuildlabelscpus	cpu_count	cpu_quota
cpu_periodcpu_rt_periodcpu_rt_runtimeconfigsmodesecretshealthcheckretriesdisabledeployreplicas	placementmax_replicas_per_node	resourceslimitsupdate_configparallelismmax_failure_ratiorollback_configrestart_policymax_attemptsmem_swappinessoom_kill_disableoom_score_adjportstarget	publishedscaleulimitssofthard
privileged	read_only
stdin_openttyvolumesvolumenocopytmpfssizenetwork
attachableexternalinternalsecretr,   c           
         | j                   j                         D ]+  }|j                  |      s	  | j                   |   |      c S  |S # t        $ r0}t	        dj                  |j                  dd      |            d }~ww xY w)Nz<Error while attempting to convert {} to appropriate type: {}ro   .)mapkeysr   r   r   r1   replace)r   pathr5   rexpr9   s        r   rA   zConversionMap.convert  s    HHMMO 		Dzz$)488D>%00		  " ,V]] LLc2A s   A	B+A??BN)r   r   r   r{   r   
FULL_JOKERr   r   r   r   rw   r   rx   rt   r   rA   r   r   r   r   r      so   2^X.2^_h?2 	Wh
3V2 	Vh	2
 	[!62 	[!?2 	\"O2 	_%2 	%&2 	Y'2 	Y'2 	]I.2 	]I.
2 	Xx4f2 	Xz*F2  	X{,CDf!2" 	X{Hf=x#2$ 	X>%2& 	X0CDh'2( 	X0-@&)2* 	X02EF+2, 	X/@&-2. 	%&/20 	Xz*F122 	'(*324 	_%v526 	Wh'728 	Wk*F92: 	Wv;2< 	Y
+V=2> 	Y
F3V?2@ 	Y
F3VA2B 	\"JC2D 	[!:E2F 	\"JUZY,jY(3ZY0,i.
i,ji,j	:x<fh
+Z*h
;Vh
+Z*h
;Vh
+Z*h
;Vc2Chr   r   )%loggingre   r   r   errorsr   compose.constr   r)   compose.utilsr   r   	getLoggerr   logr
   r.   r3   r!   r7   r*   	Exceptionr   r8   rw   r   rt   rx   r{   r   r   r   r   r   r   r   r@   r   r   r   <module>r      s     	  & . % / g!
/ 
/$8
,/ <88 <8~9 
"	 "
 

5.1D
B@0@ @F O	r   