Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9d1dbca5
Kaydet (Commit)
9d1dbca5
authored
Ara 02, 2013
tarafından
Walter Doerwald
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix issue #19834: Support unpickling of exceptions pickled by Python 2.
üst
708a3182
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
0 deletions
+136
-0
_compat_pickle.py
Lib/_compat_pickle.py
+56
-0
pickletester.py
Lib/test/pickletester.py
+80
-0
No files found.
Lib/_compat_pickle.py
Dosyayı görüntüle @
9d1dbca5
...
...
@@ -76,6 +76,62 @@ NAME_MAPPING = {
(
'itertools'
,
'ifilterfalse'
):
(
'itertools'
,
'filterfalse'
),
}
PYTHON2_EXCEPTIONS
=
(
"ArithmeticError"
,
"AssertionError"
,
"AttributeError"
,
"BaseException"
,
"BufferError"
,
"BytesWarning"
,
"DeprecationWarning"
,
"EOFError"
,
"EnvironmentError"
,
"Exception"
,
"FloatingPointError"
,
"FutureWarning"
,
"GeneratorExit"
,
"IOError"
,
"ImportError"
,
"ImportWarning"
,
"IndentationError"
,
"IndexError"
,
"KeyError"
,
"KeyboardInterrupt"
,
"LookupError"
,
"MemoryError"
,
"NameError"
,
"NotImplementedError"
,
"OSError"
,
"OverflowError"
,
"PendingDeprecationWarning"
,
"ReferenceError"
,
"RuntimeError"
,
"RuntimeWarning"
,
# StandardError is gone in Python 3, so we map it to Exception
"StopIteration"
,
"SyntaxError"
,
"SyntaxWarning"
,
"SystemError"
,
"SystemExit"
,
"TabError"
,
"TypeError"
,
"UnboundLocalError"
,
"UnicodeDecodeError"
,
"UnicodeEncodeError"
,
"UnicodeError"
,
"UnicodeTranslateError"
,
"UnicodeWarning"
,
"UserWarning"
,
"ValueError"
,
"Warning"
,
"ZeroDivisionError"
,
)
for
excname
in
PYTHON2_EXCEPTIONS
:
NAME_MAPPING
[(
"exceptions"
,
excname
)]
=
(
"builtins"
,
excname
)
NAME_MAPPING
[(
"exceptions"
,
"StandardError"
)]
=
(
"builtins"
,
"Exception"
)
# Same, but for 3.x to 2.x
REVERSE_IMPORT_MAPPING
=
dict
((
v
,
k
)
for
(
k
,
v
)
in
IMPORT_MAPPING
.
items
())
REVERSE_NAME_MAPPING
=
dict
((
v
,
k
)
for
(
k
,
v
)
in
NAME_MAPPING
.
items
())
Lib/test/pickletester.py
Dosyayı görüntüle @
9d1dbca5
...
...
@@ -407,6 +407,71 @@ DATA5 = (b'\x80\x02cCookie\nSimpleCookie\nq\x00)\x81q\x01U\x03key'
# set([3]) pickled from 2.x with protocol 2
DATA6
=
b
'
\x80\x02
c__builtin__
\n
set
\n
q
\x00
]q
\x01
K
\x03
a
\x85
q
\x02
Rq
\x03
.'
python2_exceptions_without_args
=
(
ArithmeticError
,
AssertionError
,
AttributeError
,
BaseException
,
BufferError
,
BytesWarning
,
DeprecationWarning
,
EOFError
,
EnvironmentError
,
Exception
,
FloatingPointError
,
FutureWarning
,
GeneratorExit
,
IOError
,
ImportError
,
ImportWarning
,
IndentationError
,
IndexError
,
KeyError
,
KeyboardInterrupt
,
LookupError
,
MemoryError
,
NameError
,
NotImplementedError
,
OSError
,
OverflowError
,
PendingDeprecationWarning
,
ReferenceError
,
RuntimeError
,
RuntimeWarning
,
# StandardError is gone in Python 3, we map it to Exception
StopIteration
,
SyntaxError
,
SyntaxWarning
,
SystemError
,
SystemExit
,
TabError
,
TypeError
,
UnboundLocalError
,
UnicodeError
,
UnicodeWarning
,
UserWarning
,
ValueError
,
Warning
,
ZeroDivisionError
,
)
exception_pickle
=
b
'
\x80\x02
cexceptions
\n
?
\n
q
\x00
)Rq
\x01
.'
# Exception objects without arguments pickled from 2.x with protocol 2
DATA7
=
{
exception
:
exception_pickle
.
replace
(
b
'?'
,
exception
.
__name__
.
encode
(
"ascii"
))
for
exception
in
python2_exceptions_without_args
}
# StandardError is mapped to Exception, test that separately
DATA8
=
exception_pickle
.
replace
(
b
'?'
,
b
'StandardError'
)
# UnicodeEncodeError object pickled from 2.x with protocol 2
DATA9
=
(
b
'
\x80\x02
cexceptions
\n
UnicodeEncodeError
\n
'
b
'q
\x00
(U
\x05
asciiq
\x01
X
\x03\x00\x00\x00
fooq
\x02
K
\x00
K
\x01
'
b
'U
\x03
badq
\x03
tq
\x04
Rq
\x05
.'
)
def
create_data
():
c
=
C
()
...
...
@@ -1160,6 +1225,21 @@ class AbstractPickleTests(unittest.TestCase):
self
.
assertEqual
(
list
(
loaded
.
keys
()),
[
"key"
])
self
.
assertEqual
(
loaded
[
"key"
]
.
value
,
"Set-Cookie: key=value"
)
for
(
exc
,
data
)
in
DATA7
.
items
():
loaded
=
self
.
loads
(
data
)
self
.
assertIs
(
type
(
loaded
),
exc
)
loaded
=
self
.
loads
(
DATA8
)
self
.
assertIs
(
type
(
loaded
),
Exception
)
loaded
=
self
.
loads
(
DATA9
)
self
.
assertIs
(
type
(
loaded
),
UnicodeEncodeError
)
self
.
assertEqual
(
loaded
.
object
,
"foo"
)
self
.
assertEqual
(
loaded
.
encoding
,
"ascii"
)
self
.
assertEqual
(
loaded
.
start
,
0
)
self
.
assertEqual
(
loaded
.
end
,
1
)
self
.
assertEqual
(
loaded
.
reason
,
"bad"
)
def
test_pickle_to_2x
(
self
):
# Pickle non-trivial data with protocol 2, expecting that it yields
# the same result as Python 2.x did.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment