File tree Expand file tree Collapse file tree 3 files changed +6
-12
lines changed Expand file tree Collapse file tree 3 files changed +6
-12
lines changed Original file line number Diff line number Diff line change 142
142
bytes .fromhex ("6Z2" )
143
143
except ValueError as e :
144
144
str (e ) == "non-hexadecimal number found in fromhex() arg at position 1"
145
-
145
+ with assertRaises (TypeError ):
146
+ bytes .fromhex (b'hhjjk' )
146
147
# center
147
148
assert [b"koki" .center (i , b"|" ) for i in range (3 , 10 )] == [
148
149
b"koki" ,
Original file line number Diff line number Diff line change @@ -342,7 +342,7 @@ impl PyByteInner {
342
342
Ok ( vm. ctx . new_str ( bla) )
343
343
}
344
344
345
- pub fn fromhex ( string : String , vm : & VirtualMachine ) -> Result < Vec < u8 > , PyObjectRef > {
345
+ pub fn fromhex ( string : & str , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
346
346
// first check for invalid character
347
347
for ( i, c) in string. char_indices ( ) {
348
348
if !c. is_digit ( 16 ) && !c. is_whitespace ( ) {
Original file line number Diff line number Diff line change 1
- use crate :: obj:: objstr:: PyString ;
1
+ use crate :: obj:: objstr:: PyStringRef ;
2
2
use crate :: vm:: VirtualMachine ;
3
3
use core:: cell:: Cell ;
4
4
use std:: ops:: Deref ;
@@ -216,15 +216,8 @@ impl PyBytesRef {
216
216
self . inner . hex ( vm)
217
217
}
218
218
219
- // #[pymethod(name = "fromhex")]
220
- fn fromhex ( string : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
221
- match_class ! ( string,
222
- s @ PyString => {
223
- match PyByteInner :: fromhex( s. to_string( ) , vm) {
224
- Ok ( x) => Ok ( vm. ctx. new_bytes( x) ) ,
225
- Err ( y) => Err ( y) } } ,
226
- obj => Err ( vm. new_type_error( format!( "fromhex() argument must be str, not {}" , obj ) ) )
227
- )
219
+ fn fromhex ( string : PyStringRef , vm : & VirtualMachine ) -> PyResult {
220
+ Ok ( vm. ctx . new_bytes ( PyByteInner :: fromhex ( string. as_str ( ) , vm) ?) )
228
221
}
229
222
230
223
#[ pymethod( name = "center" ) ]
You can’t perform that action at this time.
0 commit comments