mirror of
https://github.com/python/cpython.git
synced 2025-09-03 15:31:08 +00:00
[3.11] gh-50644: Forbid pickling of codecs streams (GH-109180) (GH-109232)
Attempts to pickle or create a shallow or deep copy of codecs streams
now raise a TypeError.
Previously, copying failed with a RecursionError, while pickling
produced wrong results that eventually caused unpickling to fail with
a RecursionError.
(cherry picked from commit d6892c2b92
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
c20658249d
commit
b070d73ff2
3 changed files with 95 additions and 0 deletions
|
@ -414,6 +414,9 @@ class StreamWriter(Codec):
|
|||
def __exit__(self, type, value, tb):
|
||||
self.stream.close()
|
||||
|
||||
def __reduce_ex__(self, proto):
|
||||
raise TypeError("can't serialize %s" % self.__class__.__name__)
|
||||
|
||||
###
|
||||
|
||||
class StreamReader(Codec):
|
||||
|
@ -663,6 +666,9 @@ class StreamReader(Codec):
|
|||
def __exit__(self, type, value, tb):
|
||||
self.stream.close()
|
||||
|
||||
def __reduce_ex__(self, proto):
|
||||
raise TypeError("can't serialize %s" % self.__class__.__name__)
|
||||
|
||||
###
|
||||
|
||||
class StreamReaderWriter:
|
||||
|
@ -750,6 +756,9 @@ class StreamReaderWriter:
|
|||
def __exit__(self, type, value, tb):
|
||||
self.stream.close()
|
||||
|
||||
def __reduce_ex__(self, proto):
|
||||
raise TypeError("can't serialize %s" % self.__class__.__name__)
|
||||
|
||||
###
|
||||
|
||||
class StreamRecoder:
|
||||
|
@ -866,6 +875,9 @@ class StreamRecoder:
|
|||
def __exit__(self, type, value, tb):
|
||||
self.stream.close()
|
||||
|
||||
def __reduce_ex__(self, proto):
|
||||
raise TypeError("can't serialize %s" % self.__class__.__name__)
|
||||
|
||||
### Shortcuts
|
||||
|
||||
def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue