Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(38103)

Side by Side Diff: Lib/bz2.py

Issue 16034: bz2 module appears slower in Python 3.x versus Python 2.x
Patch Set: Created 6 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Interface to the libbzip2 compression library. 1 """Interface to the libbzip2 compression library.
2 2
3 This module provides a file interface, classes for incremental 3 This module provides a file interface, classes for incremental
4 (de)compression, and functions for one-shot (de)compression. 4 (de)compression, and functions for one-shot (de)compression.
5 """ 5 """
6 6
7 __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", 7 __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor",
8 "open", "compress", "decompress"] 8 "open", "compress", "decompress"]
9 9
10 __author__ = "Nadeem Vawda <nadeem.vawda@gmail.com>" 10 __author__ = "Nadeem Vawda <nadeem.vawda@gmail.com>"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 self._check_not_closed() 152 self._check_not_closed()
153 return self._mode == _MODE_WRITE 153 return self._mode == _MODE_WRITE
154 154
155 # Mode-checking helper functions. 155 # Mode-checking helper functions.
156 156
157 def _check_not_closed(self): 157 def _check_not_closed(self):
158 if self.closed: 158 if self.closed:
159 raise ValueError("I/O operation on closed file") 159 raise ValueError("I/O operation on closed file")
160 160
161 def _check_can_read(self): 161 def _check_can_read(self):
162 if self.closed:
163 raise ValueError("I/O operation on closed file")
164 if self._mode not in (_MODE_READ, _MODE_READ_EOF): 162 if self._mode not in (_MODE_READ, _MODE_READ_EOF):
163 self._check_not_closed()
165 raise io.UnsupportedOperation("File not open for reading") 164 raise io.UnsupportedOperation("File not open for reading")
166 165
167 def _check_can_write(self): 166 def _check_can_write(self):
168 if self.closed:
169 raise ValueError("I/O operation on closed file")
170 if self._mode != _MODE_WRITE: 167 if self._mode != _MODE_WRITE:
168 self._check_not_closed()
171 raise io.UnsupportedOperation("File not open for writing") 169 raise io.UnsupportedOperation("File not open for writing")
172 170
173 def _check_can_seek(self): 171 def _check_can_seek(self):
174 if self.closed:
175 raise ValueError("I/O operation on closed file")
176 if self._mode not in (_MODE_READ, _MODE_READ_EOF): 172 if self._mode not in (_MODE_READ, _MODE_READ_EOF):
173 self._check_not_closed()
177 raise io.UnsupportedOperation("Seeking is only supported " 174 raise io.UnsupportedOperation("Seeking is only supported "
178 "on files open for reading") 175 "on files open for reading")
179 if not self._fp.seekable(): 176 if not self._fp.seekable():
180 raise io.UnsupportedOperation("The underlying file object " 177 raise io.UnsupportedOperation("The underlying file object "
181 "does not support seeking") 178 "does not support seeking")
182 179
183 # Fill the readahead buffer if it is empty. Returns False on EOF. 180 # Fill the readahead buffer if it is empty. Returns False on EOF.
184 def _fill_buffer(self): 181 def _fill_buffer(self):
185 if self._mode == _MODE_READ_EOF: 182 if self._mode == _MODE_READ_EOF:
186 return False 183 return False
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 while True: 492 while True:
496 decomp = BZ2Decompressor() 493 decomp = BZ2Decompressor()
497 results.append(decomp.decompress(data)) 494 results.append(decomp.decompress(data))
498 if not decomp.eof: 495 if not decomp.eof:
499 raise ValueError("Compressed data ended before the " 496 raise ValueError("Compressed data ended before the "
500 "end-of-stream marker was reached") 497 "end-of-stream marker was reached")
501 if not decomp.unused_data: 498 if not decomp.unused_data:
502 return b"".join(results) 499 return b"".join(results)
503 # There is unused data left over. Proceed to next stream. 500 # There is unused data left over. Proceed to next stream.
504 data = decomp.unused_data 501 data = decomp.unused_data
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+