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


Python dns.Name方法代码示例

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


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

示例1: _cbGotServers

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def _cbGotServers(self, result):
        answers, auth, add = result
        if len(answers) == 1 and answers[0].type == dns.SRV \
                             and answers[0].payload \
                             and answers[0].payload.target == dns.Name(b'.'):
            # decidedly not available
            raise error.DNSLookupError("Service %s not available for domain %s."
                                       % (repr(self.service), repr(self.domain)))

        self.servers = []
        self.orderedServers = []
        for a in answers:
            if a.type != dns.SRV or not a.payload:
                continue

            self.orderedServers.append(a.payload) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:srvconnect.py

示例2: test_resourceRecordHeader

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_resourceRecordHeader(self):
        """
        L{dns.RRHeader.encode} encodes the record header's information and
        writes it to the file-like object passed to it and
        L{dns.RRHeader.decode} reads from a file-like object to re-construct a
        L{dns.RRHeader} instance.
        """
        # encode the RR
        f = BytesIO()
        dns.RRHeader(b"test.org", 3, 4, 17).encode(f)

        # decode the result
        f.seek(0, 0)
        result = dns.RRHeader()
        result.decode(f)
        self.assertEqual(result.name, dns.Name(b"test.org"))
        self.assertEqual(result.type, 3)
        self.assertEqual(result.cls, 4)
        self.assertEqual(result.ttl, 17) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_dns.py

示例3: test_resources

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_resources(self):
        """
        L{dns.SimpleRecord.encode} encodes the record's name information and
        writes it to the file-like object passed to it and
        L{dns.SimpleRecord.decode} reads from a file-like object to re-construct
        a L{dns.SimpleRecord} instance.
        """
        names = (
            b"this.are.test.name",
            b"will.compress.will.this.will.name.will.hopefully",
            b"test.CASE.preSErVatIOn.YeAH",
            b"a.s.h.o.r.t.c.a.s.e.t.o.t.e.s.t",
            b"singleton"
        )
        for s in names:
            f = BytesIO()
            dns.SimpleRecord(s).encode(f)
            f.seek(0, 0)
            result = dns.SimpleRecord()
            result.decode(f)
            self.assertEqual(result.name, dns.Name(s)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_dns.py

示例4: _cbRecords

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def _cbRecords(self, records, name, effort):
        (ans, auth, add) = records
        result = extractRecord(self, dns.Name(name), ans + auth + add, effort)
        if not result:
            raise error.DNSLookupError(name)
        return result 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:common.py

示例5: test_nonStringName

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_nonStringName(self):
        """
        When constructed with a name which is neither C{bytes} nor C{str},
        L{Name} raises L{TypeError}.
        """
        self.assertRaises(TypeError, dns.Name, 123)
        self.assertRaises(TypeError, dns.Name, object())
        self.assertRaises(TypeError, dns.Name, []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_dns.py

示例6: test_unicodeName

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_unicodeName(self):
        """
        L{dns.Name} automatically encodes unicode domain name using C{idna}
        encoding.
        """
        name = dns.Name(u'\u00e9chec.example.org')
        self.assertIsInstance(name.name, bytes)
        self.assertEqual(b'xn--chec-9oa.example.org', name.name) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_dns.py

示例7: test_decode

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_decode(self):
        """
        L{Name.decode} populates the L{Name} instance with name information read
        from the file-like object passed to it.
        """
        n = dns.Name()
        n.decode(BytesIO(b"\x07example\x03com\x00"))
        self.assertEqual(n.name, b"example.com") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_dns.py

示例8: test_encodeWithCompression

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_encodeWithCompression(self):
        """
        If a compression dictionary is passed to it, L{Name.encode} uses offset
        information from it to encode its name with references to existing
        labels in the stream instead of including another copy of them in the
        output.  It also updates the compression dictionary with the location of
        the name it writes to the stream.
        """
        name = dns.Name(b"foo.example.com")
        compression = {b"example.com": 0x17}

        # Some bytes already encoded into the stream for this message
        previous = b"some prefix to change .tell()"
        stream = BytesIO()
        stream.write(previous)

        # The position at which the encoded form of this new name will appear in
        # the stream.
        expected = len(previous) + dns.Message.headerSize
        name.encode(stream, compression)
        self.assertEqual(
            b"\x03foo\xc0\x17",
            stream.getvalue()[len(previous):])
        self.assertEqual(
            {b"example.com": 0x17, b"foo.example.com": expected},
            compression) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:28,代码来源:test_dns.py

示例9: test_decodeWithCompression

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_decodeWithCompression(self):
        """
        If the leading byte of an encoded label (in bytes read from a stream
        passed to L{Name.decode}) has its two high bits set, the next byte is
        treated as a pointer to another label in the stream and that label is
        included in the name being decoded.
        """
        # Slightly modified version of the example from RFC 1035, section 4.1.4.
        stream = BytesIO(
            b"x" * 20 +
            b"\x01f\x03isi\x04arpa\x00"
            b"\x03foo\xc0\x14"
            b"\x03bar\xc0\x20")
        stream.seek(20)
        name = dns.Name()
        name.decode(stream)
        # Verify we found the first name in the stream and that the stream
        # position is left at the first byte after the decoded name.
        self.assertEqual(b"f.isi.arpa", name.name)
        self.assertEqual(32, stream.tell())

        # Get the second name from the stream and make the same assertions.
        name.decode(stream)
        self.assertEqual(name.name, b"foo.f.isi.arpa")
        self.assertEqual(38, stream.tell())

        # Get the third and final name
        name.decode(stream)
        self.assertEqual(name.name, b"bar.foo.f.isi.arpa")
        self.assertEqual(44, stream.tell()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:32,代码来源:test_dns.py

示例10: test_rejectCompressionLoop

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_rejectCompressionLoop(self):
        """
        L{Name.decode} raises L{ValueError} if the stream passed to it includes
        a compression pointer which forms a loop, causing the name to be
        undecodable.
        """
        name = dns.Name()
        stream = BytesIO(b"\xc0\x00")
        self.assertRaises(ValueError, name.decode, stream) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_dns.py

示例11: test_equality

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_equality(self):
        """
        L{Name} instances are equal as long as they have the same value for
        L{Name.name}, regardless of the case.
        """
        name1 = dns.Name(b"foo.bar")
        name2 = dns.Name(b"foo.bar")
        self.assertEqual(name1, name2)

        name3 = dns.Name(b"fOO.bar")
        self.assertEqual(name1, name3) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_dns.py

示例12: test_inequality

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_inequality(self):
        """
        L{Name} instances are not equal as long as they have different
        L{Name.name} attributes.
        """
        name1 = dns.Name(b"foo.bar")
        name2 = dns.Name(b"bar.foo")
        self.assertNotEqual(name1, name2) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_dns.py

示例13: test_name

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_name(self):
        """
        Two L{dns.Name} instances compare equal if and only if they have the
        same name value.
        """
        self._equalityTest(
            dns.Name(b'abc'), dns.Name(b'abc'), dns.Name(b'def')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_dns.py

示例14: test_nameReadonly

# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Name [as 别名]
def test_nameReadonly(self):
        """
        L{dns._OPTHeader.name} is readonly.
        """
        h = dns._OPTHeader()
        self.assertRaises(
            AttributeError, setattr, h, 'name', dns.Name(b'example.com')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_dns.py


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