本文整理汇总了Python中jsonschema.compat.str_types方法的典型用法代码示例。如果您正苦于以下问题:Python compat.str_types方法的具体用法?Python compat.str_types怎么用?Python compat.str_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonschema.compat
的用法示例。
在下文中一共展示了compat.str_types方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_ipv4
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_ipv4(instance):
if not isinstance(instance, compat.str_types):
return True
try:
address = netaddr.IPAddress(instance, version=4)
# netaddr happly accepts, and expands "127.0" into "127.0.0.0"
if str(address) != instance:
return False
except Exception:
return False
if instance == '0.0.0.0': # RFC5735
return False
return True
示例2: is_email
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_email(instance):
if not isinstance(instance, str_types):
return True
return "@" in instance
示例3: is_ipv4
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_ipv4(instance):
if not isinstance(instance, str_types):
return True
if not _ipv4_re.match(instance):
return False
return all(0 <= int(component) <= 255 for component in instance.split("."))
示例4: is_ipv6
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_ipv6(instance):
if not isinstance(instance, str_types):
return True
return socket.inet_pton(socket.AF_INET6, instance)
示例5: is_host_name
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_host_name(instance):
if not isinstance(instance, str_types):
return True
if not _host_name_re.match(instance):
return False
components = instance.split(".")
for component in components:
if len(component) > 63:
return False
return True
示例6: is_uri
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_uri(instance):
if not isinstance(instance, str_types):
return True
return rfc3987.parse(instance, rule="URI")
示例7: is_datetime
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_datetime(instance):
if not isinstance(instance, str_types):
return True
return strict_rfc3339.validate_rfc3339(instance)
示例8: is_regex
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_regex(instance):
if not isinstance(instance, str_types):
return True
return re.compile(instance)
示例9: is_date
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_date(instance):
if not isinstance(instance, str_types):
return True
return datetime.datetime.strptime(instance, "%Y-%m-%d")
示例10: is_time
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_time(instance):
if not isinstance(instance, str_types):
return True
return datetime.datetime.strptime(instance, "%H:%M:%S")
示例11: is_css21_color
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_css21_color(instance):
if (
not isinstance(instance, str_types) or
instance.lower() in webcolors.css21_names_to_hex
):
return True
return is_css_color_code(instance)
示例12: is_ipv6
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_ipv6(instance):
if not isinstance(instance, compat.str_types):
return True
try:
netaddr.IPAddress(instance, version=6)
except Exception:
return False
return True
示例13: is_hostname
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_hostname(instance):
if not isinstance(instance, compat.str_types):
return True
if not re.match(RE_HOSTNAME, instance):
return False
return True
示例14: is_ns_hostname
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_ns_hostname(instance):
if not isinstance(instance, compat.str_types):
return True
# BIND doesn't like *.host.com. see bug #1533299
if not re.match(RE_ZONENAME, instance):
return False
return True
示例15: is_ip_or_host
# 需要导入模块: from jsonschema import compat [as 别名]
# 或者: from jsonschema.compat import str_types [as 别名]
def is_ip_or_host(instance):
if not isinstance(instance, compat.str_types):
return True
if not re.match(RE_ZONENAME, instance)\
and not is_ipv4(instance)\
and not is_ipv6(instance):
return False
return True