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


Python idna.nameprep方法代码示例

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


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

示例1: test_nameprep

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def test_nameprep(self):
        from encodings.idna import nameprep
        for pos, (orig, prepped) in enumerate(nameprep_tests):
            if orig is None:
                # Skipped
                continue
            # The Unicode strings are given in UTF-8
            orig = unicode(orig, "utf-8")
            if prepped is None:
                # Input contains prohibited characters
                self.assertRaises(UnicodeError, nameprep, orig)
            else:
                prepped = unicode(prepped, "utf-8")
                try:
                    self.assertEqual(nameprep(orig), prepped)
                except Exception,e:
                    raise test_support.TestFailed("Test 3.%d: %s" % (pos+1, str(e))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_codecs.py

示例2: test_nameprep

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def test_nameprep(self):
        from encodings.idna import nameprep
        for pos, (orig, prepped) in enumerate(nameprep_tests):
            if orig is None:
                # Skipped
                continue
            # The Unicode strings are given in UTF-8
            orig = str(orig, "utf-8", "surrogatepass")
            if prepped is None:
                # Input contains prohibited characters
                self.assertRaises(UnicodeError, nameprep, orig)
            else:
                prepped = str(prepped, "utf-8", "surrogatepass")
                try:
                    self.assertEqual(nameprep(orig), prepped)
                except Exception as e:
                    raise support.TestFailed("Test 3.%d: %s" % (pos+1, str(e))) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_codecs.py

示例3: test_nameprep

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def test_nameprep(self):
        from encodings.idna import nameprep
        for pos, (orig, prepped) in enumerate(nameprep_tests):
            if orig is None:
                # Skipped
                continue
            # The Unicode strings are given in UTF-8
            orig = unicode(orig, "utf-8")
            if prepped is None:
                # Input contains prohibited characters
                self.assertRaises(UnicodeError, nameprep, orig)
            else:
                prepped = unicode(prepped, "utf-8")
                try:
                    self.assertEquals(nameprep(orig), prepped)
                except Exception,e:
                    raise test_support.TestFailed("Test 3.%d: %s" % (pos+1, str(e))) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:19,代码来源:test_codecs.py

示例4: prepare

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def prepare(self, string):
        result = []

        labels = idna.dots.split(string)

        if labels and len(labels[-1]) == 0:
            trailing_dot = u'.'
            del labels[-1]
        else:
            trailing_dot = u''

        for label in labels:
            result.append(self.nameprep(label))

        return u".".join(result) + trailing_dot 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:xmpp_stringprep.py

示例5: nameprep

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def nameprep(self, label):
        label = idna.nameprep(label)
        self.check_prohibiteds(label)
        if label[0] == u'-':
            raise UnicodeError("Invalid leading hyphen-minus")
        if label[-1] == u'-':
            raise UnicodeError("Invalid trailing hyphen-minus")
        return label 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:xmpp_stringprep.py

示例6: nameprep

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def nameprep(self, label):
            return label.lower() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:4,代码来源:xmpp_stringprep.py

示例7: prepare

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def prepare(self, string):
        result = []

        labels = idna.dots.split(string)

        if labels and len(labels[-1]) == 0:
            trailing_dot = '.'
            del labels[-1]
        else:
            trailing_dot = ''

        for label in labels:
            result.append(self.nameprep(label))

        return ".".join(result) + trailing_dot 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:17,代码来源:xmpp_stringprep.py

示例8: __prepare_domain

# 需要导入模块: from encodings import idna [as 别名]
# 或者: from encodings.idna import nameprep [as 别名]
def __prepare_domain(data):
        """Prepare domainpart of the JID.

        :Parameters:
            - `data`: Domain part of the JID
        :Types:
            - `data`: `str`

        :raise JIDError: if the domain name is too long."""
        if not data:
            raise JIDError("Domain must be given")
        data = data.rstrip(".")
        if not data:
            raise JIDError("Domain must be given")
        if '[' in data:
            if data[0] == '[' and data[-1] == ']':
                try:
                    # decode...
                    addr = socket.inet_pton(socket.AF_INET6, data[1:-1])
                    # ...and normalize
                    return "[{0}]".format(
                                    socket.inet_ntop(socket.AF_INET6, addr))
                except socket.error:
                    raise JIDError("Invalid IPv6 literal in JID domainpart")
            else:
                raise JIDError("Invalid use of '[' or ']' in JID domainpart")
        elif data[0].isdigit() and data[-1].isdigit():
            try:
                # try to decode as IPv4...
                addr = socket.inet_pton(socket.AF_INET, data)
                # ...and normalize
                return socket.inet_ntop(socket.AF_INET, addr)
            except socket.error:
                pass
        data = str(data)
        labels = data.split(".")
        labels = [idna.nameprep(label) for label in labels]
        domain = ".".join(labels)
        if len(domain.encode("utf-8")) > 1023:
            raise JIDError("Domain name too long")
        return domain 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:43,代码来源:jid.py


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