3 ;X"@sddlZddlZddlZddlmZddlmZGdddeZggdZ dddffddZ e d d d Z ej d Z e d ddddZeedre dejdddZej dZe dddddZy ddlZWnek rYnXe dedddZy ddlZWnTek r^y ddlZWnek r>YnXe deejfddd ZYnXe dd!d Ze d"ejdd#d$Ze d%ed&d'd(Ze d)ed&d*d+Zy ddlZWnek rYn*Xd,d-Z e d.ee!fd&d/d0Z"d1d2Z#ee d3Z$ee d4Z%dS)5N) str_types) FormatErrorc@sBeZdZdZiZd ddZffddZeeZddZ 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. :class:`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 :meth:`FormatChecker.checks` or :meth:`FormatChecker.cls_checks` decorators. Arguments: formats (iterable): The known formats to validate. This argument can be used to limit which formats will be used during validation. Ncs2|dkrjj_ntfdd|D_dS)Nc3s|]}|j|fVqdS)N)checkers).0k)self/usr/lib/python3.6/_format.py 'sz)FormatChecker.__init__..)rcopydict)rZformatsr )rr __init__#szFormatChecker.__init__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 :attr:`ValidationError.cause` attribute of the resulting validation error. cs|fj<|S)N)r)func)formatraisesrr r _checks>sz%FormatChecker.checks.._checksr )rrrrr )rrrr checks)szFormatChecker.checkscCst||jkrdS|j|\}}d\}}y ||}Wn&|k rV}z |}WYdd}~XnX|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: :exc:`FormatError` if instance does not conform to ``format`` Nz%r is not a %r)cause)NN)rr)rinstancerrrresultrer r r checkEs  zFormatChecker.checkc Cs.y|j||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 conformshs zFormatChecker.conforms)N) __name__ __module__ __qualname____doc__rrr classmethod cls_checksrrr r r r r s  #r)draft3draft4cs$p|p|fdd}|S)NcsHr"tdjtj|}rDtdjtj|}|S)Nr r!)_draft_checkersappendrr)r)r r!rr r wrapsz_checks_drafts..wrapr )Zbothr r!rr$r )r r!rr _checks_draftssr%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|tsdStj|sdStdd|jdDS)NTFcss*|]"}dt|kodknVqdS)rN)int)r componentr r r r szis_ipv4...)r'r_ipv4_rematchallsplit)rr r r is_ipv4s   r1 inet_ptonZipv6)rcCst|tsdStjtj|S)NT)r'rsocketr2ZAF_INET6)rr r r is_ipv6s r4z#^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$z host-nameZhostnamecCsHt|tsdStj|sdS|jd}x|D]}t|dkr,dSq,WdS)NTFr,?)r'r _host_name_rer.r0len)rZ componentsr+r r r is_host_names     r8ZuricCst|tsdStj|ddS)NTZURI)Zrule)r'rrfc3987parse)rr r r is_uris r;z date-timecCst|tsdStj|S)NT)r'risodateZparse_datetime)rr r r is_datetimes r=cCst|tsdStj|S)NT)r'rstrict_rfc3339Zvalidate_rfc3339)rr r r r=s ZregexcCst|tsdStj|S)NT)r'rrecompile)rr r r is_regexs rAZdate)r rcCst|tsdStjj|dS)NTz%Y-%m-%d)r'rdatetimestrptime)rr r r is_dates rDZtimecCst|tsdStjj|dS)NTz%H:%M:%S)r'rrBrC)rr r r is_times rEcCs tj|S)N) webcolorsZ normalize_hex)rr r r is_css_color_codesrGZcolorcCs&t|t s|jtjkrdSt|S)NT)r'rlowerrFZcss21_names_to_hexrG)rr r r is_css21_colors rIcCs|jtjkrdSt|S)NT)rHrFZcss3_names_to_hexrG)rr r r is_css3_colorsrJr r!)&rBr?r3Zjsonschema.compatrZjsonschema.exceptionsrobjectrr"r%r(r@r-r1hasattrerrorr4r6r8r9 ImportError ValueErrorr;r>r<Z ISO8601Errorr=rArDrErFrG TypeErrorrIrJZdraft3_format_checkerZdraft4_format_checkerr r r r sP  {