-
Notifications
You must be signed in to change notification settings - Fork 422
Add re-add deprecated support for unicode in a variety of APIs #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e82326c
2403ef5
82efe3e
d2f0b07
9778f41
ef06348
c5484ba
6462b07
0894b17
607a380
0c02199
7578f35
13a0e65
362c1f5
8dc37a1
17eca48
f188d23
516c12c
9347742
39a8d59
da6399a
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 |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
|
||
from gc import collect, get_referrers | ||
from errno import ECONNREFUSED, EINPROGRESS, EWOULDBLOCK, EPIPE, ESHUTDOWN | ||
from sys import platform, version_info, getfilesystemencoding | ||
from sys import platform, getfilesystemencoding | ||
from socket import SHUT_RDWR, error, socket | ||
from os import makedirs | ||
from os.path import join | ||
from unittest import main | ||
from weakref import ref | ||
from warnings import catch_warnings, simplefilter | ||
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. wa comes before we :) 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. If we want to enforce this automatically, we can 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. Please continue with the current standard of importing modules in the order which minimizes heap allocation on Python 2.6.5 and Python 2.7.9. 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. That's a joke right? 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. Yes! 🎆 🎈 🎈 |
||
|
||
from six import PY3, text_type, u | ||
|
||
|
@@ -43,11 +44,9 @@ | |
Context, ContextType, Session, Connection, ConnectionType, SSLeay_version) | ||
|
||
from OpenSSL._util import lib as _lib | ||
|
||
from OpenSSL.test.util import NON_ASCII, TestCase, b | ||
from OpenSSL.test.test_crypto import ( | ||
cleartextCertificatePEM, cleartextPrivateKeyPEM) | ||
from OpenSSL.test.util import WARNING_TYPE_EXPECTED, NON_ASCII, TestCase, b | ||
from OpenSSL.test.test_crypto import ( | ||
cleartextCertificatePEM, cleartextPrivateKeyPEM, | ||
client_cert_pem, client_key_pem, server_cert_pem, server_key_pem, | ||
root_cert_pem) | ||
|
||
|
@@ -2108,7 +2107,7 @@ def test_set_tlsext_host_name_wrong_args(self): | |
self.assertRaises( | ||
TypeError, conn.set_tlsext_host_name, b("with\0null")) | ||
|
||
if version_info >= (3,): | ||
if PY3: | ||
# On Python 3.x, don't accidentally implicitly convert from text. | ||
self.assertRaises( | ||
TypeError, | ||
|
@@ -2749,6 +2748,26 @@ def test_short_bytes(self): | |
self.assertEquals(count, 2) | ||
self.assertEquals(client.recv(2), b('xy')) | ||
|
||
|
||
def test_text(self): | ||
""" | ||
When passed a text, :py:obj:`Connection.send` transmits all of it and | ||
returns the number of bytes sent. It also raises a DeprecationWarning. | ||
""" | ||
server, client = self._loopback() | ||
with catch_warnings(record=True) as w: | ||
simplefilter("always") | ||
count = server.send(b"xy".decode("ascii")) | ||
self.assertEqual( | ||
"{0} for buf is no longer accepted, use bytes".format( | ||
WARNING_TYPE_EXPECTED | ||
), | ||
str(w[-1].message) | ||
) | ||
self.assertIs(w[-1].category, DeprecationWarning) | ||
self.assertEquals(count, 2) | ||
self.assertEquals(client.recv(2), b"xy") | ||
|
||
try: | ||
memoryview | ||
except NameError: | ||
|
@@ -2969,6 +2988,25 @@ def test_short(self): | |
self.assertEquals(client.recv(1), b('x')) | ||
|
||
|
||
def test_text(self): | ||
""" | ||
:py:obj:`Connection.sendall` transmits all the content in the string | ||
passed to it raising a DeprecationWarning in case of this being a text. | ||
""" | ||
server, client = self._loopback() | ||
with catch_warnings(record=True) as w: | ||
simplefilter("always") | ||
server.sendall(b"x".decode("ascii")) | ||
self.assertEqual( | ||
"{0} for buf is no longer accepted, use bytes".format( | ||
WARNING_TYPE_EXPECTED | ||
), | ||
str(w[-1].message) | ||
) | ||
self.assertIs(w[-1].category, DeprecationWarning) | ||
self.assertEquals(client.recv(1), b"x") | ||
|
||
|
||
try: | ||
memoryview | ||
except NameError: | ||
|
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.
warnings is a stdlib module therefore the import should be in the previous block