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
40ee1574
Commit
40ee1574
authored
Oct 01, 2012
by
Nadeem Vawda
Browse files
Options
Browse Files
Download
Plain Diff
Merge: #16304: Optimizations for BZ2File, and minor bugfix.
parents
4993cc0a
eb70be2b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
Lib/bz2.py
Lib/bz2.py
+12
-12
No files found.
Lib/bz2.py
View file @
40ee1574
...
...
@@ -159,21 +159,18 @@ class BZ2File(io.BufferedIOBase):
raise
ValueError
(
"I/O operation on closed file"
)
def
_check_can_read
(
self
):
if
self
.
closed
:
raise
ValueError
(
"I/O operation on closed file"
)
if
self
.
_mode
not
in
(
_MODE_READ
,
_MODE_READ_EOF
):
self
.
_check_not_closed
()
raise
io
.
UnsupportedOperation
(
"File not open for reading"
)
def
_check_can_write
(
self
):
if
self
.
closed
:
raise
ValueError
(
"I/O operation on closed file"
)
if
self
.
_mode
!=
_MODE_WRITE
:
self
.
_check_not_closed
()
raise
io
.
UnsupportedOperation
(
"File not open for writing"
)
def
_check_can_seek
(
self
):
if
self
.
closed
:
raise
ValueError
(
"I/O operation on closed file"
)
if
self
.
_mode
not
in
(
_MODE_READ
,
_MODE_READ_EOF
):
self
.
_check_not_closed
()
raise
io
.
UnsupportedOperation
(
"Seeking is only supported "
"on files open for reading"
)
if
not
self
.
_fp
.
seekable
():
...
...
@@ -322,10 +319,12 @@ class BZ2File(io.BufferedIOBase):
non-negative, no more than size bytes will be read (in which
case the line may be incomplete). Returns b'' if already at EOF.
"""
if
not
hasattr
(
size
,
"__index__"
):
raise
TypeError
(
"Integer argument expected"
)
size
=
size
.
__index__
()
if
not
isinstance
(
size
,
int
):
if
not
hasattr
(
size
,
"__index__"
):
raise
TypeError
(
"Integer argument expected"
)
size
=
size
.
__index__
()
with
self
.
_lock
:
self
.
_check_can_read
()
# Shortcut for the common case - the whole line is in the buffer.
if
size
<
0
:
end
=
self
.
_buffer
.
find
(
b"
\
n
"
,
self
.
_buffer_offset
)
+
1
...
...
@@ -343,9 +342,10 @@ class BZ2File(io.BufferedIOBase):
further lines will be read once the total size of the lines read
so far equals or exceeds size.
"""
if
not
hasattr
(
size
,
"__index__"
):
raise
TypeError
(
"Integer argument expected"
)
size
=
size
.
__index__
()
if
not
isinstance
(
size
,
int
):
if
not
hasattr
(
size
,
"__index__"
):
raise
TypeError
(
"Integer argument expected"
)
size
=
size
.
__index__
()
with
self
.
_lock
:
return
io
.
BufferedIOBase
.
readlines
(
self
,
size
)
...
...
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