當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。