diff options
| author | Abraham Martin <amc203@cam.ac.uk> | 2015-03-25 10:50:09 +0000 |
|---|---|---|
| committer | Abraham Martin <amc203@cam.ac.uk> | 2015-03-25 10:50:09 +0000 |
| commit | 82efe3e6db46c0924b5b2d6e0793a62bd48e7dcc (patch) | |
| tree | dc530af08a6b06a20232031c60674932a3e2d570 /OpenSSL/SSL.py | |
| parent | 2403ef5498f98cffcde210a382ae3c44d9be6332 (diff) | |
| download | pyopenssl-82efe3e6db46c0924b5b2d6e0793a62bd48e7dcc.tar.gz | |
Different warning messages for different versions of Python
Diffstat (limited to 'OpenSSL/SSL.py')
| -rw-r--r-- | OpenSSL/SSL.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index 5d9c360..8972097 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -1,5 +1,5 @@ -import warnings -from sys import platform +from warnings import warn +from sys import platform, version_info from functools import wraps, partial from itertools import count from weakref import WeakValueDictionary @@ -314,7 +314,12 @@ class Context(object): # Backward compatibility if isinstance(cafile, _text_type): - warnings.warn("str object in cafile is no longer accepted, use bytes", DeprecationWarning) + if version_info.major == 2: + warn("unicode in cafile is no longer accepted, use bytes", DeprecationWarning) + elif version_info.major == 3: + warn("str in cafile is no longer accepted, use bytes", DeprecationWarning) + else: + warn("text in cafile is no longer accepted, use bytes", DeprecationWarning) cafile = cafile.encode('utf-8') if cafile is None: @@ -980,7 +985,12 @@ class Connection(object): # Backward compatibility if isinstance(buf, _text_type): - warnings.warn("str object in buf is no longer accepted, use bytes", DeprecationWarning) + if version_info.major == 2: + warn("unicode in buf is no longer accepted, use bytes", DeprecationWarning) + elif version_info.major == 3: + warn("str in buf is no longer accepted, use bytes", DeprecationWarning) + else: + warn("text in buf is no longer accepted, use bytes", DeprecationWarning) buf = buf.encode('utf-8') if isinstance(buf, _memoryview): @@ -1010,7 +1020,12 @@ class Connection(object): # Backward compatibility if isinstance(buf, _text_type): - warnings.warn("str object in buf is no longer accepted, use bytes", DeprecationWarning) + if version_info.major == 2: + warn("unicode in buf is no longer accepted, use bytes", DeprecationWarning) + elif version_info.major == 3: + warn("str in buf is no longer accepted, use bytes", DeprecationWarning) + else: + warn("text in buf is no longer accepted, use bytes", DeprecationWarning) buf = buf.encode('utf-8') if isinstance(buf, _memoryview): @@ -1101,7 +1116,12 @@ class Connection(object): # Backward compatibility if isinstance(buf, _text_type): - warnings.warn("str object in buf is no longer accepted, use bytes", DeprecationWarning) + if version_info.major == 2: + warn("unicode in buf is no longer accepted, use bytes", DeprecationWarning) + elif version_info.major == 3: + warn("str in vuf is no longer accepted, use bytes", DeprecationWarning) + else: + warn("text in buf is no longer accepted, use bytes", DeprecationWarning) buf = buf.encode("ascii") if self._into_ssl is None: |
