File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 34
34
import java .util .ArrayList ;
35
35
import java .util .List ;
36
36
37
+ import com .oracle .graal .python .builtins .objects .ints .PInt ;
37
38
import com .oracle .graal .python .builtins .objects .list .PList ;
38
39
import com .oracle .graal .python .runtime .PythonCore ;
39
40
import com .oracle .graal .python .runtime .sequence .PSequence ;
@@ -74,12 +75,27 @@ public static byte[] fromList(PythonCore core, PList list) {
74
75
Integer integer = (Integer ) item ;
75
76
if (integer >= 0 && integer < 256 ) {
76
77
bytes [i ] = integer .byteValue ();
77
- } else {
78
- throw core .raise (ValueError , "byte must be in range(0, 256)" );
78
+ continue ;
79
79
}
80
+ } else if (item instanceof Long ) {
81
+ Long integer = (Long ) item ;
82
+ if (integer >= 0 && integer < 256 ) {
83
+ bytes [i ] = integer .byteValue ();
84
+ continue ;
85
+ }
86
+ } else if (item instanceof PInt ) {
87
+ try {
88
+ long integer = ((PInt ) item ).intValueExact ();
89
+ if (integer >= 0 && integer < 256 ) {
90
+ bytes [i ] = (byte ) integer ;
91
+ }
92
+ } catch (ArithmeticException e ) {
93
+ }
94
+ continue ;
80
95
} else {
81
96
throw core .raise (TypeError , "'%s' object cannot be interpreted as an integer" , core .lookupType (item .getClass ()));
82
97
}
98
+ throw core .raise (ValueError , "byte must be in range(0, 256)" );
83
99
}
84
100
return bytes ;
85
101
}
You can’t perform that action at this time.
0 commit comments