B ㊇c5@sdZddlZddlZddlmZddlmZddlmZmZddZ dd Z d d Z Gd d d Z GdddZ GdddZdS)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 ----------------- N)datetime)ParamValidationError)is_json_value_headerparse_to_aware_datetimecCs,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)paramsshape validatorrrl/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/botocore/validate.pyvalidate_parameterss rcsfdd}|S)Ncsfdd}fdd|S)Ncs |||r|||||SdS)Nr)selfparamr errorsname) _type_checkfuncrr_on_passes_type_check4s zKtype_check.._create_type_check_guard.._on_passes_type_checkcs2t|s.ddD}|j|d||ddSdS)NcSsg|] }t|qSr)str).0trrr :szUtype_check.._create_type_check_guard.._type_check..z invalid type)r valid_typesFT) isinstancer)rrrvalid_type_names)rrrr8s zAtype_check.._create_type_check_guard.._type_checkr)rr)r)rrr_create_type_check_guard3s z,type_check.._create_type_check_guardr)rrr)rr type_check2s 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_checkIs    r,c@s<eZdZddZddZddZddZd d Zd d Zd S)ValidationErrorscCs g|_dS)N)_errors)rrrr__init__[szValidationErrors.__init__cCs|jr dSdS)NTF)r.)rrrrr ^szValidationErrors.has_errorscCs.g}x|jD]}|||q Wd|S)N )r.append _format_errorjoin)rZerror_messageserrorrrrr cs z ValidationErrors.generate_reportc Cs|\}}}||}|dkr2d|d|ddS|dkrf|d}d|d }d |d|d |S|d kr|d }t|}d|d} d|d|d|d| S|dkr|d }|d} d|d|d| S|dkr|d }|d} d|d|d| S|dkr d||dS|dkrd|d }t|}d|d} d|d|d|d| S|dkrd|d } d!|d"| d#S|d$krd|d } d%|d&| d#SdS)'Nzmissing required fieldzMissing required parameter in z: " required_name"z unknown field unknown_paramz, valid_nameszUnknown parameter in z", must be one of: z invalid typerrzInvalid type for parameter z , value: z, type: z, valid types: z invalid ranger$zInvalid value for parameter z, valid min value: zinvalid lengthzInvalid length for parameter z, valid min length: zunable to encode to jsonz2Invalid parameter {} must be json serializable: {} type_errorzinvalid type for documentz$Invalid type for document parameter zmore than one inputmembersz.zinvalid type for document)rr@r) rdictrLlist enumeraterintboolr%rr=) rr r rrkeyindexentityrrrrrrLs$   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||qWx0|D](}||||j|||d |qWdS) Nrz empty input)r:r#zmore than one inputrequiredzmissing required field)r5Z user_paramsz unknown field)r7r8r;) Zis_tagged_unionlenrr:r&r(rUr1rI) rr r rrZrequired_memberr:Z known_paramsrrrr_validate_structures:     z"ParamValidator._validate_structurecCst|t||d|dS)Nzinvalid length)r,r])rrr rrrrr_validate_string!s zParamValidator._validate_stringc CsP|j}t|t||d|x0t|D]$\}}|||||d|dq$WdS)Nzinvalid length[])memberr,r]rVrI)rrr rrZ member_shapeiitemrrr_validate_list-szParamValidator._validate_listc Cs\|j}|j}xJ|D]>\}}|||||d|d|||||d|qWdS)Nz (key: )r;)rYr)itemsrI) rrr rrZ key_shapeZ value_shaperYr)rrr _validate_map4s zParamValidator._validate_mapcCst|||d|dS)Nz invalid range)r,)rrr rrrrr_validate_integer<sz ParamValidator._validate_integercCsFt|tttfrdSt|dr"dS|j|d|ttttdgddS)Nreadz invalid typezfile-like object)rr)rbytes bytearrayrr'r)rrr rrrrr_validate_blob@s zParamValidator._validate_blobcCsdS)Nr)rrr rrrrr_validate_booleanNsz ParamValidator._validate_booleancCst|||d|dS)Nz invalid range)r,)rrr rrrrr_validate_doubleRszParamValidator._validate_doublecCst|||d|dS)Nz invalid range)r,)rrr rrrrr_validate_longXszParamValidator._validate_longcCs0||}|s,ttdg}|j|d||ddS)Nztimestamp-stringz invalid type)rr)_type_check_datetimerrr)rrr rrZ is_valid_typerrrr_validate_timestamp\s   z"ParamValidator._validate_timestampc Cs,y t|dStttfk r&dSXdS)NTF)rrRrQAttributeError)rr)rrrrqgs z#ParamValidator._type_check_datetimeN)rErFrG__doc__rrMrIrJrLr rTr^rr_rUtuplererhrWrirmrXrnr%decimalDecimalroZ_validate_floatrprrrqrrrrrs$ )  rc@seZdZddZddZdS)ParamValidationDecoratorcCs||_||_dS)N)_param_validator _serializer)rZparam_validator serializerrrrr/rsz!ParamValidationDecorator.__init__cCsB|j}|dk r4|j||j}|r4t|d|j||S)N)r) input_shaperyrr rr rzserialize_to_request)r parametersZoperation_modelr|rrrrr}vs z-ParamValidationDecorator.serialize_to_requestN)rErFrGr/r}rrrrrxqsrx)rtrvrOrZbotocore.exceptionsrZbotocore.utilsrrrr r,r-rrxrrrrs  [=