Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c67fe4a

Browse filesBrowse files
committed
Fix a test
1 parent 5727195 commit c67fe4a
Copy full SHA for c67fe4a

File tree

2 files changed

+13
-8
lines changed
Filter options

2 files changed

+13
-8
lines changed

‎Lib/test/test_bz2.py

Copy file name to clipboardExpand all lines: Lib/test/test_bz2.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,6 @@ def testDecompressUnusedData(self):
753753
self.assertEqual(text, self.TEXT)
754754
self.assertEqual(bz2d.unused_data, unused_data)
755755

756-
# TODO: RUSTPYTHON
757-
@unittest.expectedFailure
758756
def testEOFError(self):
759757
bz2d = BZ2Decompressor()
760758
text = bz2d.decompress(self.DATA)

‎stdlib/src/bz2.rs

Copy file name to clipboardExpand all lines: stdlib/src/bz2.rs
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ mod _bz2 {
7777
unused_data,
7878
needs_input,
7979
} = &mut *self.state.lock();
80+
if *eof {
81+
return Err(vm.new_exception_msg(
82+
vm.ctx.exceptions.eof_error.to_owned(),
83+
"End of stream already reached".to_owned(),
84+
));
85+
}
8086
let data_vec = data.borrow_buf().to_vec();
8187
input_buffer.extend(data_vec);
8288

@@ -102,6 +108,10 @@ mod _bz2 {
102108
let consumed = cursor.position() as usize;
103109
// Remove the consumed bytes.
104110
input_buffer.drain(0..consumed);
111+
unused_data.replace(input_buffer.clone());
112+
// skrink the vector to save memory
113+
input_buffer.shrink_to_fit();
114+
unused_data.as_mut().map(|v| v.shrink_to_fit());
105115

106116
if *eof {
107117
*needs_input = false;
@@ -112,8 +122,6 @@ mod _bz2 {
112122
// If the decoder reached end-of-stream (i.e. no more input remains), mark eof.
113123
if input_buffer.is_empty() {
114124
*eof = true;
115-
*unused_data = Some(input_buffer.clone());
116-
input_buffer.clear();
117125
}
118126

119127
Ok(vm.ctx.new_bytes(output))
@@ -128,10 +136,9 @@ mod _bz2 {
128136
#[pygetset]
129137
fn unused_data(&self, vm: &VirtualMachine) -> PyBytesRef {
130138
let state = self.state.lock();
131-
if state.eof {
132-
vm.ctx.new_bytes(state.input_buffer.to_vec())
133-
} else {
134-
vm.ctx.new_bytes(b"".to_vec())
139+
match &state.unused_data {
140+
Some(data) => vm.ctx.new_bytes(data.clone()),
141+
None => vm.ctx.new_bytes(Vec::new()),
135142
}
136143
}
137144

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.