| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 74f5687 commit 2ddc5ec
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -388,6 +388,10 @@ def __new__(cls, protocol=PROTOCOL_TLS, *args, **kwargs): | |||
| 388 | 388 | self = _SSLContext.__new__(cls, protocol) | |
| 389 | 389 | return self | |
| 390 | 390 | ||
| 391 | + def __getstate__(self): | ||
| 392 | + raise TypeError("cannot serialize {} object".format( | ||
| 393 | + self.__class__.__name__)) | ||
| 394 | + | ||
| 391 | 395 | def _encode_hostname(self, hostname): | |
| 392 | 396 | if hostname is None: | |
| 393 | 397 | return None | |
@@ -695,6 +699,10 @@ def server_hostname(self): | |||
| 695 | 699 | server hostame is set.""" | |
| 696 | 700 | return self._sslobj.server_hostname | |
| 697 | 701 | ||
| 702 | + def __getstate__(self): | ||
| 703 | + raise TypeError("cannot serialize {} object".format( | ||
| 704 | + self.__class__.__name__)) | ||
| 705 | + | ||
| 698 | 706 | def read(self, len=1024, buffer=None): | |
| 699 | 707 | """Read up to 'len' bytes from the SSL object and return them. | |
| 700 | 708 | ||
@@ -880,9 +888,13 @@ def session_reused(self): | |||
| 880 | 888 | if self._sslobj is not None: | |
| 881 | 889 | return self._sslobj.session_reused | |
| 882 | 890 | ||
| 891 | + def __getstate__(self): | ||
| 892 | + raise TypeError("cannot serialize {} object".format( | ||
| 893 | + self.__class__.__name__)) | ||
| 894 | + | ||
| 883 | 895 | def dup(self): | |
| 884 | - raise NotImplemented("Can't dup() %s instances" % | ||
| 885 | - self.__class__.__name__) | ||
| 896 | + raise NotImplementedError("Can't dup() {} instances".format( | ||
| 897 | + self.__class__.__name__)) | ||
| 886 | 898 | ||
| 887 | 899 | def _checkClosed(self, msg=None): | |
| 888 | 900 | # raise an exception here if you wish to check for spurious closes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,8 @@ | |||
| 19 | 19 | import platform | |
| 20 | 20 | import functools | |
| 21 | 21 | import sysconfig | |
| 22 | + import copy | ||
| 23 | + import pickle | ||
| 22 | 24 | try: | |
| 23 | 25 | import ctypes | |
| 24 | 26 | except ImportError: | |
@@ -972,6 +974,17 @@ def test_connect_ex_error(self): | |||
| 972 | 974 | ) | |
| 973 | 975 | self.assertIn(rc, errors) | |
| 974 | 976 | ||
| 977 | + def test_copy_pickle(self): | ||
| 978 | + ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
| 979 | + with ctx.wrap_socket(socket.socket(), | ||
| 980 | + server_hostname='localhost') as s: | ||
| 981 | + with self.assertRaises(TypeError): | ||
| 982 | + copy.copy(s) | ||
| 983 | + with self.assertRaises(TypeError): | ||
| 984 | + copy.deepcopy(s) | ||
| 985 | + with self.assertRaises(TypeError): | ||
| 986 | + pickle.dumps(s) | ||
| 987 | + | ||
| 975 | 988 | ||
| 976 | 989 | class ContextTests(unittest.TestCase): | |
| 977 | 990 | ||
@@ -1608,6 +1621,15 @@ class MySSLObject(ssl.SSLObject): | |||
| 1608 | 1621 | obj = ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO()) | |
| 1609 | 1622 | self.assertIsInstance(obj, MySSLObject) | |
| 1610 | 1623 | ||
| 1624 | + def test_copy_pickle(self): | ||
| 1625 | + ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
| 1626 | + with self.assertRaises(TypeError): | ||
| 1627 | + copy.copy(ctx) | ||
| 1628 | + with self.assertRaises(TypeError): | ||
| 1629 | + copy.deepcopy(ctx) | ||
| 1630 | + with self.assertRaises(TypeError): | ||
| 1631 | + pickle.dumps(ctx) | ||
| 1632 | + | ||
| 1611 | 1633 | ||
| 1612 | 1634 | class SSLErrorTests(unittest.TestCase): | |
| 1613 | 1635 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Improve error message when trying to serialize SSLContext, SSLObject, and | ||
| 2 | + SSLSocket objects. The classes can't be pickled or copied by the copy | ||
| 3 | + module. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments