本文整理汇总了Python中twisted.python.log.removeObserver方法的典型用法代码示例。如果您正苦于以下问题:Python log.removeObserver方法的具体用法?Python log.removeObserver怎么用?Python log.removeObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.log
的用法示例。
在下文中一共展示了log.removeObserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_malformedHeaderCGI
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_malformedHeaderCGI(self):
"""
Check for the error message in the duplicated header
"""
cgiFilename = self.writeCGI(BROKEN_HEADER_CGI)
portnum = self.startServer(cgiFilename)
url = "http://localhost:%d/cgi" % (portnum,)
agent = client.Agent(reactor)
d = agent.request(b"GET", url)
d.addCallback(discardBody)
loggedMessages = []
def addMessage(eventDict):
loggedMessages.append(log.textFromEventDict(eventDict))
log.addObserver(addMessage)
self.addCleanup(log.removeObserver, addMessage)
def checkResponse(ignored):
self.assertIn("ignoring malformed CGI header: 'XYZ'",
loggedMessages)
d.addCallback(checkResponse)
return d
示例2: test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse(self):
"""
If the request passed to L{HTTP11ClientProtocol} finished generation
with an error after the L{HTTP11ClientProtocol}'s connection has been
lost, an error is logged that gives a non-confusing hint to user on what
went wrong.
"""
errors = []
log.addObserver(errors.append)
self.addCleanup(log.removeObserver, errors.append)
def check(ignore):
error = errors[0]
self.assertEqual(error[u'why'],
u'Error writing request, but not in valid state '
u'to finalize request: CONNECTION_LOST')
return self.test_connectionLostDuringRequestGeneration(
'errback').addCallback(check)
示例3: test_logStderr
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_logStderr(self):
"""
When the _errFlag is set to L{StandardErrorBehavior.LOG},
L{endpoints._WrapIProtocol} logs stderr (in childDataReceived).
"""
d = self.ep.connect(self.factory)
self.successResultOf(d)
wpp = self.reactor.processProtocol
log.addObserver(self._stdLog)
self.addCleanup(log.removeObserver, self._stdLog)
wpp.childDataReceived(2, b'stderr1')
self.assertEqual(self.eventLog['executable'], wpp.executable)
self.assertEqual(self.eventLog['data'], b'stderr1')
self.assertEqual(self.eventLog['protocol'], wpp.protocol)
self.assertIn(
'wrote stderr unhandled by',
log.textFromEventDict(self.eventLog))
示例4: test_quiet
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_quiet(self):
"""
L{TLSMemoryBIOFactory.doStart} and L{TLSMemoryBIOFactory.doStop} do
not log any messages.
"""
contextFactory = ServerTLSContext()
logs = []
logger = logs.append
log.addObserver(logger)
self.addCleanup(log.removeObserver, logger)
wrappedFactory = ServerFactory()
# Disable logging on the wrapped factory:
wrappedFactory.doStart = lambda: None
wrappedFactory.doStop = lambda: None
factory = TLSMemoryBIOFactory(contextFactory, False, wrappedFactory)
factory.doStart()
factory.doStop()
self.assertEqual(logs, [])
示例5: test_startLoggingTwice
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_startLoggingTwice(self):
"""
There are some obscure error conditions that can occur when logging is
started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
information.
"""
self._startLoggingCleanup()
# The bug is particular to the way that the t.p.log 'global' function
# handle stdout. If we use our own stream, the error doesn't occur. If
# we use our own LogPublisher, the error doesn't occur.
sys.stdout = StringIO()
def showError(eventDict):
if eventDict['isError']:
sys.__stdout__.write(eventDict['failure'].getTraceback())
log.addObserver(showError)
self.addCleanup(log.removeObserver, showError)
observer = log.startLogging(sys.stdout)
self.addCleanup(observer.stop)
# At this point, we expect that sys.stdout is a StdioOnnaStick object.
self.assertIsInstance(sys.stdout, LoggingFile)
fakeStdout = sys.stdout
observer = log.startLogging(sys.stdout)
self.assertIs(sys.stdout, fakeStdout)
示例6: test_failureLogger
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_failureLogger(self):
"""
The reason argument passed to log.err() appears in the report
generated by DefaultObserver.
"""
self.catcher = []
self.observer = self.catcher.append
log.addObserver(self.observer)
self.addCleanup(log.removeObserver, self.observer)
obs = log.DefaultObserver()
obs.stderr = StringIO()
obs.start()
self.addCleanup(obs.stop)
reason = "The reason."
log.err(Exception(), reason)
errors = self.flushLoggedErrors()
self.assertIn(reason, obs.stderr.getvalue())
self.assertEqual(len(errors), 1)
示例7: test_outputReceivedCompleteLine
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_outputReceivedCompleteLine(self):
"""
Getting a complete output line generates a log message.
"""
events = []
self.addCleanup(log.removeObserver, events.append)
log.addObserver(events.append)
self.pm.addProcess("foo", ["foo"])
# Schedule the process to start
self.pm.startService()
# Advance the reactor to start the process
self.reactor.advance(0)
self.assertIn("foo", self.pm.protocols)
# Long time passes
self.reactor.advance(self.pm.threshold)
# Process greets
self.pm.protocols["foo"].outReceived(b'hello world!\n')
self.assertEquals(len(events), 1)
message = events[0]['message']
self.assertEquals(message, tuple([u'[foo] hello world!']))
示例8: test_outputReceivedCompleteLineInvalidUTF8
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_outputReceivedCompleteLineInvalidUTF8(self):
"""
Getting invalid UTF-8 results in the repr of the raw message
"""
events = []
self.addCleanup(log.removeObserver, events.append)
log.addObserver(events.append)
self.pm.addProcess("foo", ["foo"])
# Schedule the process to start
self.pm.startService()
# Advance the reactor to start the process
self.reactor.advance(0)
self.assertIn("foo", self.pm.protocols)
# Long time passes
self.reactor.advance(self.pm.threshold)
# Process greets
self.pm.protocols["foo"].outReceived(b'\xffhello world!\n')
self.assertEquals(len(events), 1)
messages = events[0]['message']
self.assertEquals(len(messages), 1)
message = messages[0]
tag, output = message.split(' ', 1)
self.assertEquals(tag, '[foo]')
self.assertEquals(output, repr(b'\xffhello world!'))
示例9: test_outputReceivedPartialLine
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_outputReceivedPartialLine(self):
"""
Getting partial line results in no events until process end
"""
events = []
self.addCleanup(log.removeObserver, events.append)
log.addObserver(events.append)
self.pm.addProcess("foo", ["foo"])
# Schedule the process to start
self.pm.startService()
# Advance the reactor to start the process
self.reactor.advance(0)
self.assertIn("foo", self.pm.protocols)
# Long time passes
self.reactor.advance(self.pm.threshold)
# Process greets
self.pm.protocols["foo"].outReceived(b'hello world!')
self.assertEquals(len(events), 0)
self.pm.protocols["foo"].processEnded(Failure(ProcessDone(0)))
self.assertEquals(len(events), 1)
message = events[0]['message']
self.assertEquals(message, tuple([u'[foo] hello world!']))
示例10: test_startStopObserver
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_startStopObserver(self):
"""
Test that start and stop methods of the observer actually register
and unregister to the log system.
"""
oldAddObserver = log.addObserver
oldRemoveObserver = log.removeObserver
l = []
try:
log.addObserver = l.append
log.removeObserver = l.remove
obs = log.PythonLoggingObserver()
obs.start()
self.assertEqual(l[0], obs.emit)
obs.stop()
self.assertEqual(len(l), 0)
finally:
log.addObserver = oldAddObserver
log.removeObserver = oldRemoveObserver
示例11: test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_errorMessageOnConnectionLostBeforeGenerationFailedDoesNotConfuse(self):
"""
If the request passed to L{HTTP11ClientProtocol} finished generation
with an error after the L{HTTP11ClientProtocol}'s connection has been
lost, an error is logged that gives a non-confusing hint to user on what
went wrong.
"""
errors = []
log.addObserver(errors.append)
self.addCleanup(log.removeObserver, errors.append)
def check(ignore):
error = errors[0]
self.assertEquals(error['why'],
'Error writing request, but not in valid state '
'to finalize request: CONNECTION_LOST')
return self.test_connectionLostDuringRequestGeneration(
'errback').addCallback(check)
示例12: test_stop
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_stop(self):
"""
L{app.AppLogger.stop} removes the observer created in C{start}, and
reinitialize its C{_observer} so that if C{stop} is called several
times it doesn't break.
"""
removed = []
observer = object()
def remove(observer):
removed.append(observer)
self.patch(log, 'removeObserver', remove)
logger = app.AppLogger({})
logger._observer = observer
logger.stop()
self.assertEquals(removed, [observer])
logger.stop()
self.assertEquals(removed, [observer])
self.assertIdentical(logger._observer, None)
示例13: test_startLoggingTwice
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_startLoggingTwice(self):
"""
There are some obscure error conditions that can occur when logging is
started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
information.
"""
# The bug is particular to the way that the t.p.log 'global' function
# handle stdout. If we use our own stream, the error doesn't occur. If
# we use our own LogPublisher, the error doesn't occur.
sys.stdout = StringIO()
self.addCleanup(setattr, sys, 'stdout', sys.__stdout__)
def showError(eventDict):
if eventDict['isError']:
sys.__stdout__.write(eventDict['failure'].getTraceback())
log.addObserver(showError)
self.addCleanup(log.removeObserver, showError)
observer = log.startLogging(sys.stdout)
self.addCleanup(observer.stop)
# At this point, we expect that sys.stdout is a StdioOnnaStick object.
self.assertIsInstance(sys.stdout, log.StdioOnnaStick)
fakeStdout = sys.stdout
observer = log.startLogging(sys.stdout)
self.assertIdentical(sys.stdout, fakeStdout)
示例14: test_startStopObserver
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_startStopObserver(self):
"""
Test that start and stop methods of the observer actually register
and unregister to the log system.
"""
oldAddObserver = log.addObserver
oldRemoveObserver = log.removeObserver
l = []
try:
log.addObserver = l.append
log.removeObserver = l.remove
obs = log.PythonLoggingObserver()
obs.start()
self.assertEquals(l[0], obs.emit)
obs.stop()
self.assertEquals(len(l), 0)
finally:
log.addObserver = oldAddObserver
log.removeObserver = oldRemoveObserver
示例15: test_wsgiErrors
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import removeObserver [as 别名]
def test_wsgiErrors(self):
"""
The C{'wsgi.errors'} key of the C{environ} C{dict} passed to the
application is a file-like object (as defined in the U{Input and Errors
Streams<http://www.python.org/dev/peps/pep-0333/#input-and-error-streams>}
section of PEP 333) which converts bytes written to it into events for
the logging system.
"""
events = []
addObserver(events.append)
self.addCleanup(removeObserver, events.append)
errors = self.render('GET', '1.1', [], [''])
def cbErrors(result):
environ, startApplication = result
errors = environ['wsgi.errors']
errors.write('some message\n')
errors.writelines(['another\nmessage\n'])
errors.flush()
self.assertEqual(events[0]['message'], ('some message\n',))
self.assertEqual(events[0]['system'], 'wsgi')
self.assertTrue(events[0]['isError'])
self.assertEqual(events[1]['message'], ('another\nmessage\n',))
self.assertEqual(events[1]['system'], 'wsgi')
self.assertTrue(events[1]['isError'])
self.assertEqual(len(events), 2)
errors.addCallback(cbErrors)
return errors