本文整理汇总了Python中twisted.names.dns.Message方法的典型用法代码示例。如果您正苦于以下问题:Python dns.Message方法的具体用法?Python dns.Message怎么用?Python dns.Message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.names.dns
的用法示例。
在下文中一共展示了dns.Message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_messageReceivedAllowQuery
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_messageReceivedAllowQuery(self):
"""
L{server.DNSServerFactory.messageReceived} passes all messages to
L{server.DNSServerFactory.allowQuery} along with the receiving protocol
and origin address.
"""
message = dns.Message()
dummyProtocol = object()
dummyAddress = object()
f = RaisingDNSServerFactory()
e = self.assertRaises(
RaisingDNSServerFactory.AllowQueryArguments,
f.messageReceived,
message=message, proto=dummyProtocol, address=dummyAddress)
args, kwargs = e.args
self.assertEqual(args, (message, dummyProtocol, dummyAddress))
self.assertEqual(kwargs, {})
示例2: test_allowQueryFalse
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_allowQueryFalse(self):
"""
If C{allowQuery} returns C{False},
L{server.DNSServerFactory.messageReceived} calls L{server.sendReply}
with a message whose C{rCode} is L{dns.EREFUSED}.
"""
class SendReplyException(Exception):
pass
class RaisingDNSServerFactory(server.DNSServerFactory):
def allowQuery(self, *args, **kwargs):
return False
def sendReply(self, *args, **kwargs):
raise SendReplyException(args, kwargs)
f = RaisingDNSServerFactory()
e = self.assertRaises(
SendReplyException,
f.messageReceived,
message=dns.Message(), proto=None, address=None)
(proto, message, address), kwargs = e.args
self.assertEqual(message.rCode, dns.EREFUSED)
示例3: test_handleQuery
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_handleQuery(self):
"""
L{server.DNSServerFactory.handleQuery} takes the first query from the
supplied message and dispatches it to
L{server.DNSServerFactory.resolver.query}.
"""
m = dns.Message()
m.addQuery(b'one.example.com')
m.addQuery(b'two.example.com')
f = server.DNSServerFactory()
f.resolver = RaisingResolver()
e = self.assertRaises(
RaisingResolver.QueryArguments,
f.handleQuery,
message=m, protocol=NoopProtocol(), address=None)
(query,), kwargs = e.args
self.assertEqual(query, m.queries[0])
示例4: test_gotResolverResponse
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_gotResolverResponse(self):
"""
L{server.DNSServerFactory.gotResolverResponse} accepts a tuple of
resource record lists and triggers a response message containing those
resource record lists.
"""
f = server.DNSServerFactory()
answers = []
authority = []
additional = []
e = self.assertRaises(
RaisingProtocol.WriteMessageArguments,
f.gotResolverResponse,
(answers, authority, additional),
protocol=RaisingProtocol(), message=dns.Message(), address=None)
(message,), kwargs = e.args
self.assertIs(message.answers, answers)
self.assertIs(message.authority, authority)
self.assertIs(message.additional, additional)
示例5: test_gotResolverResponseCallsResponseFromMessage
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_gotResolverResponseCallsResponseFromMessage(self):
"""
L{server.DNSServerFactory.gotResolverResponse} calls
L{server.DNSServerFactory._responseFromMessage} to generate a response.
"""
factory = NoResponseDNSServerFactory()
factory._responseFromMessage = raiser
request = dns.Message()
request.timeReceived = 1
e = self.assertRaises(
RaisedArguments,
factory.gotResolverResponse,
([], [], []),
protocol=None, message=request, address=None
)
self.assertEqual(
((), dict(message=request, rCode=dns.OK,
answers=[], authority=[], additional=[])),
(e.args, e.kwargs)
)
示例6: test_responseFromMessageRecursionAvailable
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_responseFromMessageRecursionAvailable(self):
"""
L{server.DNSServerFactory._responseFromMessage} generates a response
message whose C{recAV} attribute is L{True} if
L{server.DNSServerFactory.canRecurse} is L{True}.
"""
factory = server.DNSServerFactory()
factory.canRecurse = True
response1 = factory._responseFromMessage(
message=dns.Message(recAv=False))
factory.canRecurse = False
response2 = factory._responseFromMessage(
message=dns.Message(recAv=True))
self.assertEqual(
(True, False),
(response1.recAv, response2.recAv))
示例7: test_responseFromMessageCallsMessageFactory
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_responseFromMessageCallsMessageFactory(self):
"""
L{server.DNSServerFactory._responseFromMessage} calls
C{dns._responseFromMessage} to generate a response
message from the request message. It supplies the request message and
other keyword arguments which should be passed to the response message
initialiser.
"""
factory = server.DNSServerFactory()
self.patch(dns, '_responseFromMessage', raiser)
request = dns.Message()
e = self.assertRaises(
RaisedArguments,
factory._responseFromMessage,
message=request, rCode=dns.OK
)
self.assertEqual(
((), dict(responseConstructor=factory._messageFactory,
message=request, rCode=dns.OK, recAv=factory.canRecurse,
auth=False)),
(e.args, e.kwargs)
)
示例8: test_gotResolverResponseLogging
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_gotResolverResponseLogging(self):
"""
L{server.DNSServerFactory.gotResolverResponse} logs the total number of
records in the response if C{verbose > 0}.
"""
f = NoResponseDNSServerFactory(verbose=1)
answers = [dns.RRHeader()]
authority = [dns.RRHeader()]
additional = [dns.RRHeader()]
assertLogMessage(
self,
["Lookup found 3 records"],
f.gotResolverResponse,
(answers, authority, additional),
protocol=NoopProtocol(), message=dns.Message(), address=None)
示例9: test_gotResolverResponseCaching
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_gotResolverResponseCaching(self):
"""
L{server.DNSServerFactory.gotResolverResponse} caches the response if at
least one cache was provided in the constructor.
"""
f = NoResponseDNSServerFactory(caches=[RaisingCache()])
m = dns.Message()
m.addQuery(b'example.com')
expectedAnswers = [dns.RRHeader()]
expectedAuthority = []
expectedAdditional = []
e = self.assertRaises(
RaisingCache.CacheResultArguments,
f.gotResolverResponse,
(expectedAnswers, expectedAuthority, expectedAdditional),
protocol=NoopProtocol(), message=m, address=None)
(query, (answers, authority, additional)), kwargs = e.args
self.assertEqual(query.name.name, b'example.com')
self.assertIs(answers, expectedAnswers)
self.assertIs(authority, expectedAuthority)
self.assertIs(additional, expectedAdditional)
示例10: _assertMessageRcodeForError
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def _assertMessageRcodeForError(self, responseError, expectedMessageCode):
"""
L{server.DNSServerFactory.gotResolver} accepts a L{failure.Failure} and
triggers a response message whose rCode corresponds to the DNS error
contained in the C{Failure}.
@param responseError: The L{Exception} instance which is expected to
trigger C{expectedMessageCode} when it is supplied to
C{gotResolverError}
@type responseError: L{Exception}
@param expectedMessageCode: The C{rCode} which is expected in the
message returned by C{gotResolverError} in response to
C{responseError}.
@type expectedMessageCode: L{int}
"""
f = server.DNSServerFactory()
e = self.assertRaises(
RaisingProtocol.WriteMessageArguments,
f.gotResolverError,
failure.Failure(responseError),
protocol=RaisingProtocol(), message=dns.Message(), address=None)
(message,), kwargs = e.args
self.assertEqual(message.rCode, expectedMessageCode)
示例11: test_gotResolverErrorResetsResponseAttributes
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_gotResolverErrorResetsResponseAttributes(self):
"""
L{server.DNSServerFactory.gotResolverError} does not allow request
attributes to leak into the response ie it sends a response with AD, CD
set to 0 and empty response record sections.
"""
factory = server.DNSServerFactory()
responses = []
factory.sendReply = (
lambda protocol, response, address: responses.append(response)
)
request = dns.Message(authenticData=True, checkingDisabled=True)
request.answers = [object(), object()]
request.authority = [object(), object()]
request.additional = [object(), object()]
factory.gotResolverError(
failure.Failure(error.DomainError()),
protocol=None, message=request, address=None
)
self.assertEqual([dns.Message(rCode=3, answer=True)], responses)
示例12: test_gotResolverResponseResetsResponseAttributes
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_gotResolverResponseResetsResponseAttributes(self):
"""
L{server.DNSServerFactory.gotResolverResponse} does not allow request
attributes to leak into the response ie it sends a response with AD, CD
set to 0 and none of the records in the request answer sections are
copied to the response.
"""
factory = server.DNSServerFactory()
responses = []
factory.sendReply = (
lambda protocol, response, address: responses.append(response)
)
request = dns.Message(authenticData=True, checkingDisabled=True)
request.answers = [object(), object()]
request.authority = [object(), object()]
request.additional = [object(), object()]
factory.gotResolverResponse(
([], [], []),
protocol=None, message=request, address=None
)
self.assertEqual([dns.Message(rCode=0, answer=True)], responses)
示例13: test_sendReplyWithAddress
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_sendReplyWithAddress(self):
"""
If L{server.DNSServerFactory.sendReply} is supplied with a protocol
*and* an address tuple it will supply that address to
C{protocol.writeMessage}.
"""
m = dns.Message()
dummyAddress = object()
f = server.DNSServerFactory()
e = self.assertRaises(
RaisingProtocol.WriteMessageArguments,
f.sendReply,
protocol=RaisingProtocol(),
message=m,
address=dummyAddress)
args, kwargs = e.args
self.assertEqual(args, (m, dummyAddress))
self.assertEqual(kwargs, {})
示例14: test_sendReplyLoggingNoAnswers
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_sendReplyLoggingNoAnswers(self):
"""
If L{server.DNSServerFactory.sendReply} logs a "no answers" message if
the supplied message has no answers.
"""
self.patch(server.time, 'time', lambda: 2)
m = dns.Message()
m.timeReceived = 1
f = server.DNSServerFactory(verbose=2)
assertLogMessage(
self,
["Replying with no answers", "Processed query in 1.000 seconds"],
f.sendReply,
protocol=NoopProtocol(),
message=m,
address=None)
示例15: test_sendReplyLoggingWithAnswers
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import Message [as 别名]
def test_sendReplyLoggingWithAnswers(self):
"""
If L{server.DNSServerFactory.sendReply} logs a message for answers,
authority, additional if the supplied a message has records in any of
those sections.
"""
self.patch(server.time, 'time', lambda: 2)
m = dns.Message()
m.answers.append(dns.RRHeader(payload=dns.Record_A('127.0.0.1')))
m.authority.append(dns.RRHeader(payload=dns.Record_A('127.0.0.1')))
m.additional.append(dns.RRHeader(payload=dns.Record_A('127.0.0.1')))
m.timeReceived = 1
f = server.DNSServerFactory(verbose=2)
assertLogMessage(
self,
['Answers are <A address=127.0.0.1 ttl=None>',
'Authority is <A address=127.0.0.1 ttl=None>',
'Additional is <A address=127.0.0.1 ttl=None>',
'Processed query in 1.000 seconds'],
f.sendReply,
protocol=NoopProtocol(),
message=m,
address=None)