mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Support keyword argument 'bin', with a pending deprecation warning.
This commit is contained in:
parent
31f119ebdb
commit
795ea89cb5
1 changed files with 13 additions and 5 deletions
|
@ -167,7 +167,7 @@ del x
|
||||||
|
|
||||||
class Pickler:
|
class Pickler:
|
||||||
|
|
||||||
def __init__(self, file, proto=0):
|
def __init__(self, file, proto=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 proto argument tells the pickler to use the given
|
||||||
|
@ -191,6 +191,14 @@ 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:
|
||||||
|
raise ValueError, "can't specify both 'proto' and 'bin' arguments"
|
||||||
|
if bin is not None:
|
||||||
|
warnings.warn("The 'bin' argument to Pickler() is deprecated",
|
||||||
|
PendingDeprecationWarning)
|
||||||
|
proto = bin
|
||||||
|
if proto is None:
|
||||||
|
proto = 0
|
||||||
if proto < 0:
|
if proto < 0:
|
||||||
proto = 2
|
proto = 2
|
||||||
elif proto not in (0, 1, 2):
|
elif proto not in (0, 1, 2):
|
||||||
|
@ -1464,12 +1472,12 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
def dump(obj, file, proto=0):
|
def dump(obj, file, proto=None, bin=None):
|
||||||
Pickler(file, proto).dump(obj)
|
Pickler(file, proto, bin).dump(obj)
|
||||||
|
|
||||||
def dumps(obj, proto=0):
|
def dumps(obj, proto=None, bin=None):
|
||||||
file = StringIO()
|
file = StringIO()
|
||||||
Pickler(file, proto).dump(obj)
|
Pickler(file, proto, 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