a ki]- @sddlZddlZddlZddlZddlmZddlmZGdddeZ e Z e Z e Z e Z ee e e e dZdTdd Zed d ed d d dZedZedddddddZeedredejejefdddZedZedddddddZz ddlZWney"Yn0edejdd d!Zz ddlZWnbeyzdd"l m!Z!WneyzYn*0ed#d d$d%Z"ed&d&ed'd(d)Z#YnT0ed*edd+d,Z$ed-edd.d/Z%ed#edd0d%Z"ed&d&ed'd1d)Z#zdd2l&m'Z'Wn>eyJzdd2l(m'Z'WneyDdZ'Yn0Yn0e'rved3d d4d5Z)ed6d7d8d9Z*ed:ejdd;d<Z+ed=d=ed>d?d@Z,ed6edAdBdCZ-z ddl.Z.WneyYn*0dDdEZ/edFee0fdAdGdHZ1dIdJZ2z ddl3Z3Wney Yn00edKdKe3j4d'dLdMZ5edNe3j4ddOdPZ6z ddl7Z8WneypYn(0edQdQe8j9j:d'e8;<fdRdSZ=dS)UN) str_types) FormatErrorc@sHeZdZdZiZdddZddZddd ZeeZ d d Z d d Z dS) FormatCheckera A ``format`` property checker. JSON Schema does not mandate that the ``format`` property actually do any validation. If validation is desired however, instances of this class can be hooked into validators to enable format validation. `FormatChecker` objects always return ``True`` when asked about formats that they do not know how to validate. To check a custom format using a function that takes an instance and returns a ``bool``, use the `FormatChecker.checks` or `FormatChecker.cls_checks` decorators. Arguments: formats (~collections.Iterable): The known formats to validate. This argument can be used to limit which formats will be used during validation. Ncs2|durj_ntfdd|D_dS)Nc3s|]}|j|fVqdSNcheckers).0kself6/usr/lib/python3.9/site-packages/jsonschema/_format.py 'z)FormatChecker.__init__..)rcopydict)r formatsr r r __init__#szFormatChecker.__init__cCsdt|jS)Nz)formatsortedrr r r r __repr__)szFormatChecker.__repr__r csfdd}|S)a Register a decorated function as validating a new format. Arguments: format (str): The format that the decorated function will check. raises (Exception): The exception(s) raised by the decorated function when an invalid instance is found. The exception object will be accessible as the `jsonschema.exceptions.ValidationError.cause` attribute of the resulting validation error. cs|fj<|Srrfuncrraisesr r r _checks@sz%FormatChecker.checks.._checksr )r rrrr rr checks,szFormatChecker.checksc Csv||jvrdS|j|\}}d\}}z ||}Wn(|yX}z|}WYd}~n d}~00|srtd||f|ddS)a} Check whether the instance conforms to the given format. Arguments: instance (*any primitive type*, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Raises: FormatError: if the instance does not conform to ``format`` N)NNz%r is not a %r)cause)rr)r instancerrrresultrer r r checkGs   zFormatChecker.checkcCs.z|||Wnty$YdS0dSdS)a\ Check whether the instance conforms to the given format. Arguments: instance (*any primitive type*, i.e. str, number, bool): The instance to check format (str): The format that instance should conform to Returns: bool: whether it conformed FTN)r!r)r rrr r r conformsis  zFormatChecker.conforms)N)r ) __name__ __module__ __qualname____doc__rrrr classmethod cls_checksr!r"r r r r r s  "r)draft3draft4draft6draft7r cs8p|p|p|p|fdd}|S)Ncsrtd|}r0td|}rHtd|}r`td|}tprprpr||S)Nr)r*r+r,)_draft_checkersrrr(rr)r*r+r,rr r wrapsz_checks_drafts..wrapr )namer)r*r+r,rr/r r.r _checks_draftss r1z idn-email)r0ZemailcCst|tsdSd|vS)NT@) isinstancerrr r r is_emails r5z$^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$z ip-addressZipv4cCs4t|tsdSt|sdStdd|dDS)NTFcss*|]"}dt|kodknVqdS)rN)int)r componentr r r rrzis_ipv4...)r3r_ipv4_rematchallsplitr4r r r is_ipv4s   r> inet_ptonZipv6)r0rcCst|tsdSttj|SNT)r3rsocketr?ZAF_INET6r4r r r is_ipv6s rBz#^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$z host-namehostnamecCsFt|tsdSt|sdS|d}|D]}t|dkr*dSq*dS)NTFr9?)r3r _host_name_rer;r=len)r componentsr8r r r is_host_names    rHz idn-hostname)r,rcCst|tsdSt|dSr@)r3ridnaencoder4r r r is_idn_host_names  rK)validate_rfc3986ZuricCst|tsdSt|ddSNTZURIZruler3rrLr4r r r is_uris rPz uri-reference)r+r,rcCst|tsdSt|ddSNTZ URI_referencerNrOr4r r r is_uri_references rRZiricCst|tsdStj|ddS)NTZIRIrNr3rrfc3987parser4r r r is_iris rVz iri-referencecCst|tsdStj|ddS)NTZ IRI_referencerNrSr4r r r is_iri_references rWcCst|tsdStj|ddSrMrSr4r r r rPs cCst|tsdStj|ddSrQrSr4r r r rR#s )validate_rfc3339z date-timecCst|tsdSt|Sr@)r3rrXr4r r r is_datetime7s rYtime)r,cCst|tsdStd|S)NTz 1970-01-01T)r3rrYr4r r r is_time=s r[ZregexcCst|tsdSt|Sr@)r3rrecompiler4r r r is_regexDs r^date)r)r,rcCst|tsdStj|dS)NTz%Y-%m-%dr3rdatetimestrptimer4r r r is_dateKs rc)r)rcCst|tsdStj|dS)NTz%H:%M:%Sr`r4r r r is_draft3_timeRs rdcCs t|Sr) webcolorsZ normalize_hexr4r r r is_css_color_code^srfZcolorcCs$t|tr|tjvrdSt|Sr@)r3rlowerreZcss21_names_to_hexrfr4r r r is_css21_coloras  rhcCs|tjvrdSt|Sr@)rgreZcss3_names_to_hexrfr4r r r is_css3_colorjsriz json-pointercCst|tsdSt|Sr@)r3r jsonpointer JsonPointerr4r r r is_json_pointerus rlzrelative-json-pointercCsjt|tsdSgd}}t|D]6\}}|r<||q |sFdS||d}qXq |dkpht|S)NTF#)r3r enumerateisdigitappendrjrk)rZnon_negative_integerresti characterr r r is_relative_json_pointers    ruz uri-templatecCst|}||Sr) uritemplateZ URITemplateZvalidate)rZtemplate_validatortemplater r r is_uri_templates rx)NNNNNr )>rar\rAstructZjsonschema.compatrZjsonschema.exceptionsrobjectrZdraft3_format_checkerZdraft4_format_checkerZdraft6_format_checkerZdraft7_format_checkerrr-r1r5r]r:r>hasattrerror ValueErrorrBrErHrI ImportErrorZ IDNAErrorrKrTZrfc3986_validatorrLrPrRrVrWZstrict_rfc3339rXZrfc3339_validatorrYr[r^rcrdrerf TypeErrorrhrirjZJsonPointerExceptionrlruZuritemplate.exceptionsrv exceptionsZInvalidTemplateZ ValidatorZforce_balanced_bracesrxr r r r s  z  !