o
    !d_                     @   s   d dl Z d dlZd dlmZ d dlm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)six)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-functionZCodez4building-argument-table.lambda.publish-layer-versionZ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   Cusr/lib/python3.10/site-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)Z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. Replaces 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)Z
param_typer   Zblob)	help_textZcli_type_namer   ZipFileFevent_emitter)r   argument_modelZoperation_modelZis_requiredr   r   )ZIP_DOCSTRINGformatr   ZipFileArgumentr   copydeepcopyr   membersReplacedZipFileArgumentZ_operation_modelZget_component)r   sessionargument_tabler   r   Z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&   r'   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encoder   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 serialized 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   getr;   update)r   
parametersr   Zzip_file_paramr   r   r   add_to_paramsr   s   zZipFileArgument.add_to_paramsr)   r*   r+   r,   r   rD   __classcell__r   r   r?   r   r!   e   s    r!   c                       r9   )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   )r<   r%   r   	_cli_namer;   r=   r?   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.)Z_unpack_argumentr5   rG   rA   r;   rB   )r   rC   r   Zunpackedr   r   r   rD      s   
z%ReplacedZipFileArgument.add_to_paramsrE   r   r   r?   r   r%   }   s    r%   )r2   r"   
contextlibr   Zbotocore.vendoredr   Zawscli.argumentsr   r   r6   r   r   r
   objectr   r	   r   r!   r%   r   r   r   r   <module>   s     