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


Python iostream.SSLIOStream方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def __init__(self, stream, address, protocol):
        self.address = address
        # Save the socket's address family now so we know how to
        # interpret self.address even after the stream is closed
        # and its socket attribute replaced with None.
        if stream.socket is not None:
            self.address_family = stream.socket.family
        else:
            self.address_family = None
        # In HTTPServerRequest we want an IP, not a full socket address.
        if (self.address_family in (socket.AF_INET, socket.AF_INET6) and
                address is not None):
            self.remote_ip = address[0]
        else:
            # Unix (or other) socket; fake the remote address.
            self.remote_ip = '0.0.0.0'
        if protocol:
            self.protocol = protocol
        elif isinstance(stream, iostream.SSLIOStream):
            self.protocol = "https"
        else:
            self.protocol = "http"
        self._orig_remote_ip = self.remote_ip
        self._orig_protocol = self.protocol 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:httpserver.py

示例2: test_large_read_until

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def test_large_read_until(self):
        # Performance test: read_until used to have a quadratic component
        # so a read_until of 4MB would take 8 seconds; now it takes 0.25
        # seconds.
        server, client = self.make_iostream_pair()
        try:
            # This test fails on pypy with ssl.  I think it's because
            # pypy's gc defeats moves objects, breaking the
            # "frozen write buffer" assumption.
            if (isinstance(server, SSLIOStream) and
                    platform.python_implementation() == 'PyPy'):
                raise unittest.SkipTest(
                    "pypy gc causes problems with openssl")
            NUM_KB = 4096
            for i in range(NUM_KB):
                client.write(b"A" * 1024)
            client.write(b"\r\n")
            server.read_until(b"\r\n", self.stop)
            data = self.wait()
            self.assertEqual(len(data), NUM_KB * 1024 + 2)
        finally:
            server.close()
            client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:25,代码来源:iostream_test.py

示例3: test_start_tls_smtp

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def test_start_tls_smtp(self):
        # This flow is simplified from RFC 3207 section 5.
        # We don't really need all of this, but it helps to make sure
        # that after realistic back-and-forth traffic the buffers end up
        # in a sane state.
        yield self.server_send_line(b"220 mail.example.com ready\r\n")
        yield self.client_send_line(b"EHLO mail.example.com\r\n")
        yield self.server_send_line(b"250-mail.example.com welcome\r\n")
        yield self.server_send_line(b"250 STARTTLS\r\n")
        yield self.client_send_line(b"STARTTLS\r\n")
        yield self.server_send_line(b"220 Go ahead\r\n")
        client_future = self.client_start_tls(dict(cert_reqs=ssl.CERT_NONE))
        server_future = self.server_start_tls(_server_ssl_options())
        self.client_stream = yield client_future
        self.server_stream = yield server_future
        self.assertTrue(isinstance(self.client_stream, SSLIOStream))
        self.assertTrue(isinstance(self.server_stream, SSLIOStream))
        yield self.client_send_line(b"EHLO mail.example.com\r\n")
        yield self.server_send_line(b"250 mail.example.com welcome\r\n") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:iostream_test.py

示例4: connect_to_server

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def connect_to_server(self, server_cls):
        server = client = None
        try:
            sock, port = bind_unused_port()
            server = server_cls(ssl_options=_server_ssl_options())
            server.add_socket(sock)

            client = SSLIOStream(socket.socket(),
                                 ssl_options=dict(cert_reqs=ssl.CERT_NONE))
            yield client.connect(('127.0.0.1', port))
            self.assertIsNotNone(client.socket.cipher())
        finally:
            if server is not None:
                server.stop()
            if client is not None:
                client.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:18,代码来源:iostream_test.py

