o
    øsßaG  ã                   @   s�   d dl Z d dlZd dlmZ d dlZd dlmZmZ dZdZ	dd„ Z
dd	„ ZG d
d„ deƒZdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZdS )é    N)Úclosing)ÚCustomArgumentÚCLIArgumentzk--zip-file must be a zip file with the fileb:// prefix.
Example usage:  --zip-file fileb://path/to/file.zipzœ<p>The path to the zip file of the {param_type} you are uploading. Specify --zip-file or --{param_type}, but not both. Example: fileb://{param_type}.zip</p>c                 C   s@   |   dtdƒj¡ |   dtdƒj¡ |   dt¡ |   dt¡ d S )Nz.building-argument-table.lambda.create-functionÚCodez4building-argument-table.lambda.publish-layer-versionÚContentz3building-argument-table.lambda.update-function-codez+process-cli-arg.lambda.update-function-code)ÚregisterÚZipFileArgumentHoisterÚhoistÚ_modify_zipfile_docstringÚvalidate_is_zip_file)Úcli© r   úA/usr/lib/python3/dist-packages/awscli/customizations/awslambda.pyÚregister_lambda_create_function!   s   ÿÿÿÿr   c                 K   s   | j dkrt|ƒ d S d S ©Núzip-file)ÚnameÚ_should_contain_zip_content)Úcli_argumentÚvalueÚkwargsr   r   r   r   ,   s   
ÿr   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   ar  Hoists a ZipFile argument up to the top level.

    Injects a top-level ZipFileArgument into the argument table which maps
    a --zip-file parameter to the underlying ``serialized_name`` ZipFile
    shape. Repalces the old ZipFile argument with an instance of
    ReplacedZipFileArgument to prevent its usage and recommend the new
    top-level injected parameter.
    c                 C   s   || _ | ¡ | _d S )N)Ú_serialized_nameÚlowerÚ_name)ÚselfÚserialized_namer   r   r   Ú__init__:   s   zZipFileArgumentHoister.__init__c                 K   sl   t j| jd�}td|d| jd�|d< || j }t |j¡}|jd= t	| j||j
d| d¡| jd�|| j< d S )	N)Ú
param_typer   Úblob)Ú	help_textÚcli_type_namer   ÚZipFileFÚevent_emitter)r   Úargument_modelÚoperation_modelÚis_requiredr"   r   )ÚZIP_DOCSTRINGÚformatr   ÚZipFileArgumentr   ÚcopyÚdeepcopyr#   ÚmembersÚReplacedZipFileArgumentÚ_operation_modelÚget_component)r   ÚsessionÚargument_tabler   r   ÚargumentÚmodelr   r   r   r	   >   s    
þ
úzZipFileArgumentHoister.hoistN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r   r   r   r   1   s    r   c                 K   s   d|v rt |d _d S d S r   )r&   Údocumentation)r/   r0   r   r   r   r   r
   Q   s   ÿr
   c                 C   sx   t | tƒs
|  d¡} t | ¡}z tt |¡ƒ�}| ¡  W d   ƒ W d S 1 s(w   Y  W d S  tj	y;   t
tƒ‚w )Nzutf-8)Ú
isinstanceÚbytesÚencodeÚsixÚBytesIOr   Úzipfiler!   ÚinfolistÚ
BadZipfileÚ
ValueErrorÚ	ERROR_MSG)r   ÚfileobjÚfr   r   r   r   V   s   



&ÿÿr   c                       ó(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r(   aƒ  A new ZipFile argument to be injected at the top level.

    This class injects a ZipFile argument under the specified serialized_name
    parameter. This can be used to take a top level parameter like --zip-file
    and inject it into a nested different parameter like Code so
    --zip-file foo.zip winds up being serilized as
    { 'Code': { 'ZipFile': <contents of foo.zip> } }.
    c                    s&   |  d¡| _tt| ƒj|i |¤Ž d S )Nr   )ÚpopÚ_param_to_replaceÚsuperr(   r   ©r   Úargsr   ©Ú	__class__r   r   r   n   s   zZipFileArgument.__init__c                 C   sJ   |d u rd S t |ƒ d|i}| | j¡r|| j  |¡ d S ||| j< d S )Nr!   )r   ÚgetrF   Úupdate)r   Ú
parametersr   Úzip_file_paramr   r   r   Úadd_to_paramsr   s   zZipFileArgument.add_to_params©r3   r4   r5   r6   r   rP   Ú__classcell__r   r   rJ   r   r(   e   s    r(   c                       rD   )r,   a„  A replacement arugment for nested ZipFile argument.

    This prevents the use of a non-working nested argument that expects binary.
    Instead an instance of ZipFileArgument should be injected at the top level
    and used instead. That way fileb:// can be used to load the binary
    contents. And the argument class can inject those bytes into the correct
    serialization name.
    c                    s2   t t| ƒj|i |¤Ž d|d  | _|d | _d S )Nz--%sr   r   )rG   r,   r   Ú	_cli_namerF   rH   rJ   r   r   r   †   s   z ReplacedZipFileArgument.__init__c                 C   sZ   |d u rd S |   |¡}d|v rtd| j ƒ‚| | j¡r&|| j  |¡ d S ||| j< d S )Nr!   zyZipFile cannot be provided as part of the %s argument.  Please use the '--zip-file' option instead to specify a zip file.)Ú_unpack_argumentr@   rS   rL   rF   rM   )r   rN   r   Úunpackedr   r   r   rP   ‹   s   
ýÿz%ReplacedZipFileArgument.add_to_paramsrQ   r   r   rJ   r   r,   }   s    r,   )r=   r)   Ú
contextlibr   r;   Úawscli.argumentsr   r   rA   r&   r   r   Úobjectr   r
   r   r(   r,   r   r   r   r   Ú<module>   s    ÿÿ 