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 @@ -221,8 +221,10 @@ impl PyBytes {
221
221
self . inner . swapcase ( ) . into ( )
222
222
}
223
223
224
+ // TODO: Changed in version 3.8: bytes.hex() now supports optional sep and
225
+ // bytes_per_sep parameters to insert separators between bytes in the hex output.
224
226
#[ pymethod( name = "hex" ) ]
225
- fn hex ( & self ) -> String {
227
+ pub ( crate ) fn hex ( & self ) -> String {
226
228
self . inner . hex ( )
227
229
}
228
230
Original file line number Diff line number Diff line change @@ -602,6 +602,30 @@ impl PyMemoryView {
602
602
}
603
603
}
604
604
605
+ // TODO: Changed in version 3.8: memoryview.hex() now supports optional sep and bytes_per_sep
606
+ // parameters to insert separators between bytes in the hex output.
607
+ #[ pymethod]
608
+ fn hex ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < String > {
609
+ zelf. try_not_released ( vm) ?;
610
+ let guard;
611
+ let vec;
612
+ let bytes = match zelf. as_contiguous ( ) {
613
+ Some ( bytes) => {
614
+ guard = bytes;
615
+ & * guard
616
+ }
617
+ None => {
618
+ vec = zelf. to_contiguous ( ) ;
619
+ vec. as_slice ( )
620
+ }
621
+ } ;
622
+ let s = bytes
623
+ . iter ( )
624
+ . map ( |x| format ! ( "{:02x}" , x) )
625
+ . collect :: < String > ( ) ;
626
+ Ok ( s)
627
+ }
628
+
605
629
fn eq ( zelf : & PyRef < Self > , other : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < bool > {
606
630
if zelf. is ( other) {
607
631
return Ok ( true ) ;
@@ -685,7 +709,8 @@ impl Buffer for PyMemoryViewRef {
685
709
}
686
710
687
711
fn is_resizable ( & self ) -> bool {
688
- self . buffer . is_resizable ( )
712
+ // memoryview cannot resize
713
+ false
689
714
}
690
715
691
716
fn as_contiguous ( & self ) -> Option < BorrowedValue < [ u8 ] > > {
You can’t perform that action at this time.
0 commit comments