diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2013-04-16 06:14:55 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2013-04-16 06:14:55 (GMT) |
commit | 7c5e094cbfa6769bf4cabfa5f883f2dc5320667b (patch) | |
tree | 096be7fc037ead2cf551a1ce25c8b7afd4dee463 /Lib/pickle.py | |
parent | 48a2e7c357b7f2148ada9473c796351cc562284b (diff) | |
download | cpython-7c5e094cbfa6769bf4cabfa5f883f2dc5320667b.zip cpython-7c5e094cbfa6769bf4cabfa5f883f2dc5320667b.tar.gz cpython-7c5e094cbfa6769bf4cabfa5f883f2dc5320667b.tar.bz2 |
Make C and Python implementations of pickle load STRING opcodes the same way.
The C version tried to remove trailing whitespace between the last quote and
the newline character. I am not sure why it had this because pickle never
generated such pickles---for this to happen repr(some_string) would need to
return trailing whitespace. It was maybe there to make it easier for people
to write pickles in text editors. Anyhow, the Python version doesn't do this
so there is no point keeping this around anymore.
Also, I've changed the exception raised when a bad pickle is encountered.
Again this unlikely to make much difference to anyone though it does make
testing slightly nicer for us.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index a4acbe9..d121ec9 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -900,14 +900,13 @@ class _Unpickler: dispatch[BINFLOAT[0]] = load_binfloat def load_string(self): - orig = self.readline() - rep = orig[:-1] + data = self.readline()[:-1] # Strip outermost quotes - if len(rep) >= 2 and rep[0] == rep[-1] and rep[0] in b'"\'': - rep = rep[1:-1] + if len(data) >= 2 and data[0] == data[-1] and data[0] in b'"\'': + data = data[1:-1] else: - raise ValueError("insecure string pickle") - self.append(codecs.escape_decode(rep)[0] + raise UnpicklingError("the STRING opcode argument must be quoted") + self.append(codecs.escape_decode(data)[0] .decode(self.encoding, self.errors)) dispatch[STRING[0]] = load_string |