本文整理汇总了Python中mozdns.domain.models.Domain.clean方法的典型用法代码示例。如果您正苦于以下问题:Python Domain.clean方法的具体用法?Python Domain.clean怎么用?Python Domain.clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozdns.domain.models.Domain
的用法示例。
在下文中一共展示了Domain.clean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_domain
# 需要导入模块: from mozdns.domain.models import Domain [as 别名]
# 或者: from mozdns.domain.models.Domain import clean [as 别名]
def create_domain(self, name, ip_type=None, delegated=False):
if ip_type is None:
ip_type = '4'
if name in ('arpa', 'in-addr.arpa', 'ip6.arpa'):
pass
else:
name = ip_to_domain_name(name, ip_type=ip_type)
d = Domain(name=name, delegated=delegated)
d.clean()
self.assertTrue(d.is_reverse)
return d
示例2: ensure_domain
# 需要导入模块: from mozdns.domain.models import Domain [as 别名]
# 或者: from mozdns.domain.models.Domain import clean [as 别名]
def ensure_domain(name, purgeable=False, inherit_soa=False, force=False):
"""This function will take ``domain_name`` and make sure that a domain with
that name exists. If this function creates a domain it will set the
domain's purgeable flag to the value of the named arguement ``purgeable``.
See the doc page about Labels and Domains for other information about this
function.
This function will attempt to prevent you from:
* creating a new TLD
* creating a domain that would be a child of a delegated domain
* creating a domain that wouldn't exist in an existing zone (it
wouldn't have an SOA)
You can override these constrains by setting the ``force`` named argument
to ``True``.
By default if a domain's parent has an SOA, the new domain will not inherit
that SOA. You can cause the domain to inherit the SOA by passing the named
argument ``inherit_soa`` as ``True``. For example, the function
:func:`ensure_label_domain` passes ``inherit_soa=True``.
If a domain already exists with a name equal to ``name`` it is immediately
returned. It is up to the caller to ensure that ``purgeable`` is set if it
is needed.
"""
try:
domain = Domain.objects.get(name=name)
return domain
except ObjectDoesNotExist:
pass
# Looks like we are creating some domains. Make sure the first domain we
# create is under a domain that has a non-None SOA reference.
parts = list(reversed(name.split('.')))
if not force:
domain_name = ''
leaf_domain = None
# Find the leaf domain.
for i in range(len(parts)):
domain_name = parts[i] + '.' + domain_name
domain_name = domain_name.strip('.')
try:
tmp_domain = Domain.objects.get(name=domain_name)
# It got here so we know we found a domain.
leaf_domain = tmp_domain
except ObjectDoesNotExist:
continue
if not leaf_domain:
raise ValidationError(
"Creating this record would cause the "
"creation of a new TLD. Please contact "
"http://www.icann.org/ for more information.")
if leaf_domain.delegated:
raise ValidationError(
"Creating this record would cause the "
"creation of a domain that would be a child of a "
"delegated domain.")
if not leaf_domain.soa:
raise ValidationError(
"Creating this record would cause the "
"creation of a domain that would not be in an existing "
"DNS zone.")
domain_name = ''
# We know the end domain doesn't exist, so we build it up incrementally
# starting at the very right most parent domain. If we find that a parent
# domain already exists we continue until we find the domain that doesn't
# exist.
for i in range(len(parts)):
domain_name = parts[i] + '.' + domain_name
domain_name = domain_name.strip('.')
if Domain.objects.filter(name=domain_name).exists():
continue
# We are about to create a domain that previously didn't exist!
clobber_querysets = get_clobbered(domain_name)
# Don't use get_or_create here because we need to pass certain kwargs
# to clean()
domain = Domain(name=domain_name)
# we know the clobber_querysets may conflict, but we will handle
# resolving the conflict later in this function
if purgeable:
domain.purgeable = True
domain.clean(ignore_conflicts=True) # master domain is set here
if (inherit_soa and domain.master_domain and
domain.master_domain.soa is not None):
domain.soa = domain.master_domain.soa
# get the domain in the db so we can save the clobbered objects
domain.save(do_full_clean=False)
# update the objects that initially conflicted with this domain
for qs in clobber_querysets:
qs.update(domain=domain, label='')
#.........这里部分代码省略.........