@@ -9,7 +9,7 @@ use std::io::SeekFrom;
9
9
use num_traits:: ToPrimitive ;
10
10
11
11
use super :: os;
12
- use crate :: function:: { OptionalArg , PyFuncArgs } ;
12
+ use crate :: function:: { OptionalArg , OptionalOption , PyFuncArgs } ;
13
13
use crate :: obj:: objbytearray:: PyByteArray ;
14
14
use crate :: obj:: objbytes;
15
15
use crate :: obj:: objbytes:: PyBytes ;
@@ -21,11 +21,8 @@ use crate::pyobject::TypeProtocol;
21
21
use crate :: pyobject:: { BufferProtocol , Either , PyObjectRef , PyRef , PyResult , PyValue } ;
22
22
use crate :: vm:: VirtualMachine ;
23
23
24
- fn byte_count ( bytes : OptionalArg < Option < PyObjectRef > > ) -> i64 {
25
- match bytes {
26
- OptionalArg :: Present ( Some ( ref int) ) => objint:: get_value ( int) . to_i64 ( ) . unwrap ( ) ,
27
- _ => ( -1 as i64 ) ,
28
- }
24
+ fn byte_count ( bytes : OptionalOption < i64 > ) -> i64 {
25
+ bytes. flat_option ( ) . unwrap_or ( -1 as i64 )
29
26
}
30
27
31
28
#[ derive( Debug ) ]
@@ -134,7 +131,7 @@ impl PyStringIORef {
134
131
//Read k bytes from the object and return.
135
132
//If k is undefined || k == -1, then we read all bytes until the end of the file.
136
133
//This also increments the stream position by the value of k
137
- fn read ( self , bytes : OptionalArg < Option < PyObjectRef > > , vm : & VirtualMachine ) -> PyResult {
134
+ fn read ( self , bytes : OptionalOption < i64 > , vm : & VirtualMachine ) -> PyResult {
138
135
let data = match self . buffer . borrow_mut ( ) . read ( byte_count ( bytes) ) {
139
136
Some ( value) => value,
140
137
None => Vec :: new ( ) ,
@@ -193,7 +190,7 @@ impl PyBytesIORef {
193
190
//Takes an integer k (bytes) and returns them from the underlying buffer
194
191
//If k is undefined || k == -1, then we read all bytes until the end of the file.
195
192
//This also increments the stream position by the value of k
196
- fn read ( self , bytes : OptionalArg < Option < PyObjectRef > > , vm : & VirtualMachine ) -> PyResult {
193
+ fn read ( self , bytes : OptionalOption < i64 > , vm : & VirtualMachine ) -> PyResult {
197
194
match self . buffer . borrow_mut ( ) . read ( byte_count ( bytes) ) {
198
195
Some ( value) => Ok ( vm. ctx . new_bytes ( value) ) ,
199
196
None => Err ( vm. new_value_error ( "Error Retrieving Value" . to_string ( ) ) ) ,
0 commit comments