Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upuse _ffi.from_buffer() to support bytearray #852
Conversation
This comment has been minimized.
This comment has been minimized.
Let’s put a test for a few invalid types here so we’ll know if cffi ever changes its exceptions on this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Same fix will need to apply to sendall(). Not sure about bio, since it is the other side of the encryption. |
This comment has been minimized.
This comment has been minimized.
Technically speaking, you should call The reason is: the way Python's buffer protocol works, as long as someone holds a reference to the raw data in the buffer, the original object is pinned. So for example, if you call Extra annoyances:
|
This comment has been minimized.
This comment has been minimized.
OK @njsmith how do you like this one? It has a compat no-op context manager for from_buffer. Unfortunately from_buffer is smarter than the test mock. I moved the length test past from_buffer in one of the commits because the error message from from_buffer() "wrong type" is nicer than the error message from len() "doesn't have a length" |
total_sent += result | ||
left_to_send -= result | ||
|
||
return total_sent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
OK folks, it's about as good as I'm likely to make it. Includes a bugfix for Includes a test to make sure |
This comment has been minimized.
This comment has been minimized.
I'm not very familiar with pyopenssl's internals, but FWIW this looks fine to me. |
This comment has been minimized.
This comment has been minimized.
@dholth btw, you have a flake8 failure:
|
This comment has been minimized.
This comment has been minimized.
Missed it by that much
On Tue, Jul 9, 2019, at 5:59 PM, Nathaniel J. Smith wrote:
@dholth <https://github.com/dholth> btw, you have a flake8 failure:
`tests/test_ssl.py:2103:80: E501 line too long (80 > 79 characters)
`
… —
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#852?email_source=notifications&email_token=AABSZEU5GNR6SKVWROUUQW3P6UC5FA5CNFSM4H65NEKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZRVGJY#issuecomment-509825831>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AABSZEV4U5VX3YGTUTRBP3DP6UC5FANCNFSM4H65NEKA>.
|
This comment has been minimized.
This comment has been minimized.
This likely improves performance too, with the simplified checking and doesn't-copy nature of from_buffer. |
Sorry about the ridiculous amount of time this review took. Thanks for working on this, looks good! |
dholth commentedJul 8, 2019
If you try to send a dict it produces this error message:
TypeError: a bytes-like object is required, not 'dict'
It doesn't accept
bytearray
withoutfrom_buffer
(cffi doesn't automatically convert that type forchar*
arguments)