示例5: __init__

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def __init__(self, stream, address, protocol, trusted_downstream=None):
        self.address = address
        # Save the socket's address family now so we know how to
        # interpret self.address even after the stream is closed
        # and its socket attribute replaced with None.
        if stream.socket is not None:
            self.address_family = stream.socket.family
        else:
            self.address_family = None
        # In HTTPServerRequest we want an IP, not a full socket address.
        if (self.address_family in (socket.AF_INET, socket.AF_INET6) and
                address is not None):
            self.remote_ip = address[0]
        else:
            # Unix (or other) socket; fake the remote address.
            self.remote_ip = '0.0.0.0'
        if protocol:
            self.protocol = protocol
        elif isinstance(stream, iostream.SSLIOStream):
            self.protocol = "https"
        else:
            self.protocol = "http"
        self._orig_remote_ip = self.remote_ip
        self._orig_protocol = self.protocol
        self.trusted_downstream = set(trusted_downstream or []) 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:httpserver.py

示例6: test_large_read_until

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def test_large_read_until(self):
        # Performance test: read_until used to have a quadratic component
        # so a read_until of 4MB would take 8 seconds; now it takes 0.25
        # seconds.
        rs, ws = yield self.make_iostream_pair()
        try:
            # This test fails on pypy with ssl.  I think it's because
            # pypy's gc defeats moves objects, breaking the
            # "frozen write buffer" assumption.
            if (isinstance(rs, SSLIOStream) and
                    platform.python_implementation() == 'PyPy'):
                raise unittest.SkipTest(
                    "pypy gc causes problems with openssl")
            NUM_KB = 4096
            for i in range(NUM_KB):
                ws.write(b"A" * 1024)
            ws.write(b"\r\n")
            data = yield rs.read_until(b"\r\n")
            self.assertEqual(len(data), NUM_KB * 1024 + 2)
        finally:
            ws.close()
            rs.close() 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:iostream_test.py

示例7: _create_connection

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def _create_connection(self, stream):
        can_http2 = False
        if isinstance(stream, SSLIOStream):
            assert stream.socket.cipher() is not None, 'handshake incomplete'
            proto = stream.socket.selected_alpn_protocol()
            if proto == constants.HTTP2_TLS:
                can_http2 = True
        elif self.client._use_http2_cleartext():
            can_http2 = True
        if can_http2:
            conn = Connection(stream, True,
                              Params(decompress=self.request.decompress_response))
            IOLoop.current().add_future(conn.start(None),
                                        lambda f: f.result())
            h2_stream = conn.create_stream(self)
            return h2_stream
        return super(_HTTP2ClientConnection, self)._create_connection(stream) 
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:19,代码来源:client.py

示例8: open

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def open(self, timeout=DEFAULT_CONNECT_TIMEOUT):
        logger.debug('socket connecting')
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        if self.ssl_options is None:
            self.stream = iostream.IOStream(sock)
        else:
            self.stream = iostream.SSLIOStream(
                sock, ssl_options=self.ssl_options)

        try:
            yield self.with_timeout(timeout, self.stream.connect(
                (self.host, self.port)))
        except (socket.error, OSError, IOError):
            message = 'could not connect to {}:{}'.format(self.host, self.port)
            raise TTransportException(
                type=TTransportException.NOT_OPEN,
                message=message)

        self._set_close_callback()
        raise gen.Return(self) 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:22,代码来源:tornado.py

示例9: _make_client_iostream

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def _make_client_iostream(self):
        return SSLIOStream(socket.socket(), io_loop=self.io_loop,
                           ssl_options=dict(cert_reqs=ssl.CERT_NONE)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:iostream_test.py

示例10: _make_server_iostream

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def _make_server_iostream(self, connection, **kwargs):
        connection = ssl.wrap_socket(connection,
                                     server_side=True,
                                     do_handshake_on_connect=False,
                                     **_server_ssl_options())
        return SSLIOStream(connection, io_loop=self.io_loop, **kwargs) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:iostream_test.py

示例11: _make_client_iostream

# 需要导入模块: from tornado import iostream [as 别名]
# 或者: from tornado.iostream import SSLIOStream [as 别名]
def _make_client_iostream(self, connection, **kwargs):
        return SSLIOStream(connection, io_loop=self.io_loop,
                           ssl_options=dict(cert_reqs=ssl.CERT_NONE),
                           **kwargs)


# This will run some tests that are basically redundant but it's the
# simplest way to make sure that it works to pass an SSLContext
# instead of an ssl_options dict to the SSLIOStream constructor. 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:iostream_test.py


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