o saG@sddlZddlZddlmZddlZddlmZmZdZdZ ddZ dd Z Gd d d e Z d d ZddZGdddeZGdddeZdS)N)closing)CustomArgument CLIArgumentzk--zip-file must be a zip file with the fileb:// prefix. Example usage: --zip-file fileb://path/to/file.zipz

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

cCs@|dtdj|dtdj|dt|dtdS)Nz.building-argument-table.lambda.create-functionCodez4building-argument-table.lambda.publish-layer-versionContentz3building-argument-table.lambda.update-function-codez+process-cli-arg.lambda.update-function-code)registerZipFileArgumentHoisterhoist_modify_zipfile_docstringvalidate_is_zip_file)clir A/usr/lib/python3/dist-packages/awscli/customizations/awslambda.pyregister_lambda_create_function!srcKs|jdkr t|dSdSNzip-file)name_should_contain_zip_content) cli_argumentvaluekwargsr r rr ,s  r c@s eZdZdZddZddZdS)rarHoists 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. cCs||_||_dS)N)_serialized_namelower_name)selfserialized_namer r r__init__:szZipFileArgumentHoister.__init__cKsltj|jd}td|d|jd|d<||j}t|j}|jd=t |j||j d| d|jd||j<dS) N) param_typerblob) help_text cli_type_namerZipFileF event_emitter)rargument_modeloperation_model is_requiredr"r) ZIP_DOCSTRINGformatrZipFileArgumentrcopydeepcopyr#membersReplacedZipFileArgument_operation_model get_component)rsessionargument_tablerrargumentmodelr r rr >s   zZipFileArgumentHoister.hoistN)__name__ __module__ __qualname____doc__rr r r r rr1s rcKsd|vr t|d_dSdSr)r& documentation)r/r0rr r rr Qsr cCsxt|ts |d}t|}z tt|}|WdWdS1s(wYWdStj y;t t w)Nzutf-8) isinstancebytesencodesixBytesIOrzipfiler!infolist BadZipfile ValueError ERROR_MSG)rfileobjfr r rrVs    &rc(eZdZdZfddZddZZS)r(aA 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': } }. cs&|d|_tt|j|i|dS)Nr)pop_param_to_replacesuperr(rrargsr __class__r rrns zZipFileArgument.__init__cCsJ|durdSt|d|i}||jr||j|dS|||j<dS)Nr!)rgetrFupdate)r parametersrzip_file_paramr r r add_to_paramsrs zZipFileArgument.add_to_paramsr3r4r5r6rrP __classcell__r r rJrr(es r(crD)r,aA 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. cs2tt|j|i|d|d|_|d|_dS)Nz--%srr)rGr,r _cli_namerFrHrJr rrsz ReplacedZipFileArgument.__init__cCsZ|durdS||}d|vrtd|j||jr&||j|dS|||j<dS)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@rSrLrFrM)rrNrunpackedr r rrPs  z%ReplacedZipFileArgument.add_to_paramsrQr r rJrr,}s r,)r=r) contextlibrr;awscli.argumentsrrrAr&rr objectrr rr(r,r r r rs