7777import com .oracle .truffle .api .TruffleOptions ;
7878import com .oracle .truffle .api .dsl .Cached ;
7979import com .oracle .truffle .api .dsl .Cached .Shared ;
80+ import com .oracle .truffle .api .dsl .Fallback ;
8081import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
8182import com .oracle .truffle .api .dsl .NodeFactory ;
8283import com .oracle .truffle .api .dsl .Specialization ;
@@ -521,8 +522,8 @@ protected static int[] checkStructtime(PTuple time,
521522 CastToJavaIntExactNode toJavaIntExact ,
522523 PRaiseNode raise ) {
523524 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()" );
526527 }
527528 int [] date = new int [9 ];
528529 for (int i = 0 ; i < 9 ; i ++) {
@@ -531,7 +532,7 @@ protected static int[] checkStructtime(PTuple time,
531532
532533 // This is specific to java
533534 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" );
535536 }
536537
537538 if (date [TM_MON ] == 0 ) {
@@ -817,6 +818,9 @@ private static String format(String format, int[] date) {
817818
818819 @ Specialization
819820 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+ }
820824 return format (format , getIntLocalTimeStruct ((long ) timeSeconds ()));
821825 }
822826
@@ -826,6 +830,9 @@ public String formatTime(String format, PTuple time,
826830 @ Cached SequenceStorageNodes .LenNode lenNode ,
827831 @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
828832 @ Cached CastToJavaIntExactNode castToInt ) {
833+ if (format .indexOf (0 ) > -1 ) {
834+ throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_CHARACTER );
835+ }
829836 int [] date = checkStructtime (time , getArray , lenNode , lib , castToInt , getRaiseNode ());
830837 return format (format , date );
831838 }
@@ -921,6 +928,11 @@ public String localtime(PTuple time,
921928 return format (StrfTimeNode .checkStructtime (time , getArray , lenNode , asPIntLib , toJavaIntExact , getRaiseNode ()));
922929 }
923930
931+ @ Fallback
932+ public Object localtime (@ SuppressWarnings ("unused" ) Object time ) {
933+ throw raise (TypeError , ErrorMessages .TUPLE_OR_STRUCT_TIME_ARG_REQUIRED );
934+ }
935+
924936 protected static String format (int [] tm ) {
925937 return format (CTIME_FORMAT , tm );
926938 }
0 commit comments