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


Python log.gen_log方法代码示例

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


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

示例1: test_connection_refused

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_connection_refused(self):
        # When a connection is refused, the connect callback should not
        # be run.  (The kqueue IOLoop used to behave differently from the
        # epoll IOLoop in this respect)
        cleanup_func, port = refusing_port()
        self.addCleanup(cleanup_func)
        stream = IOStream(socket.socket(), self.io_loop)
        self.connect_called = False

        def connect_callback():
            self.connect_called = True
            self.stop()
        stream.set_close_callback(self.stop)
        # log messages vary by platform and ioloop implementation
        with ExpectLog(gen_log, ".*", required=False):
            stream.connect(("127.0.0.1", port), connect_callback)
            self.wait()
        self.assertFalse(self.connect_called)
        self.assertTrue(isinstance(stream.error, socket.error), stream.error)
        if sys.platform != 'cygwin':
            _ERRNO_CONNREFUSED = (errno.ECONNREFUSED,)
            if hasattr(errno, "WSAECONNREFUSED"):
                _ERRNO_CONNREFUSED += (errno.WSAECONNREFUSED,)
            # cygwin's errnos don't match those used on native windows python
            self.assertTrue(stream.error.args[0] in _ERRNO_CONNREFUSED) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:27,代码来源:iostream_test.py

示例2: test_async_read_error_logging

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_async_read_error_logging(self):
        # Socket errors on asynchronous reads should be logged (but only
        # once).
        server, client = self.make_iostream_pair()
        server.set_close_callback(self.stop)
        try:
            # Start a read that will be fulfilled asynchronously.
            server.read_bytes(1, lambda data: None)
            client.write(b'a')
            # Stub out read_from_fd to make it fail.

            def fake_read_from_fd():
                os.close(server.socket.fileno())
                server.__class__.read_from_fd(server)
            server.read_from_fd = fake_read_from_fd
            # This log message is from _handle_read (not read_from_fd).
            with ExpectLog(gen_log, "error on read"):
                self.wait()
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:23,代码来源:iostream_test.py

示例3: test_read_until_regex_max_bytes_inline

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_read_until_regex_max_bytes_inline(self):
        server, client = self.make_iostream_pair()
        client.set_close_callback(lambda: self.stop("closed"))
        try:
            # Similar to the error case in the previous test, but the
            # server writes first so client reads are satisfied
            # inline.  For consistency with the out-of-line case, we
            # do not raise the error synchronously.
            server.write(b"123456")
            with ExpectLog(gen_log, "Unsatisfiable read"):
                client.read_until_regex(b"def", self.stop, max_bytes=5)
                data = self.wait()
            self.assertEqual(data, "closed")
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:18,代码来源:iostream_test.py

示例4: test_connection_refused

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_connection_refused(self):
        cleanup_func, port = refusing_port()
        self.addCleanup(cleanup_func)
        with ExpectLog(gen_log, ".*", required=False):
            self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop)
            response = self.wait()
        self.assertEqual(599, response.code)

        if sys.platform != 'cygwin':
            # cygwin returns EPERM instead of ECONNREFUSED here
            contains_errno = str(errno.ECONNREFUSED) in str(response.error)
            if not contains_errno and hasattr(errno, "WSAECONNREFUSED"):
                contains_errno = str(errno.WSAECONNREFUSED) in str(response.error)
            self.assertTrue(contains_errno, response.error)
            # This is usually "Connection refused".
            # On windows, strerror is broken and returns "Unknown error".
            expected_message = os.strerror(errno.ECONNREFUSED)
            self.assertTrue(expected_message in str(response.error),
                            response.error) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:simple_httpclient_test.py

示例5: test_cross_user

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_cross_user(self):
        token2 = self.get_token()
        # Each token can be used to authenticate its own request.
        for token in (self.xsrf_token, token2):
            response = self.fetch(
                "/", method="POST",
                body=urllib_parse.urlencode(dict(_xsrf=token)),
                headers=self.cookie_headers(token))
            self.assertEqual(response.code, 200)
        # Sending one in the cookie and the other in the body is not allowed.
        for cookie_token, body_token in ((self.xsrf_token, token2),
                                         (token2, self.xsrf_token)):
            with ExpectLog(gen_log, '.*XSRF cookie does not match POST'):
                response = self.fetch(
                    "/", method="POST",
                    body=urllib_parse.urlencode(dict(_xsrf=body_token)),
                    headers=self.cookie_headers(cookie_token))
            self.assertEqual(response.code, 403) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:web_test.py

示例6: test_websocket_network_fail

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_websocket_network_fail(self):
        sock, port = bind_unused_port()
        sock.close()
        with self.assertRaises(IOError):
            with ExpectLog(gen_log, ".*"):
                yield websocket_connect(
                    'ws://127.0.0.1:%d/' % port,
                    io_loop=self.io_loop,
                    connect_timeout=3600) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:websocket_test.py

示例7: test_gaierror

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_gaierror(self):
        # Test that IOStream sets its exc_info on getaddrinfo error.
        # It's difficult to reliably trigger a getaddrinfo error;
        # some resolvers own't even return errors for malformed names,
        # so we mock it instead. If IOStream changes to call a Resolver
        # before sock.connect, the mock target will need to change too.
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        stream = IOStream(s, io_loop=self.io_loop)
        stream.set_close_callback(self.stop)
        with mock.patch('socket.socket.connect',
                        side_effect=socket.gaierror('boom')):
            with ExpectLog(gen_log, "Connect error"):
                stream.connect(('localhost', 80), callback=self.stop)
                self.wait()
                self.assertIsInstance(stream.error, socket.gaierror) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:iostream_test.py

