Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
dmapi / usr / lib / python2.7 / dist-packages / dmapi / api / validation / __init__.pyc
Size: Mime:
ó
ÿ^¢`c@sudZddlZddlZddlmZddlmZed„Z	ddd„Zd„Zddd„Z
dS(	s&
Request Body validating middleware.

iÿÿÿÿN(tapi_version_request(t
validatorscCsêtj|ƒ}tj|ƒ}d|krJ|dj}	|djƒ}
n|dj}	|djƒ}
|
r®|dks…|dkrætj||
|ƒ}|j|ƒtSn8|	j	||ƒrætj||
|ƒ}|j|ƒtSt
S(s]A helper method to execute JSON-Schema Validation.

    This method checks the request version whether matches the specified max
    version and min_version. It also takes a care of legacy v2 request.

    If the version range matches the request, we validate the schema against
    the target and a failure will result in a ValidationError being raised.

    :param schema: A dict, the JSON-Schema is used to validate the target.
    :param target: A dict, the target is validated by the JSON-Schema.
    :param min_version: A string of two numerals. X.Y indicating the minimum
                        version of the JSON-Schema to validate against.
    :param max_version: A string of two numerals. X.Y indicating the maximum
                        version of the JSON-Schema to validate against.
    :param args: Positional arguments which passed into original method.
    :param kwargs: Keyword arguments which passed into original method.
    :param is_body: A boolean. Indicating whether the target is HTTP request
                    body or not.
    :returns: A boolean. `True` if and only if the version range matches the
              request AND the schema is successfully validated. `False` if the
              version range does not match the request and no validation is
              performed.
    :raises: ValidationError, when the validation fails.
    treqis2.0N(tapi_versiontAPIVersionRequestRtis_legacy_v2tNoneRt_SchemaValidatortvalidatetTruetmatchestFalse(tschemattargettmin_versiontmax_versiontargstkwargstis_bodytmin_vertmax_vertvert	legacy_v2tschema_validator((sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyt_schema_validation_helpers&



cs‡‡‡fd†}|S(sâRegister a schema to validate request body.

    Registered schema will be used for validating request body just before
    API method executing.

    :argument dict request_body_schema: a schema to validate request body

    cs+tjˆƒ‡‡‡‡fd†ƒ}|S(Ncs*tˆ|dˆˆ||ƒˆ||ŽS(Ntbody(R(RR(tfuncRRtrequest_body_schema(sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pytwrapper]s

(t	functoolstwraps(RR(RRR(RsA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyt
add_validator\s'((RRRR((RRRsA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyRRs
	csÏ|jdtƒ}g}|jddƒ}|rZx'|D]}|jtj|ƒƒq7Wn|rËxht|jjƒƒD]N‰ˆt	|djƒƒkrvt	‡fd†|DƒƒsÄ|jˆ=qÄqvqvWndS(sPStrip the additional properties from the req.GET.

    This helper method assumes the JSON-Schema is only described as a dict
    without nesting. This method should be called after query parameters pass
    the JSON-Schema validation. It also means this method only can be called
    after _schema_validation_helper return `True`.
    tadditionalPropertiestpatternPropertiest
propertiesc3s$|]}|jˆƒr|VqdS(N(tmatch(t.0tregex(tparam(sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pys	<genexpr>sN(
tgetR	RtappendtretcompiletsettGETtkeystlist(RRtadditional_propertiestpattern_regexestpatternsR%((R&sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyt"_strip_additional_query_parametershs
cs‡‡‡fd†}|S(sIRegister a schema to validate request query parameters.

    Registered schema will be used for validating request query params just
    before API method executing.

    :param query_params_schema: A dict, the JSON-Schema for validating the
                                query parameters.
    :param min_version: A string of two numerals. X.Y indicating the minimum
                        version of the JSON-Schema to validate against.
    :param max_version: A string of two numerals. X.Y indicating the maximum
                        version of the JSON-Schema against to.
    cs+tjˆƒ‡‡‡‡fd†ƒ}|S(Nc	sjd|kr|d}n
|d}tˆ|jjƒˆˆ||dtƒr]tˆ|ƒnˆ||ŽS(NRiR(RR,t
dict_of_listsRR2(RRR(RRRtquery_params_schema(sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyR”s

(RR(RR(RRR4(RsA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyR“s'((R4RRR((RRR4sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pytquery_schema„s(t__doc__RR)tdmapi.api.openstackRRtdmapi.api.validationRR	RRRR2R5(((sA/usr/lib/python2.7/dist-packages/dmapi/api/validation/__init__.pyt<module>sA