a 97a1@sdZddlmZddlZddlZddlmZddlmZddlmZddl m Z dd Z d d Z d d Z GdddeZGdddeZGdddeZdS)aQUser input parameter validation. This module handles user input parameter validation against a provided input model. Note that the objects in this module do *not* mutate any arguments. No type version happens here. It is up to another layer to properly convert arguments to any required types. Validation Errors ----------------- )sixN)datetime)parse_to_aware_datetime)is_json_value_header)ParamValidationErrorcCs,t}|||}|r(t|ddS)avValidates input parameters against a schema. This is a convenience function that validates parameters against a schema. You can also instantiate and use the ParamValidator class directly if you want more control. If there are any validation errors then a ParamValidationError will be raised. If there are no validation errors than no exception is raised and a value of None is returned. :param params: The user provided input parameters. :type shape: botocore.model.Shape :param shape: The schema which the input parameters should adhere to. :raise: ParamValidationError reportN)ParamValidatorvalidate has_errorsrgenerate_report)paramsshapeZ validatorrrl/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/botocore/validate.pyvalidate_parameterss rcsfdd}|S)Ncsfdd}fdd|S)Ncs |||r|||||SdSNrselfparamrerrorsname _type_checkfuncrr_on_passes_type_check6s zKtype_check.._create_type_check_guard.._on_passes_type_checkcs2t|s.ddD}|j|d||ddSdS)NcSsg|]}t|qSrr text_type.0trrr <zUtype_check.._create_type_check_guard.._type_check.. invalid typer valid_typesFT) isinstancer)rrrvalid_type_namesr%rrr:s  zAtype_check.._create_type_check_guard.._type_checkr)rrr(rr_create_type_check_guard5s z,type_check.._create_type_check_guardr)r%r)rr(r type_check4s r*cCsnd}td}d|jvr.|jd}||krTd}n&t|drT|jdrTd}||krTd}|rj|j||||ddS) NFz-infminT serializationZ hostLabel)r min_allowed)floatmetadatahasattrr,getr)rvaluer error_typerfailedr.rrr range_checkFs    r6c@s<eZdZddZddZddZddZd d Zd d Zd S)ValidationErrorscCs g|_dSr_errorsrrrr__init__XszValidationErrors.__init__cCs|jr dSdSNTFr8r:rrrr [szValidationErrors.has_errorscCs*g}|jD]}|||q d|S)N )r9append _format_errorjoin)rZerror_messageserrorrrrr `s z ValidationErrors.generate_reportcCs|\}}}||}|dkr,d||dfS|dkrPd||dd|dfS|d krd ||d tt|d d|d fS|d kr|d}d||d |fS|dkr|d}d||d |fS|dkrd||dfS|dkrd||d tt|d d|d fSdS)Nmissing required fieldz&Missing required parameter in %s: "%s" required_name unknown fieldz1Unknown parameter in %s: "%s", must be one of: %s unknown_paramz, valid_namesr#zCInvalid type for parameter %s, value: %s, type: %s, valid types: %srr% invalid ranger.z>Invalid value for parameter %s, value: %s, valid min value: %sinvalid lengthz@Invalid length for parameter %s, value: %s, valid min length: %sunable to encode to jsonz2Invalid parameter %s must be json serializable: %s type_errorinvalid type for documentzLInvalid type for document parameter %s, value: %s, type: %s, valid types: %s) _get_namer@strtype)rrAr4r additionalr.rrrr?fsV       zValidationErrors._format_errorcCs&|sdS|dr|ddS|SdS)Ninput.r-) startswith)rrrrrrLs   zValidationErrors._get_namecKs|j|||fdSr)r9r>)rrreasonkwargsrrrrszValidationErrors.reportN) __name__ __module__ __qualname__r;r r r?rLrrrrrr7Ws "r7c@seZdZdZddZddZddZdd Zd d Ze e fd d dZ e e j d ddZe eefd ddZe e fd ddZe e jd ddZddZe efd ddZe eejfe jd ddZeZe e jd ddZdd Zd!d"Zd#S)$r z+Validates parameters against a shape model.cCst}|j|||dd|S)aValidate parameters against a shape model. This method will validate the parameters against a provided shape model. All errors will be collected before returning to the caller. This means that this method will not stop at the first error, it will return all possible errors. :param params: User provided dict of parameters :param shape: A shape model describing the expected input. :return: A list of errors. )r)r7 _validate)rr rrrrrr szParamValidator.validatecCs(t|r|jS|jdkr$|jr$|jSdS)NZ structure)r_validate_jsonvalue_string type_nameZis_document_type_validate_document)rrrrr_check_special_validation_casessz.ParamValidator._check_special_validation_casescCs<||}|r|||||nt|d|j||||dS)Nz _validate_%s)r]getattrr[)rr rrrZspecial_validatorrrrrYs  zParamValidator._validatec CsLzt|Wn8ttfyF}z|j|d|dWYd}~n d}~00dS)NrI)rJ)jsondumps ValueError TypeErrorr)rr rrrerrrrZsz)ParamValidator._validate_jsonvalue_stringc Cs|dur dSt|tr6|D]}||||||qnt|trlt|D] \}}||||d||fqHnJt|tjttt fst ttt ttf}dd|D} |j |d|t || ddS)Nz%s[%d]cSsg|]}t|qSrrrrrrr!r"z5ParamValidator._validate_document..rK)rZ param_typer%) r&dictr\list enumerater string_typesintboolr/rMrrN) rr rrrkeyindexentityr%r'rrrr\s$    z!ParamValidator._validate_documentr(c Cs|jdgD]}||vr|j|d||dq|j}g}|D].}||vr`|j|d|t|dq<||q<|D]&}||||j||d||fqpdS)NrequiredrB)rCZ user_paramsrD)rErF%s.%s)r0r2rmembersrer>rY) rr rrrZrequired_memberroZ known_paramsrrrr_validate_structures"   z"ParamValidator._validate_structurecCst|t||d|dS)NrH)r6lenrrrr_validate_strings zParamValidator._validate_stringc CsH|j}t|t||d|t|D] \}}||||d||fq"dS)NrHz%s[%s])memberr6rqrfrY)rrrrrZ member_shapeiitemrrr_validate_listszParamValidator._validate_listc CsR|j}|j}|D]8\}}||||d||f||||d||fqdS)Nz %s (key: %s)rn)rjr3itemsrY) rrrrrZ key_shapeZ value_shaperjr3rrr _validate_maps zParamValidator._validate_mapcCst|||d|dSNrGr6rrrr_validate_integersz ParamValidator._validate_integercCsHt|tttjfrdSt|dr$dS|j|d|ttttdgddS)Nreadr#zfile-like objectr$)r&bytes bytearrayrrr1rrMrrrr_validate_blobs   zParamValidator._validate_blobcCsdSrrrrrr_validate_booleansz ParamValidator._validate_booleancCst|||d|dSryrzrrrr_validate_doubleszParamValidator._validate_doublecCst|||d|dSryrzrrrr_validate_longszParamValidator._validate_longcCs2||}|s.ttdg}|j|d||ddS)Nztimestamp-stringr#r$)_type_check_datetimerrrr)rrrrrZ is_valid_typer'rrr_validate_timestamp s   z"ParamValidator._validate_timestampc Cs.zt|WdStttfy(YdS0dSr<)rrbraAttributeError)rr3rrrr*s z#ParamValidator._type_check_datetimeN) rUrVrW__doc__r r]rYrZr\r*rdrprrgrrretuplervrx integer_typesr{rrirr/decimalDecimalrZ_validate_floatrrrrrrrr s4               r c@seZdZddZddZdS)ParamValidationDecoratorcCs||_||_dSr)_param_validator _serializer)rZparam_validator serializerrrrr;5sz!ParamValidationDecorator.__init__cCsB|j}|dur4|j||j}|r4t|d|j||S)Nr) input_shaperr r rr rserialize_to_request)r parametersZoperation_modelrrrrrr9sz-ParamValidationDecorator.serialize_to_requestN)rUrVrWr;rrrrrr4sr)rZbotocore.compatrrr_rZbotocore.utilsrrZbotocore.exceptionsrrr*r6objectr7r rrrrrs     =!