示例8: test_read_until_max_bytes

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_read_until_max_bytes(self):
        server, client = self.make_iostream_pair()
        client.set_close_callback(lambda: self.stop("closed"))
        try:
            # Extra room under the limit
            client.read_until(b"def", self.stop, max_bytes=50)
            server.write(b"abcdef")
            data = self.wait()
            self.assertEqual(data, b"abcdef")

            # Just enough space
            client.read_until(b"def", self.stop, max_bytes=6)
            server.write(b"abcdef")
            data = self.wait()
            self.assertEqual(data, b"abcdef")

            # Not enough space, but we don't know it until all we can do is
            # log a warning and close the connection.
            with ExpectLog(gen_log, "Unsatisfiable read"):
                client.read_until(b"def", self.stop, max_bytes=5)
                server.write(b"123456")
                data = self.wait()
            self.assertEqual(data, "closed")
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:28,代码来源:iostream_test.py

示例9: test_read_until_max_bytes_ignores_extra

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_read_until_max_bytes_ignores_extra(self):
        server, client = self.make_iostream_pair()
        client.set_close_callback(lambda: self.stop("closed"))
        try:
            # Even though data that matches arrives the same packet that
            # puts us over the limit, we fail the request because it was not
            # found within the limit.
            server.write(b"abcdef")
            with ExpectLog(gen_log, "Unsatisfiable read"):
                client.read_until(b"def", self.stop, max_bytes=5)
                data = self.wait()
            self.assertEqual(data, "closed")
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:iostream_test.py

示例10: test_read_until_regex_max_bytes

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_read_until_regex_max_bytes(self):
        server, client = self.make_iostream_pair()
        client.set_close_callback(lambda: self.stop("closed"))
        try:
            # Extra room under the limit
            client.read_until_regex(b"def", self.stop, max_bytes=50)
            server.write(b"abcdef")
            data = self.wait()
            self.assertEqual(data, b"abcdef")

            # Just enough space
            client.read_until_regex(b"def", self.stop, max_bytes=6)
            server.write(b"abcdef")
            data = self.wait()
            self.assertEqual(data, b"abcdef")

            # Not enough space, but we don't know it until all we can do is
            # log a warning and close the connection.
            with ExpectLog(gen_log, "Unsatisfiable read"):
                client.read_until_regex(b"def", self.stop, max_bytes=5)
                server.write(b"123456")
                data = self.wait()
            self.assertEqual(data, "closed")
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:28,代码来源:iostream_test.py

示例11: test_read_until_regex_max_bytes_ignores_extra

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_read_until_regex_max_bytes_ignores_extra(self):
        server, client = self.make_iostream_pair()
        client.set_close_callback(lambda: self.stop("closed"))
        try:
            # Even though data that matches arrives the same packet that
            # puts us over the limit, we fail the request because it was not
            # found within the limit.
            server.write(b"abcdef")
            with ExpectLog(gen_log, "Unsatisfiable read"):
                client.read_until_regex(b"def", self.stop, max_bytes=5)
                data = self.wait()
            self.assertEqual(data, "closed")
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:iostream_test.py

示例12: test_handshake_fail

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_handshake_fail(self):
        server_future = self.server_start_tls(_server_ssl_options())
        # Certificates are verified with the default configuration.
        client_future = self.client_start_tls(server_hostname="localhost")
        with ExpectLog(gen_log, "SSL Error"):
            with self.assertRaises(ssl.SSLError):
                yield client_future
        with self.assertRaises((ssl.SSLError, socket.error)):
            yield server_future 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:iostream_test.py

示例13: test_twitter_show_user_error

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_twitter_show_user_error(self):
        with ExpectLog(gen_log, 'Error response HTTP 500'):
            response = self.fetch('/twitter/client/show_user?name=error')
        self.assertEqual(response.code, 500)
        self.assertEqual(response.body, b'error from twitter request') 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:auth_test.py

示例14: test_no_content

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_no_content(self):
        response = self.fetch("/no_content")
        self.assertEqual(response.code, 204)
        # 204 status doesn't need a content-length, but tornado will
        # add a zero content-length anyway.
        #
        # A test without a content-length header is included below
        # in HTTP204NoContentTestCase.
        self.assertEqual(response.headers["Content-length"], "0")

        # 204 status with non-zero content length is malformed
        with ExpectLog(gen_log, "Malformed HTTP message"):
            response = self.fetch("/no_content?error=1")
        self.assertEqual(response.code, 599) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:16,代码来源:simple_httpclient_test.py

示例15: test_ssl_options_handshake_fail

# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import gen_log [as 别名]
def test_ssl_options_handshake_fail(self):
        with ExpectLog(gen_log, "SSL Error|Uncaught exception",
                       required=False):
            resp = self.fetch(
                "/hello", ssl_options=dict(cert_reqs=ssl.CERT_REQUIRED))
        self.assertRaises(ssl.SSLError, resp.rethrow) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:simple_httpclient_test.py


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