-
Notifications
You must be signed in to change notification settings - Fork 117
Create PY2 constant to simplify compatibility decisions #82
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,23 @@ | |
import rsa | ||
import rsa.cli | ||
import rsa.util | ||
from rsa._compat import PY2 | ||
|
||
if sys.version_info[0] < 3: | ||
def make_buffer(): | ||
|
||
def make_buffer(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmm now that I see how it turns out, I have some doubts about doing the if PY3:
def write_to_stdout(data): ...
def make_buffer(): ...
else:
def write_to_stdout(data): ...
def make_buffer(): ... we only need to evaluate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to prioritize readability and In my opinion, those advantages will make devs to save a lot more time when trying to contribute to the project or follow a stack trace than one more comparison per call will ever provide. Does that make any sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense, and I agree that readability is very important. However, I'm also curious as to the runtime performance impact. Do you have time to do some timing tests with some large key generation and file encryption? |
||
if PY2: | ||
return BytesIO() | ||
buf = StringIO() | ||
buf.buffer = BytesIO() | ||
return buf | ||
|
||
|
||
def get_bytes_out(out): | ||
# Python 2.x writes 'str' to stdout: | ||
def get_bytes_out(out): | ||
if PY2: | ||
# Python 2.x writes 'str' to stdout | ||
return out.getvalue() | ||
else: | ||
def make_buffer(): | ||
buf = StringIO() | ||
buf.buffer = BytesIO() | ||
return buf | ||
|
||
|
||
def get_bytes_out(out): | ||
# Python 3.x writes 'bytes' to stdout.buffer: | ||
return out.buffer.getvalue() | ||
# Python 3.x writes 'bytes' to stdout.buffer | ||
return out.buffer.getvalue() | ||
|
||
|
||
@contextmanager | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
|
||
import unittest | ||
import struct | ||
import sys | ||
|
||
from rsa._compat import byte, is_bytes, range | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a docstring like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!