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)rformatsr )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)emailcCst|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   r7 inet_ptonZipv6)r)rcCst|tsdSttj|S)NT)r-rsocketr8AF_INET6)rr r r is_ipv6s r;z#^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$z host-namehostnamecCsHt|tsdSt|sdS|d}x|D]}t|dkr,dSq,WdS)NTFr2?)r-r _host_name_rer4r6len)r componentsr1r r r is_host_names     rAz idn-hostname)r&rcCst|tsdSt|dS)NT)r-ridnaencode)rr r r is_idn_host_names  rD)validate_rfc3986ZuricCst|tsdSt|ddS)NTURI)rule)r-rrE)rr r r is_uris rHz uri-reference)r%r&rcCst|tsdSt|ddS)NT URI_reference)rG)r-rrE)rr r r is_uri_references rJZiricCst|tsdStj|ddS)NTZIRI)rG)r-rrfc3987parse)rr r r is_iris rMz iri-referencecCst|tsdStj|ddS)NTZ IRI_reference)rG)r-rrKrL)rr r r is_iri_references rNcCst|tsdStj|ddS)NTrF)rG)r-rrKrL)rr r r rHs cCst|tsdStj|ddS)NTrI)rG)r-rrKrL)rr r r rJ#s )validate_rfc3339z date-timecCst|tsdSt|S)NT)r-rrO)rr r r is_datetime7s rPtime)r&cCst|tsdStd|S)NTz 1970-01-01T)r-rrP)rr r r is_time=s rRregexcCst|tsdSt|S)NT)r-rrecompile)rr r r is_regexDs rVdate)r#r&rcCst|tsdStj|dS)NTz%Y-%m-%d)r-rdatetimestrptime)rr r r is_dateKs rZ)r#rcCst|tsdStj|dS)NTz%H:%M:%S)r-rrXrY)rr r r is_draft3_timeRs r[cCs t|S)N) webcolorsZ normalize_hex)rr r r is_css_color_code^sr]ZcolorcCs$t|tr|tjkrdSt|S)NT)r-rlowerr\Zcss21_names_to_hexr])rr r r is_css21_coloras r_cCs|tjkrdSt|S)NT)r^r\Zcss3_names_to_hexr])rr r r is_css3_colorjsr`z json-pointercCst|tsdSt|S)NT)r-r jsonpointer JsonPointer)rr r r is_json_pointerus rczrelative-json-pointercCsjt|tsdSgd}}x>t|D]2\}}|r>||q"|sFdS||d}Pq"W|dkpht|S)NTF#)r-r enumerateisdigitappendrarb)rZnon_negative_integerresti characterr r r is_relative_json_pointers    rlz uri-templatecCst|}||S)N) uritemplateZ URITemplatevalidate)rZtemplate_validatortemplater r r is_uri_templates rp)NNNNNr )>rXrTr9structZjsonschema.compatrZjsonschema.exceptionsrobjectrZdraft3_format_checkerZdraft4_format_checkerZdraft6_format_checkerZdraft7_format_checkerr r'r*r.rUr3r7hasattrerror ValueErrorr;r>rArB ImportErrorZ IDNAErrorrDrKZrfc3986_validatorrErHrJrMrNZstrict_rfc3339rOZrfc3339_validatorrPrRrVrZr[r\r] TypeErrorr_r`raZJsonPointerExceptionrcrlZuritemplate.exceptionsrm exceptionsZInvalidTemplateZ ValidatorZforce_balanced_bracesrpr r r r s  z