commit 131ed04840bc002b8c6e50cd03465c0cbbff2aca Author: Damian Johnson atagar@torproject.org Date: Fri Jan 10 14:40:21 2020 -0800
Remove old buffer handling
Honestly I'm confused what isis was attempting to do here. This has something to do with old python version compatability so it's likely moot.
Python 3.x replaced buffer() with memoryview()...
https://stackoverflow.com/questions/50160187/buffer-function-for-python-3
... so we could likely could make that replacement. But instead lets try to simply rip this out.
Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/twisted/trial/runner.py", line 823, in loadByName return self.suiteFactory([self.findByName(name, recurse=recurse)]) ... File "/home/atagar/Desktop/tor/bridgedb/bridgedb/bridgerequest.py", line 27, in <module> from bridgedb.crypto import getHMACFunc File "/home/atagar/Desktop/tor/bridgedb/bridgedb/crypto.py", line 74, in <module> io.BytesIO(buffer('test')) builtins.NameError: name 'buffer' is not defined
This didn't change test outcome...
before: FAILED (skips=1, failures=7, errors=48, successes=256) after: FAILED (skips=1, failures=7, errors=48, successes=256) --- bridgedb/crypto.py | 20 -------------------- bridgedb/distributors/email/autoresponder.py | 15 ++------------- 2 files changed, 2 insertions(+), 33 deletions(-)
diff --git a/bridgedb/crypto.py b/bridgedb/crypto.py index ee9d099..b39c659 100644 --- a/bridgedb/crypto.py +++ b/bridgedb/crypto.py @@ -57,29 +57,9 @@ from Crypto.PublicKey import RSA from twisted.internet import ssl from twisted.python.procutils import which
- #: The hash digest to use for HMACs. DIGESTMOD = hashlib.sha1
-# Test to see if we have the old or new style buffer() interface. Trying -# to use an old-style buffer on Python2.7 prior to version 2.7.5 will produce: -# -# TypeError: 'buffer' does not have the buffer interface -# -#: ``True`` if we have the new-style `buffer`_ interface; ``False`` otherwise. -#: -#: .. _buffer: https://docs.python.org/2/c-api/buffer.html -NEW_BUFFER_INTERFACE = False -try: - io.BytesIO(buffer('test')) -except TypeError: # pragma: no cover - logging.warn( - "This Python version is too old! "\ - "It doesn't support new-style buffer interfaces: "\ - "https://mail.python.org/pipermail/python-dev/2010-October/104917.html") -else: - NEW_BUFFER_INTERFACE = True -
class PKCS1PaddingError(Exception): """Raised when there is a problem adding or removing PKCS#1 padding.""" diff --git a/bridgedb/distributors/email/autoresponder.py b/bridgedb/distributors/email/autoresponder.py index b00feeb..bc1c7b9 100644 --- a/bridgedb/distributors/email/autoresponder.py +++ b/bridgedb/distributors/email/autoresponder.py @@ -51,7 +51,6 @@ from twisted.python import failure from bridgedb import strings from bridgedb import metrics from bridgedb import safelog -from bridgedb.crypto import NEW_BUFFER_INTERFACE from bridgedb.distributors.email import dkim from bridgedb.distributors.email import request from bridgedb.distributors.email import templates @@ -183,22 +182,12 @@ class EmailResponse(object): the email.)
- :vartype _buff: :any:`unicode` or :any:`buffer` - :var _buff: Used internally to write lines for the response email into the - ``_mailfile``. The reason why both of these attributes have two - possible types is for the same Python-buggy reasons which require - :data:`~bridgedb.crypto.NEW_BUFFER_INTERFACE`. - :vartype mailfile: :class:`io.StringIO` or :class:`io.BytesIO` - :var mailfile: An in-memory file-like object for storing the formatted - headers and body of the response email. :var str delimiter: Delimiter between lines written to the :data:`mailfile`. :var bool closed: ``True`` if :meth:`close` has been called. :vartype to: :api:`twisted.mail.smtp.Address` :var to: The client's email address, to which this response should be sent. """ - _buff = buffer if NEW_BUFFER_INTERFACE else unicode - mailfile = io.BytesIO if NEW_BUFFER_INTERFACE else io.StringIO
def __init__(self, gpgSignFunc=None): """Create a response to an email we have recieved. @@ -212,7 +201,7 @@ class EmailResponse(object): obtaining a pre-configured **gpgSignFunc**. """ self.gpgSign = gpgSignFunc - self.mailfile = self.mailfile() + self.mailfile = io.StringIO() self.delimiter = '\n' self.closed = False self.to = None @@ -281,7 +270,7 @@ class EmailResponse(object): self.writelines(line) else: line += self.delimiter - self.mailfile.write(self._buff(line.encode('utf8'))) + self.mailfile.write(line.encode('utf8')) self.mailfile.flush()
def writelines(self, lines):