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