77
77
import com .oracle .truffle .api .TruffleOptions ;
78
78
import com .oracle .truffle .api .dsl .Cached ;
79
79
import com .oracle .truffle .api .dsl .Cached .Shared ;
80
+ import com .oracle .truffle .api .dsl .Fallback ;
80
81
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
81
82
import com .oracle .truffle .api .dsl .NodeFactory ;
82
83
import com .oracle .truffle .api .dsl .Specialization ;
@@ -521,8 +522,8 @@ protected static int[] checkStructtime(PTuple time,
521
522
CastToJavaIntExactNode toJavaIntExact ,
522
523
PRaiseNode raise ) {
523
524
Object [] otime = getInternalObjectArrayNode .execute (time .getSequenceStorage ());
524
- if (lenNode .execute (time .getSequenceStorage ()) < 9 ) {
525
- throw raise .raise (TypeError , ErrorMessages .FUNC_TAKES_AT_LEAST_D_ARGS , 9 , otime . length );
525
+ if (lenNode .execute (time .getSequenceStorage ()) != 9 ) {
526
+ throw raise .raise (TypeError , ErrorMessages .S_ILLEGAL_TIME_TUPLE_ARG , "asctime()" );
526
527
}
527
528
int [] date = new int [9 ];
528
529
for (int i = 0 ; i < 9 ; i ++) {
@@ -531,7 +532,7 @@ protected static int[] checkStructtime(PTuple time,
531
532
532
533
// This is specific to java
533
534
if (date [TM_YEAR ] < Year .MIN_VALUE || date [TM_YEAR ] > Year .MAX_VALUE ) {
534
- throw raise .raise (ValueError , "year out of range" );
535
+ throw raise .raise (OverflowError , "year out of range" );
535
536
}
536
537
537
538
if (date [TM_MON ] == 0 ) {
@@ -817,6 +818,9 @@ private static String format(String format, int[] date) {
817
818
818
819
@ Specialization
819
820
public String formatTime (String format , @ SuppressWarnings ("unused" ) PNone time ) {
821
+ if (format .indexOf (0 ) > -1 ) {
822
+ throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_CHARACTER );
823
+ }
820
824
return format (format , getIntLocalTimeStruct ((long ) timeSeconds ()));
821
825
}
822
826
@@ -826,6 +830,9 @@ public String formatTime(String format, PTuple time,
826
830
@ Cached SequenceStorageNodes .LenNode lenNode ,
827
831
@ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
828
832
@ Cached CastToJavaIntExactNode castToInt ) {
833
+ if (format .indexOf (0 ) > -1 ) {
834
+ throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_CHARACTER );
835
+ }
829
836
int [] date = checkStructtime (time , getArray , lenNode , lib , castToInt , getRaiseNode ());
830
837
return format (format , date );
831
838
}
@@ -921,6 +928,11 @@ public String localtime(PTuple time,
921
928
return format (StrfTimeNode .checkStructtime (time , getArray , lenNode , asPIntLib , toJavaIntExact , getRaiseNode ()));
922
929
}
923
930
931
+ @ Fallback
932
+ public Object localtime (@ SuppressWarnings ("unused" ) Object time ) {
933
+ throw raise (TypeError , ErrorMessages .TUPLE_OR_STRUCT_TIME_ARG_REQUIRED );
934
+ }
935
+
924
936
protected static String format (int [] tm ) {
925
937
return format (CTIME_FORMAT , tm );
926
938
}
0 commit comments