B =@Sa4@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 validatorrri/private/var/folders/fg/1jzmct0d7d72tjkvm_1nhqc5sw67yj/T/pip-unpacked-wheel-ef76ia09/botocore/validate.pyvalidate_parameterss rcsfdd}|S)Ncsfdd}fdd|S)Ncs |||r|||||SdS)Nr)selfparamr errorsname) _type_checkfuncrr_on_passes_type_check6s zKtype_check.._create_type_check_guard.._on_passes_type_checkcs2t|s.ddD}|j|d||ddSdS)NcSsg|]}t|qSr)r text_type).0trrr <szUtype_check.._create_type_check_guard.._type_check..z invalid type)r valid_typesFT) isinstancer)rrrvalid_type_names)rrrr:s   zAtype_check.._create_type_check_guard.._type_checkr)rr)r)rrr_create_type_check_guard5s z,type_check.._create_type_check_guardr)rrr)rr type_check4s r cCsnd}td}d|jkr.|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    r,c@s<eZdZddZddZddZddZd d Zd d Zd S)ValidationErrorscCs g|_dS)N)_errors)rrrr__init__XszValidationErrors.__init__cCs|jr dSdS)NTF)r.)rrrrr [szValidationErrors.has_errorscCs.g}x|jD]}|||q Wd|S)N )r.append _format_errorjoin)rZerror_messageserrorrrrr `s z ValidationErrors.generate_reportcCsV|\}}}||}|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 fS|dkr2d|d|dfS|dkrRd|d|dfSdS)Nzmissing required fieldz&Missing required parameter in %s: "%s" required_namez unknown fieldz1Unknown parameter in %s: "%s", must be one of: %s unknown_paramz, valid_namesz invalid typezCInvalid type for parameter %s, value: %s, type: %s, valid types: %srrz invalid ranger$z>Invalid value for parameter %s, value: %s, valid min value: %szinvalid lengthz@Invalid length for parameter %s, value: %s, valid min length: %szunable to encode to jsonz2Invalid parameter %s must be json serializable: %s type_errorzinvalid type for documentzLInvalid type for document parameter %s, value: %s, type: %s, valid types: %szmore than one inputzkInvalid number of parameters set for tagged union structure %s. Can only set one of the following keys: %s.z. membersz empty inputzDMust set one of the following keys for tagged unionstructure %s: %s.) _get_namer3strtype)rr4r*r additionalr$rrrr2fsL     zValidationErrors._format_errorcCs&|sdS|dr|ddS|SdS)Ninput.r#) startswith)rrrrrr:s   zValidationErrors._get_namecKs|j|||fdS)N)r.r1)rrreasonkwargsrrrrszValidationErrors.reportN) __name__ __module__ __qualname__r/r r r2r:rrrrrr-Ws ,r-c@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)$rz+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)r- _validate)rr r rrrrr szParamValidator.validatecCs(t|r|jS|jdkr$|jr$|jSdS)NZ structure)r_validate_jsonvalue_string type_nameZis_document_type_validate_document)rr rrr_check_special_validation_casessz.ParamValidator._check_special_validation_casescCs<||}|r|||||nt|d|j||||dS)Nz _validate_%s)rKgetattrrI)rr r rrZspecial_validatorrrrrGs  zParamValidator._validatec CsJyt|Wn6ttfk rD}z|j|d|dWdd}~XYnXdS)Nzunable to encode to json)r8)jsondumps ValueError TypeErrorr)rr r rrerrrrHsz)ParamValidator._validate_jsonvalue_stringc Cs|dkr dSt|tr:x|D]}||||||qWnt|trtxxt|D] \}}||||d||fqNWnJt|tjttt fst ttt ttf}dd|D} |j |d|t || ddS)Nz%s[%d]cSsg|]}t|qSr)rr)rrrrrrsz5ParamValidator._validate_document..zinvalid type for document)rZ param_typer) rdictrJlist enumerater string_typesintboolr%r;rr<) rr r rrkeyindexentityrrrrrrJs     z!ParamValidator._validate_document)rc Cs|jrDt|dkr&|j|d|jdnt|dkrD|j|d|jdx0|jdgD]}||krT|j|d||dqTW|j}g}x6|D].}||kr|j|d |t|d q||qWx.|D]&}||||j||d ||fqWdS) Nrz empty input)r9r#zmore than one inputrequiredzmissing required field)r5Z user_paramsz unknown field)r6r7z%s.%s) Zis_tagged_unionlenrr9r&r(rSr1rG) rr r rrZrequired_memberr9Z known_paramsrrrr_validate_structures(     z"ParamValidator._validate_structurecCst|t||d|dS)Nzinvalid length)r,r\)rrr rrrrr_validate_strings zParamValidator._validate_stringc CsL|j}t|t||d|x,t|D] \}}||||d||fq$WdS)Nzinvalid lengthz%s[%s])memberr,r\rTrG)rrr rrZ member_shapeiitemrrr_validate_listszParamValidator._validate_listc CsV|j}|j}xD|D]8\}}||||d||f||||d||fqWdS)Nz %s (key: %s)z%s.%s)rXr)itemsrG) rrr rrZ key_shapeZ value_shaperXr)rrr _validate_map s   zParamValidator._validate_mapcCst|||d|dS)Nz invalid range)r,)rrr rrrrr_validate_integersz ParamValidator._validate_integercCsHt|tttjfrdSt|dr$dS|j|d|ttttdgddS)Nreadz invalid typezfile-like object)rr)rbytes bytearrayrrr'rr;)rrr rrrrr_validate_blobs   zParamValidator._validate_blobcCsdS)Nr)rrr rrrrr_validate_boolean$sz ParamValidator._validate_booleancCst|||d|dS)Nz invalid range)r,)rrr rrrrr_validate_double(szParamValidator._validate_doublecCst|||d|dS)Nz invalid range)r,)rrr rrrrr_validate_long.szParamValidator._validate_longcCs2||}|s.ttdg}|j|d||ddS)Nztimestamp-stringz invalid type)rr)_type_check_datetimerrrr)rrr rrZ is_valid_typerrrr_validate_timestamp2s   z"ParamValidator._validate_timestampc Cs,y t|dStttfk r&dSXdS)NTF)rrPrOAttributeError)rr)rrrrm<s z#ParamValidator._type_check_datetimeN) rCrDrE__doc__r rKrGrHrJr rRr]rrUr^rStuplerbrd integer_typesrerirWrjr%decimalDecimalrkZ_validate_floatrlrnrmrrrrrs$    rc@seZdZddZddZdS)ParamValidationDecoratorcCs||_||_dS)N)_param_validator _serializer)rZparam_validator serializerrrrr/Gsz!ParamValidationDecorator.__init__cCsB|j}|dk r4|j||j}|r4t|d|j||S)N)r) input_shapervr r rr rwserialize_to_request)r parametersZoperation_modelryrrrrrzKsz-ParamValidationDecorator.serialize_to_requestN)rCrDrEr/rzrrrrruFsru)rpZbotocore.compatrrsrMrZbotocore.utilsrrZbotocore.exceptionsrrr r,objectr-rrurrrrs     G)