From 5bceca16a98a6b5651fd6d25222603e49f3c78fb Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Llobregat Date: Tue, 18 Jun 2024 21:39:41 +0200 Subject: [PATCH] pep8 corrections made Codeclimate marks (wrongly) similarities in two completely different methods. --- tlslite/api.py | 6 +-- tlslite/integration/__init__.py | 2 +- .../integration/tlsasynciodispatchermixin.py | 49 ++++++++++++------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/tlslite/api.py b/tlslite/api.py index d0104f7d..589bdb52 100644 --- a/tlslite/api.py +++ b/tlslite/api.py @@ -35,9 +35,9 @@ try: from .integration.tlsasyncdispatchermixin import TLSAsyncDispatcherMixIn except ImportError: - # NOTE: Left this try-except block as is, due to the possibility to use both - # asyncore and asyncio in the same project no matter the python version (if the - # asyncore module is available). + # NOTE: Left this try-except block as is, due to the possibility to use + # both asyncore and asyncio in the same project no matter the python + # version (if the asyncore module is available). pass from .integration.pop3_tls import POP3_TLS diff --git a/tlslite/integration/__init__.py b/tlslite/integration/__init__.py index f071d7fd..9b3f4076 100644 --- a/tlslite/integration/__init__.py +++ b/tlslite/integration/__init__.py @@ -11,4 +11,4 @@ "xmlrpctransport", "tlssocketservermixin", "tlsasyncdispatchermixin", - "tlsasynciodispatchermixin"] \ No newline at end of file + "tlsasynciodispatchermixin"] diff --git a/tlslite/integration/tlsasynciodispatchermixin.py b/tlslite/integration/tlsasynciodispatchermixin.py index ac6bde4e..2df7a07e 100644 --- a/tlslite/integration/tlsasynciodispatchermixin.py +++ b/tlslite/integration/tlsasynciodispatchermixin.py @@ -12,33 +12,42 @@ class TLSAsyncioDispatcherMixIn(asyncio.Protocol): """ - This class can be "mixed in" with an :py:class:`asyncio.Protocol` to add TLS support. + This class can be "mixed in" with an :py:class:`asyncio.Protocol` + to add TLS support. - This class essentially sits between the protocol and the asyncio event loop, intercepting events and only + This class essentially sits between the protocol and the asyncio + event loop, intercepting events and only calling the protocol when applicable. - In the case of :py:meth:`data_received`, a read operation will be activated, and when it completes, - the bytes will be placed in a buffer where the protocol can retrieve them by calling :py:meth:`recv`, + In the case of :py:meth:`data_received`, a read operation will be + activated, and when it completes, the bytes will be placed in a + buffer where the protocol can retrieve them by calling :py:meth:`recv`, and the protocol's :py:meth:`data_received` will be called. - In the case of :py:meth:`send`, the protocol's :py:meth:`send` will be called, and when it calls - :py:meth:`send`, a write operation will be activated. + In the case of :py:meth:`send`, the protocol's :py:meth:`send` will + be called, and when it calls :py:meth:`send`, a write operation + will be activated. - To use this class, you must combine it with an asyncio.Protocol, and pass in a handshake operation with - setServerHandshakeOp(). + To use this class, you must combine it with an asyncio.Protocol, and + pass in a handshake operation with setServerHandshakeOp(). - Below is an example of using this class with aiohttp. This class is mixed in with aiohttp's BaseProtocol to - create http_tls_protocol. Note: + Below is an example of using this class with aiohttp. This class + is mixed in with aiohttp's BaseProtocol to create http_tls_protocol. + + Note: 1. the mix-in is listed first in the inheritance list - 2. the input buffer size must be at least 16K, otherwise the protocol might not read all the bytes from the - TLS layer, leaving some bytes in limbo. + 2. the input buffer size must be at least 16K, otherwise the protocol + might not read all the bytes from the TLS layer, leaving some + bytes in limbo. - 3. IE seems to have a problem receiving a whole HTTP response in a single TLS record, so HTML pages - containing '\\r\\n\\r\\n' won't be displayed on IE. + 3. IE seems to have a problem receiving a whole HTTP response + in a single TLS record, so HTML pages containing + '\\r\\n\\r\\n' won't be displayed on IE. - Add the following text into 'start_aiohttp.py', in the 'HTTP Server' section:: + Add the following text into 'start_aiohttp.py', in the + 'HTTP Server' section:: from tlslite import * s = open("./serverX509Cert.pem").read() @@ -62,10 +71,12 @@ def __init__ (self, server, conn, addr): hs.protocol_class = http_tls_protocol - If the TLS layer raises an exception, the exception will be caught in asyncio.Protocol, which will call - :py:meth:`close` on this class. The TLS layer always closes the TLS connection before raising an exception, - so the close operation will complete right away, causing asyncio.Protocol.close() to be called, which closes - the socket and removes this instance from the asyncio event loop. + If the TLS layer raises an exception, the exception will be caught in + asyncio.Protocol, which will call :py:meth:`close` on this class. + The TLS layer always closes the TLS connection before raising an + exception, so the close operation will complete right away, causing + asyncio.Protocol.close() to be called, which closes the socket and + removes this instance from the asyncio event loop. """ def __init__(self, sock=None):