@@ -375,13 +375,15 @@ def _get_next(
375
375
376
376
# exception to support day of month and day of week as defined in cron
377
377
dom_dow_exception_processed = False
378
- if (expanded [DAY_FIELD ][0 ] != "*" and expanded [DOW_FIELD ][0 ] != "*" ) and self ._day_or :
378
+ if (
379
+ expanded [DAY_FIELD ][0 ] != "*" and expanded [DOW_FIELD ][0 ] != "*"
380
+ ) and self ._day_or :
379
381
# If requested, handle a bug in vixie cron/ISC cron where day_of_month and day_of_week form
380
382
# an intersection (AND) instead of a union (OR) if either field is an asterisk or starts with an asterisk
381
383
# (https://crontab.guru/cron-bug.html)
382
- if (
383
- self ._implement_cron_bug and
384
- ( re_star . match ( self . expressions [ DAY_FIELD ]) or re_star .match (self .expressions [DOW_FIELD ]) )
384
+ if self . _implement_cron_bug and (
385
+ re_star . match ( self .expressions [ DAY_FIELD ])
386
+ or re_star .match (self .expressions [DOW_FIELD ])
385
387
):
386
388
# To produce a schedule identical to the cron bug, we'll bypass the code that
387
389
# makes a union of DOM and DOW, and instead skip to the code that does an intersect instead
@@ -401,36 +403,32 @@ def _get_next(
401
403
dom_dow_exception_processed = True
402
404
403
405
if not dom_dow_exception_processed :
404
- result = self ._calc (self .cur , expanded ,
405
- nth_weekday_of_month , is_prev )
406
+ result = self ._calc (self .cur , expanded , nth_weekday_of_month , is_prev )
406
407
407
408
# DST Handling for cron job spanning across days
408
409
dtstarttime = self ._timestamp_to_datetime (self .dst_start_time )
409
- dtstarttime_utcoffset = (
410
- dtstarttime .utcoffset () or datetime .timedelta (0 ))
410
+ dtstarttime_utcoffset = dtstarttime .utcoffset () or datetime .timedelta (0 )
411
411
dtresult = self ._timestamp_to_datetime (result )
412
412
lag = lag_hours = 0
413
413
# do we trigger DST on next crontab (handle backward changes)
414
414
dtresult_utcoffset = dtstarttime_utcoffset
415
415
if dtresult and self .tzinfo :
416
416
dtresult_utcoffset = dtresult .utcoffset ()
417
- lag_hours = (
418
- self ._timedelta_to_seconds (dtresult - dtstarttime ) / (60 * 60 )
419
- )
420
- lag = self ._timedelta_to_seconds (
421
- dtresult_utcoffset - dtstarttime_utcoffset
422
- )
417
+ lag_hours = self ._timedelta_to_seconds (dtresult - dtstarttime ) / (60 * 60 )
418
+ lag = self ._timedelta_to_seconds (dtresult_utcoffset - dtstarttime_utcoffset )
423
419
hours_before_midnight = 24 - dtstarttime .hour
424
420
if dtresult_utcoffset != dtstarttime_utcoffset :
425
- if (
426
- (lag > 0 and abs (lag_hours ) >= hours_before_midnight )
427
- or (lag < 0 and
428
- ((3600 * abs (lag_hours ) + abs (lag )) >= hours_before_midnight * 3600 ))
421
+ if (lag > 0 and abs (lag_hours ) >= hours_before_midnight ) or (
422
+ lag < 0
423
+ and ((3600 * abs (lag_hours ) + abs (lag )) >= hours_before_midnight * 3600 )
429
424
):
430
425
dtresult_adjusted = dtresult - datetime .timedelta (seconds = lag )
431
426
result_adjusted = self ._datetime_to_timestamp (dtresult_adjusted )
432
427
# Do the actual adjust only if the result time actually exists
433
- if self ._timestamp_to_datetime (result_adjusted ).tzinfo == dtresult_adjusted .tzinfo :
428
+ if (
429
+ self ._timestamp_to_datetime (result_adjusted ).tzinfo
430
+ == dtresult_adjusted .tzinfo
431
+ ):
434
432
dtresult = dtresult_adjusted
435
433
result = result_adjusted
436
434
self .dst_start_time = result
@@ -630,9 +628,8 @@ def proc_day_of_week_nth(d):
630
628
continue
631
629
else :
632
630
candidate = c [n - 1 ]
633
- if (
634
- (is_prev and candidate <= d .day ) or
635
- (not is_prev and d .day <= candidate )
631
+ if (is_prev and candidate <= d .day ) or (
632
+ not is_prev and d .day <= candidate
636
633
):
637
634
candidates .append (candidate )
638
635
@@ -830,9 +827,18 @@ def value_alias(cls, val, field_index, len_expressions=UNIX_CRON_LEN):
830
827
# do not support 0 as a month either for classical 5 fields cron,
831
828
# 6fields second repeat form or 7 fields year form
832
829
# but still let conversion happen if day field is shifted
833
- (field_index in [DAY_FIELD , MONTH_FIELD ] and len_expressions == UNIX_CRON_LEN ) or
834
- (field_index in [MONTH_FIELD , DOW_FIELD ] and len_expressions == SECOND_CRON_LEN ) or
835
- (field_index in [DAY_FIELD , MONTH_FIELD , DOW_FIELD ] and len_expressions == YEAR_CRON_LEN )
830
+ (
831
+ field_index in [DAY_FIELD , MONTH_FIELD ]
832
+ and len_expressions == UNIX_CRON_LEN
833
+ )
834
+ or (
835
+ field_index in [MONTH_FIELD , DOW_FIELD ]
836
+ and len_expressions == SECOND_CRON_LEN
837
+ )
838
+ or (
839
+ field_index in [DAY_FIELD , MONTH_FIELD , DOW_FIELD ]
840
+ and len_expressions == YEAR_CRON_LEN
841
+ )
836
842
):
837
843
val = cls .LOWMAP [field_index ][val ]
838
844
return val
@@ -985,8 +991,8 @@ def _expand(
985
991
986
992
low , high = [cls .value_alias (int (_val ), field_index , expressions ) for _val in (low , high )]
987
993
988
- if (
989
- max ( low , high ) > max ( cls .RANGES [field_index ][0 ], cls .RANGES [field_index ][1 ])
994
+ if max ( low , high ) > max (
995
+ cls .RANGES [field_index ][0 ], cls .RANGES [field_index ][1 ]
990
996
):
991
997
raise CroniterBadCronError (
992
998
"{0} is out of bands" .format (expr_format )
@@ -1015,7 +1021,9 @@ def _expand(
1015
1021
if rng :
1016
1022
already_skipped = list (reversed (whole_field_range )).index (rng [- 1 ])
1017
1023
curpos = whole_field_range .index (rng [- 1 ])
1018
- if ((curpos + step ) > len (whole_field_range )) and (already_skipped < step ):
1024
+ if ((curpos + step ) > len (whole_field_range )) and (
1025
+ already_skipped < step
1026
+ ):
1019
1027
to_skip = step - already_skipped
1020
1028
rng += list (
1021
1029
range (cls .RANGES [field_index ][0 ] + to_skip , high + 1 , step )
@@ -1055,10 +1063,9 @@ def _expand(
1055
1063
1056
1064
t = cls .value_alias (t , field_index , expressions )
1057
1065
1058
- if (
1059
- t not in ["*" , "l" ]
1060
- and (int (t ) < cls .RANGES [field_index ][0 ] or
1061
- int (t ) > cls .RANGES [field_index ][1 ])
1066
+ if t not in ["*" , "l" ] and (
1067
+ int (t ) < cls .RANGES [field_index ][0 ]
1068
+ or int (t ) > cls .RANGES [field_index ][1 ]
1062
1069
):
1063
1070
raise CroniterBadCronError (
1064
1071
"[{0}] is not acceptable, out of range" .format (expr_format )
@@ -1077,9 +1084,8 @@ def _expand(
1077
1084
)
1078
1085
if len (res ) == cls .LEN_MEANS_ALL [field_index ]:
1079
1086
# Make sure the wildcard is used in the correct way (avoid over-optimization)
1080
- if (
1081
- (field_index == DAY_FIELD and "*" not in expressions [DOW_FIELD ]) or
1082
- (field_index == DOW_FIELD and "*" not in expressions [DAY_FIELD ])
1087
+ if (field_index == DAY_FIELD and "*" not in expressions [DOW_FIELD ]) or (
1088
+ field_index == DOW_FIELD and "*" not in expressions [DAY_FIELD ]
1083
1089
):
1084
1090
pass
1085
1091
else :
@@ -1093,7 +1099,10 @@ def _expand(
1093
1099
dow_expanded_set = dow_expanded_set .difference (nth_weekday_of_month .keys ())
1094
1100
dow_expanded_set .discard ("*" )
1095
1101
# Skip: if it's all weeks instead of wildcard
1096
- if dow_expanded_set and len (set (expanded [DOW_FIELD ])) != cls .LEN_MEANS_ALL [DOW_FIELD ]:
1102
+ if (
1103
+ dow_expanded_set
1104
+ and len (set (expanded [DOW_FIELD ])) != cls .LEN_MEANS_ALL [DOW_FIELD ]
1105
+ ):
1097
1106
raise CroniterUnsupportedSyntaxError (
1098
1107
"day-of-week field does not support mixing literal values and nth day of week syntax. "
1099
1108
"Cron: '{}' dow={} vs nth={}" .format (expr_format , dow_expanded_set , nth_weekday_of_month ))
@@ -1258,10 +1267,8 @@ def croniter_range(
1258
1267
_croniter = _croniter or croniter
1259
1268
auto_rt = datetime .datetime
1260
1269
# type is used in first if branch for perfs reasons
1261
- if (
1262
- type (start ) is not type (stop ) and not (
1263
- isinstance (start , type (stop )) or
1264
- isinstance (stop , type (start )))
1270
+ if type (start ) is not type (stop ) and not (
1271
+ isinstance (start , type (stop )) or isinstance (stop , type (start ))
1265
1272
):
1266
1273
raise CroniterBadTypeRangeError (
1267
1274
"The start and stop must be same type. {0} != {1}" .
0 commit comments