B pSe- @sddlZddlZddlZddlZddlmZddlmZGdddeZ e Z e Z e Z e Z ee e e e dZdTdd Zed d ed d d dZedZedddddddZeedredejejefdddZedZedddddddZy ddlZWnek r$YnXedejdd d!Zy ddlZWnfek rydd"l m!Z!Wnek rYn*Xed#d d$d%Z"ed&d&ed'd(d)Z#YnTXed*edd+d,Z$ed-edd.d/Z%ed#edd0d%Z"ed&d&ed'd1d)Z#ydd2l&m'Z'WnBek rTydd2l(m'Z'Wnek rNdZ'YnXYnXe'red3d d4d5Z)ed6d7d8d9Z*ed:ejdd;d<Z+ed=d=ed>d?d@Z,ed6edAdBdCZ-y ddl.Z.Wnek rYn*XdDdEZ/edFee0fdAdGdHZ1dIdJZ2y ddl3Z3Wnek r.Yn0XedKdKe3j4d'dLdMZ5edNe3j4ddOdPZ6y ddl7Z8Wnek rYn(XedQdQe8j9j: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|dkrj_ntfdd|D_dS)Nc3s|]}|j|fVqdS)N)checkers).0k)selfC/opt/alt/python37/lib/python3.7/site-packages/jsonschema/_format.py 'sz)FormatChecker.__init__..)rcopydict)rZformatsr )rr __init__#szFormatChecker.__init__cCsdt|jS)Nz)formatsortedr)rr 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<|S)N)r)func)rraisesrr r _checks@sz%FormatChecker.checks.._checksr )rrrrr )rrrr checks,szFormatChecker.checksc Cst||jkrdS|j|\}}d\}}y ||}Wn&|k rV}z|}Wdd}~XYnX|sptd||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)rinstancerrrresultrer r r checkGs  zFormatChecker.checkcCs.y|||Wntk r$dSXdSdS)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)rr)rrrr r r conformsis zFormatChecker.conforms)N)r ) __name__ __module__ __qualname____doc__rrrr classmethod cls_checksrrr 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!)r)r"r#r$r%rr r wrapsz_checks_drafts..wrapr )namer"r#r$r%rr'r )r"r#r$r%rr _checks_draftss r)z idn-email)r(ZemailcCst|tsdSd|kS)NT@) isinstancer)rr r r is_emails r,z$^\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 r szis_ipv4...)r+r_ipv4_rematchallsplit)rr r r is_ipv4s   r5 inet_ptonZipv6)r(rcCst|tsdSttj|S)NT)r+rsocketr6ZAF_INET6)rr r r is_ipv6s r8z#^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$z host-nameZhostnamecCsHt|tsdSt|sdS|d}x|D]}t|dkr,dSq,WdS)NTFr0?)r+r _host_name_rer2r4len)rZ componentsr/r r r is_host_names     r<z idn-hostname)r%rcCst|tsdSt|dS)NT)r+ridnaencode)rr r r is_idn_host_names  r?)validate_rfc3986ZuricCst|tsdSt|ddS)NTURI)rule)r+rr@)rr r r is_uris rCz uri-reference)r$r%rcCst|tsdSt|ddS)NT URI_reference)rB)r+rr@)rr r r is_uri_references rEZiricCst|tsdStj|ddS)NTZIRI)rB)r+rrfc3987parse)rr r r is_iris rHz iri-referencecCst|tsdStj|ddS)NTZ IRI_reference)rB)r+rrFrG)rr r r is_iri_references rIcCst|tsdStj|ddS)NTrA)rB)r+rrFrG)rr r r rCs cCst|tsdStj|ddS)NTrD)rB)r+rrFrG)rr r r rE#s )validate_rfc3339z date-timecCst|tsdSt|S)NT)r+rrJ)rr r r is_datetime7s rKtime)r%cCst|tsdStd|S)NTz 1970-01-01T)r+rrK)rr r r is_time=s rMZregexcCst|tsdSt|S)NT)r+rrecompile)rr r r is_regexDs rPZdate)r"r%rcCst|tsdStj|dS)NTz%Y-%m-%d)r+rdatetimestrptime)rr r r is_dateKs rS)r"rcCst|tsdStj|dS)NTz%H:%M:%S)r+rrQrR)rr r r is_draft3_timeRs rTcCs t|S)N) webcolorsZ normalize_hex)rr r r is_css_color_code^srVZcolorcCs$t|tr|tjkrdSt|S)NT)r+rlowerrUZcss21_names_to_hexrV)rr r r is_css21_coloras rXcCs|tjkrdSt|S)NT)rWrUZcss3_names_to_hexrV)rr r r is_css3_colorjsrYz json-pointercCst|tsdSt|S)NT)r+r jsonpointer JsonPointer)rr r r is_json_pointerus r\zrelative-json-pointercCsjt|tsdSgd}}x>t|D]2\}}|r>||q"|sFdS||d}Pq"W|dkpht|S)NTF#)r+r enumerateisdigitappendrZr[)rZnon_negative_integerresti characterr r r is_relative_json_pointers    rez uri-templatecCst|}||S)N) uritemplateZ URITemplateZvalidate)rZtemplate_validatortemplater r r is_uri_templates rh)NNNNNr )>rQrNr7ZstructZjsonschema.compatrZjsonschema.exceptionsrobjectrZdraft3_format_checkerZdraft4_format_checkerZdraft6_format_checkerZdraft7_format_checkerr r&r)r,rOr1r5hasattrerror ValueErrorr8r:r<r= ImportErrorZ IDNAErrorr?rFZrfc3986_validatorr@rCrErHrIZstrict_rfc3339rJZrfc3339_validatorrKrMrPrSrTrUrV TypeErrorrXrYrZZJsonPointerExceptionr\reZuritemplate.exceptionsrf exceptionsZInvalidTemplateZ ValidatorZforce_balanced_bracesrhr r r r s  z