Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
feea0786
Commit
feea0786
authored
Oct 10, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Random changes having to do with readline() and bytes.
parent
8d5c8b52
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
25 deletions
+14
-25
Lib/pickle.py
Lib/pickle.py
+14
-25
No files found.
Lib/pickle.py
View file @
feea0786
...
@@ -778,31 +778,17 @@ class Unpickler:
...
@@ -778,31 +778,17 @@ class Unpickler:
The protocol version of the pickle is detected automatically, so no
The protocol version of the pickle is detected automatically, so no
proto argument is needed.
proto argument is needed.
The file-like object must have two methods, a read() method that
The file-like object must have two methods, a read() method
takes an integer argument, and a readline() method that requires no
that takes an integer argument, and a readline() method that
arguments. Both methods should return a string. Thus file-like
requires no arguments. Both methods should return bytes.
object can be a file object opened for reading, a StringIO object,
Thus file-like object can be a binary file object opened for
or any other custom object that meets this interface.
reading, a BytesIO object, or any other custom object that
meets this interface.
"""
"""
try
:
self
.
readline
=
file
.
readline
self
.
readline
=
file
.
readline
except
AttributeError
:
self
.
file
=
file
self
.
read
=
file
.
read
self
.
read
=
file
.
read
self
.
memo
=
{}
self
.
memo
=
{}
def
readline
(
self
):
# XXX Slow but at least correct
b
=
bytes
()
while
True
:
c
=
self
.
file
.
read
(
1
)
if
not
c
:
break
b
+=
c
if
c
==
b'
\
n
'
:
break
return
b
def
load
(
self
):
def
load
(
self
):
"""Read a pickled object representation from the open file.
"""Read a pickled object representation from the open file.
...
@@ -895,7 +881,8 @@ class Unpickler:
...
@@ -895,7 +881,8 @@ class Unpickler:
dispatch
[
BININT2
[
0
]]
=
load_binint2
dispatch
[
BININT2
[
0
]]
=
load_binint2
def
load_long
(
self
):
def
load_long
(
self
):
self
.
append
(
int
(
str
(
self
.
readline
()[:
-
1
]),
0
))
val
=
self
.
readline
()[:
-
1
].
decode
(
"ascii"
)
self
.
append
(
int
(
val
,
0
))
dispatch
[
LONG
[
0
]]
=
load_long
dispatch
[
LONG
[
0
]]
=
load_long
def
load_long1
(
self
):
def
load_long1
(
self
):
...
@@ -1076,8 +1063,10 @@ class Unpickler:
...
@@ -1076,8 +1063,10 @@ class Unpickler:
def
find_class
(
self
,
module
,
name
):
def
find_class
(
self
,
module
,
name
):
# Subclasses may override this
# Subclasses may override this
module
=
str
(
module
)
if
isinstance
(
module
,
bytes
):
name
=
str
(
name
)
module
=
module
.
decode
(
"utf-8"
)
if
isinstance
(
name
,
bytes
):
name
=
name
.
decode
(
"utf-8"
)
__import__
(
module
)
__import__
(
module
)
mod
=
sys
.
modules
[
module
]
mod
=
sys
.
modules
[
module
]
klass
=
getattr
(
mod
,
name
)
klass
=
getattr
(
mod
,
name
)
...
@@ -1110,7 +1099,7 @@ class Unpickler:
...
@@ -1110,7 +1099,7 @@ class Unpickler:
dispatch
[
DUP
[
0
]]
=
load_dup
dispatch
[
DUP
[
0
]]
=
load_dup
def
load_get
(
self
):
def
load_get
(
self
):
self
.
append
(
self
.
memo
[
str
8
(
self
.
readline
())[:
-
1
]])
self
.
append
(
self
.
memo
[
str
(
self
.
readline
())[:
-
1
]])
dispatch
[
GET
[
0
]]
=
load_get
dispatch
[
GET
[
0
]]
=
load_get
def
load_binget
(
self
):
def
load_binget
(
self
):
...
...
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