当前位置: 首页>>代码示例>>Python>>正文


Python ipv4_re.match方法代码示例

本文整理汇总了Python中django.core.validators.ipv4_re.match方法的典型用法代码示例。如果您正苦于以下问题:Python ipv4_re.match方法的具体用法?Python ipv4_re.match怎么用?Python ipv4_re.match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.validators.ipv4_re的用法示例。


在下文中一共展示了ipv4_re.match方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_query

# 需要导入模块: from django.core.validators import ipv4_re [as 别名]
# 或者: from django.core.validators.ipv4_re import match [as 别名]
def _check_query(self, query, country=False, city=False, city_or_country=False):
        "Helper routine for checking the query and database availability."
        # Making sure a string was passed in for the query.
        if not isinstance(query, six.string_types):
            raise TypeError('GeoIP query must be a string, not type %s' % type(query).__name__)

        # Extra checks for the existence of country and city databases.
        if city_or_country and not (self._country or self._city):
            raise GeoIP2Exception('Invalid GeoIP country and city data files.')
        elif country and not self._country:
            raise GeoIP2Exception('Invalid GeoIP country data file: %s' % self._country_file)
        elif city and not self._city:
            raise GeoIP2Exception('Invalid GeoIP city data file: %s' % self._city_file)

        # Return the query string back to the caller. GeoIP2 only takes IP addresses.
        if not (ipv4_re.match(query) or is_valid_ipv6_address(query)):
            query = socket.gethostbyname(query)

        return query 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:21,代码来源:base.py

示例2: city

# 需要导入模块: from django.core.validators import ipv4_re [as 别名]
# 或者: from django.core.validators.ipv4_re import match [as 别名]
def city(self, query):
        """
        Returns a dictionary of city information for the given IP address or
        Fully Qualified Domain Name (FQDN).  Some information in the dictionary
        may be undefined (None).
        """
        enc_query = self._check_query(query, city=True)
        if ipv4_re.match(query):
            # If an IP address was passed in
            return GeoIP_record_by_addr(self._city, c_char_p(enc_query))
        else:
            # If a FQDN was passed in.
            return GeoIP_record_by_name(self._city, c_char_p(enc_query)) 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:15,代码来源:base.py

示例3: country_code

# 需要导入模块: from django.core.validators import ipv4_re [as 别名]
# 或者: from django.core.validators.ipv4_re import match [as 别名]
def country_code(self, query):
        "Returns the country code for the given IP Address or FQDN."
        enc_query = self._check_query(query, city_or_country=True)
        if self._country:
            if ipv4_re.match(query):
                return GeoIP_country_code_by_addr(self._country, enc_query)
            else:
                return GeoIP_country_code_by_name(self._country, enc_query)
        else:
            return self.city(query)['country_code'] 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:12,代码来源:base.py

示例4: country_name

# 需要导入模块: from django.core.validators import ipv4_re [as 别名]
# 或者: from django.core.validators.ipv4_re import match [as 别名]
def country_name(self, query):
        "Returns the country name for the given IP Address or FQDN."
        enc_query = self._check_query(query, city_or_country=True)
        if self._country:
            if ipv4_re.match(query):
                return GeoIP_country_name_by_addr(self._country, enc_query)
            else:
                return GeoIP_country_name_by_name(self._country, enc_query)
        else:
            return self.city(query)['country_name'] 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:12,代码来源:base.py


注:本文中的django.core.validators.ipv4_re.match方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。