File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -598,9 +598,18 @@ mod _struct {
598
598
}
599
599
600
600
#[ pyfunction]
601
- fn unpack ( fmt : PyStringRef , buffer : PyBytesRef , vm : & VirtualMachine ) -> PyResult < PyTuple > {
602
- let fmt_str = fmt. as_str ( ) ;
603
- let format_spec = FormatSpec :: parse ( fmt_str) . map_err ( |e| new_struct_error ( vm, e) ) ?;
601
+ fn unpack (
602
+ fmt : Either < PyStringRef , PyBytesRef > ,
603
+ buffer : PyBytesRef ,
604
+ vm : & VirtualMachine ,
605
+ ) -> PyResult < PyTuple > {
606
+ // FIXME: the given fmt must be parsed as ascii string
607
+ // https://github.com/RustPython/RustPython/pull/1792#discussion_r387340905
608
+ let parsed = match fmt {
609
+ Either :: A ( string) => FormatSpec :: parse ( string. as_str ( ) ) ,
610
+ Either :: B ( bytes) => FormatSpec :: parse ( std:: str:: from_utf8 ( & bytes) . unwrap ( ) ) ,
611
+ } ;
612
+ let format_spec = parsed. map_err ( |e| new_struct_error ( vm, e) ) ?;
604
613
format_spec. unpack ( buffer. get_value ( ) , vm)
605
614
}
606
615
You can’t perform that action at this time.
0 commit comments