mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
Rename 'proto' keyword arg to 'protocol' . Greg Ward's suggestion.
This commit is contained in:
parent
d58f3fce3d
commit
cf117b0b40
1 changed files with 17 additions and 17 deletions
|
@ -167,11 +167,11 @@ del x
|
||||||
|
|
||||||
class Pickler:
|
class Pickler:
|
||||||
|
|
||||||
def __init__(self, file, proto=None, bin=None):
|
def __init__(self, file, protocol=None, bin=None):
|
||||||
"""This takes a file-like object for writing a pickle data stream.
|
"""This takes a file-like object for writing a pickle data stream.
|
||||||
|
|
||||||
The optional proto argument tells the pickler to use the given
|
The optional protocol argument tells the pickler to use the
|
||||||
protocol; supported protocols are 0, 1, 2. The default
|
given protocol; supported protocols are 0, 1, 2. The default
|
||||||
protocol is 0, to be backwards compatible. (Protocol 0 is the
|
protocol is 0, to be backwards compatible. (Protocol 0 is the
|
||||||
only protocol that can be written to a file opened in text
|
only protocol that can be written to a file opened in text
|
||||||
mode and read back successfully. When using a protocol higher
|
mode and read back successfully. When using a protocol higher
|
||||||
|
@ -191,22 +191,22 @@ class Pickler:
|
||||||
object, or any other custom object that meets this interface.
|
object, or any other custom object that meets this interface.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if proto is not None and bin is not None:
|
if protocol is not None and bin is not None:
|
||||||
raise ValueError, "can't specify both 'proto' and 'bin' arguments"
|
raise ValueError, "can't specify both 'protocol' and 'bin'"
|
||||||
if bin is not None:
|
if bin is not None:
|
||||||
warnings.warn("The 'bin' argument to Pickler() is deprecated",
|
warnings.warn("The 'bin' argument to Pickler() is deprecated",
|
||||||
PendingDeprecationWarning)
|
PendingDeprecationWarning)
|
||||||
proto = bin
|
protocol = bin
|
||||||
if proto is None:
|
if protocol is None:
|
||||||
proto = 0
|
protocol = 0
|
||||||
if proto < 0:
|
if protocol < 0:
|
||||||
proto = 2
|
protocol = 2
|
||||||
elif proto not in (0, 1, 2):
|
elif protocol not in (0, 1, 2):
|
||||||
raise ValueError, "pickle protocol must be 0, 1 or 2"
|
raise ValueError, "pickle protocol must be 0, 1 or 2"
|
||||||
self.write = file.write
|
self.write = file.write
|
||||||
self.memo = {}
|
self.memo = {}
|
||||||
self.proto = int(proto)
|
self.proto = int(protocol)
|
||||||
self.bin = proto >= 1
|
self.bin = protocol >= 1
|
||||||
self.fast = 0
|
self.fast = 0
|
||||||
|
|
||||||
def clear_memo(self):
|
def clear_memo(self):
|
||||||
|
@ -1369,12 +1369,12 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
def dump(obj, file, proto=None, bin=None):
|
def dump(obj, file, protocol=None, bin=None):
|
||||||
Pickler(file, proto, bin).dump(obj)
|
Pickler(file, protocol, bin).dump(obj)
|
||||||
|
|
||||||
def dumps(obj, proto=None, bin=None):
|
def dumps(obj, protocol=None, bin=None):
|
||||||
file = StringIO()
|
file = StringIO()
|
||||||
Pickler(file, proto, bin).dump(obj)
|
Pickler(file, protocol, bin).dump(obj)
|
||||||
return file.getvalue()
|
return file.getvalue()
|
||||||
|
|
||||||
def load(file):
|
def load(file):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue