File tree 4 files changed +29
-6
lines changed
4 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -416,8 +416,6 @@ def test_fromhex(self):
416
416
self .type2test .fromhex (data )
417
417
self .assertIn ('at position %s' % pos , str (cm .exception ))
418
418
419
- # TODO: RUSTPYTHON
420
- @unittest .expectedFailure
421
419
def test_hex (self ):
422
420
self .assertRaises (TypeError , self .type2test .hex )
423
421
self .assertRaises (TypeError , self .type2test .hex , 1 )
Original file line number Diff line number Diff line change @@ -544,8 +544,6 @@ def test_ctypes_cast(self):
544
544
m [2 :] = memoryview (p6 ).cast (format )[2 :]
545
545
self .assertEqual (d .value , 0.6 )
546
546
547
- # TODO: RUSTPYTHON
548
- @unittest .expectedFailure
549
547
def test_memoryview_hex (self ):
550
548
# Issue #9951: memoryview.hex() segfaults with non-contiguous buffers.
551
549
x = b'0' * 200000
Original file line number Diff line number Diff line change @@ -222,8 +222,10 @@ impl PyBytes {
222
222
self . inner . swapcase ( ) . into ( )
223
223
}
224
224
225
+ // TODO: Changed in version 3.8: bytes.hex() now supports optional sep and
226
+ // bytes_per_sep parameters to insert separators between bytes in the hex output.
225
227
#[ pymethod( name = "hex" ) ]
226
- fn hex ( & self ) -> String {
228
+ pub ( crate ) fn hex ( & self ) -> String {
227
229
self . inner . hex ( )
228
230
}
229
231
Original file line number Diff line number Diff line change @@ -603,6 +603,30 @@ impl PyMemoryView {
603
603
}
604
604
}
605
605
606
+ // TODO: Changed in version 3.8: memoryview.hex() now supports optional sep and bytes_per_sep
607
+ // parameters to insert separators between bytes in the hex output.
608
+ #[ pymethod]
609
+ fn hex ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < String > {
610
+ zelf. try_not_released ( vm) ?;
611
+ let guard;
612
+ let vec;
613
+ let bytes = match zelf. as_contiguous ( ) {
614
+ Some ( bytes) => {
615
+ guard = bytes;
616
+ & * guard
617
+ }
618
+ None => {
619
+ vec = zelf. to_contiguous ( ) ;
620
+ vec. as_slice ( )
621
+ }
622
+ } ;
623
+ let s = bytes
624
+ . iter ( )
625
+ . map ( |x| format ! ( "{:02x}" , x) )
626
+ . collect :: < String > ( ) ;
627
+ Ok ( s)
628
+ }
629
+
606
630
fn eq ( zelf : & PyRef < Self > , other : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < bool > {
607
631
if zelf. is ( other) {
608
632
return Ok ( true ) ;
@@ -686,7 +710,8 @@ impl Buffer for PyMemoryViewRef {
686
710
}
687
711
688
712
fn is_resizable ( & self ) -> bool {
689
- self . buffer . is_resizable ( )
713
+ // memoryview cannot resize
714
+ false
690
715
}
691
716
692
717
fn as_contiguous ( & self ) -> Option < BorrowedValue < [ u8 ] > > {
You can’t perform that action at this time.
0 commit comments