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
8587b3c0
Kaydet (Commit)
8587b3c0
authored
Şub 13, 2003
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
üst
fe62bc91
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
10 deletions
+20
-10
pickle.py
Lib/pickle.py
+7
-3
pickletester.py
Lib/test/pickletester.py
+4
-2
cPickle.c
Modules/cPickle.c
+9
-5
No files found.
Lib/pickle.py
Dosyayı görüntüle @
8587b3c0
...
...
@@ -47,6 +47,10 @@ compatible_formats = ["1.0", # Original protocol 0
"2.0"
,
# Protocol 2
]
# Old format versions we can read
# Keep in synch with cPickle. This is the highest protocol number we
# know how to read.
HIGHEST_PROTOCOL
=
2
# Why use struct.pack() for pickling but marshal.loads() for
# unpickling? struct.pack() is 40% faster than marshal.dumps(), but
# marshal.loads() is twice as fast as struct.unpack()!
...
...
@@ -200,9 +204,9 @@ class Pickler:
if
protocol
is
None
:
protocol
=
0
if
protocol
<
0
:
protocol
=
2
elif
protocol
not
in
(
0
,
1
,
2
)
:
raise
ValueError
,
"pickle protocol must be 0, 1 or 2"
protocol
=
HIGHEST_PROTOCOL
elif
not
0
<=
protocol
<=
HIGHEST_PROTOCOL
:
raise
ValueError
(
"pickle protocol must be <=
%
d"
%
HIGHEST_PROTOCOL
)
self
.
write
=
file
.
write
self
.
memo
=
{}
self
.
proto
=
int
(
protocol
)
...
...
Lib/test/pickletester.py
Dosyayı görüntüle @
8587b3c0
import
unittest
import
pickle
import
cPickle
import
pickletools
import
copy_reg
...
...
@@ -7,8 +8,9 @@ from test.test_support import TestFailed, have_unicode, TESTFN
# Tests that try a number of pickle protocols should have a
# for proto in protocols:
# kind of outer loop. Bump the 3 to 4 if/when protocol 3 is invented.
protocols
=
range
(
3
)
# kind of outer loop.
assert
pickle
.
HIGHEST_PROTOCOL
==
cPickle
.
HIGHEST_PROTOCOL
==
2
protocols
=
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
)
# Return True if opcode code appears in the pickle, else False.
...
...
Modules/cPickle.c
Dosyayı görüntüle @
8587b3c0
...
...
@@ -15,7 +15,7 @@ PyDoc_STRVAR(cPickle_module_documentation,
#define WRITE_BUF_SIZE 256
/* Bump this when new opcodes are added to the pickle protocol. */
#define
CURRENT_PROTOCOL_NUMBER
2
#define
HIGHEST_PROTOCOL
2
/*
* Pickle opcodes. These must be kept in synch with pickle.py. Extensive
...
...
@@ -2743,11 +2743,11 @@ newPicklerobject(PyObject *file, int proto)
Picklerobject
*
self
;
if
(
proto
<
0
)
proto
=
CURRENT_PROTOCOL_NUMBER
;
if
(
proto
>
CURRENT_PROTOCOL_NUMBER
)
{
proto
=
HIGHEST_PROTOCOL
;
if
(
proto
>
HIGHEST_PROTOCOL
)
{
PyErr_Format
(
PyExc_ValueError
,
"pickle protocol %d asked for; "
"the highest available protocol is %d"
,
proto
,
CURRENT_PROTOCOL_NUMBER
);
proto
,
HIGHEST_PROTOCOL
);
return
NULL
;
}
...
...
@@ -4308,7 +4308,7 @@ load_proto(Unpicklerobject *self)
* int when chewing on 1 byte.
*/
assert
(
i
>=
0
);
if
(
i
<=
CURRENT_PROTOCOL_NUMBER
)
if
(
i
<=
HIGHEST_PROTOCOL
)
return
0
;
PyErr_Format
(
PyExc_ValueError
,
"unsupported pickle protocol: %d"
,
i
);
...
...
@@ -5562,6 +5562,10 @@ initcPickle(void)
}
Py_DECREF
(
di
);
i
=
PyModule_AddIntConstant
(
m
,
"HIGHEST_PROTOCOL"
,
HIGHEST_PROTOCOL
);
if
(
i
<
0
)
return
;
/* These are purely informational; no code uses them. */
/* File format version we write. */
format_version
=
PyString_FromString
(
"2.0"
);
...
...
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