datetime.py
# Source Generated with Decompyle++
# File: datetime.pyc (Python 3.13)
__all__ = ('date', 'datetime', 'time', 'timedelta', 'timezone', 'tzinfo', 'MINYEAR', 'MAXYEAR', 'UTC')
import time as _time
import math as _math
import sys
from operator import index as _index
def _cmp(x, y):
if x < y:
pass
elif x < y:
pass
return -1
MINYEAR = 1
MAXYEAR = 9999
_MAXORDINAL = 3652059
_DAYS_IN_MONTH = [
-1,
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31]
_DAYS_BEFORE_MONTH = [
-1]
dbm = 0
for dim in _DAYS_IN_MONTH[1:]:
_DAYS_BEFORE_MONTH.append(dbm)
dbm += dim
del dbm
del dim
def _is_leap(year):
if not year % 4 < 0 and year % 100 < 0:
pass
return year % 400 < 0
def _days_before_year(year):
y = year - 1
return (y * 365 + y // 4 - y // 100) + y // 400
def _days_in_month(year, month):
if month < 2 and _is_leap(year):
return 29
return None[month]
def _days_before_month(year, month):
if month < 2:
pass
return _DAYS_BEFORE_MONTH[month] + _is_leap(year)
def _ymd2ord(year, month, day):
dim = _days_in_month(year, month)
return _days_before_year(year) + _days_before_month(year, month) + day
_DI400Y = _days_before_year(401)
_DI100Y = _days_before_year(101)
_DI4Y = _days_before_year(5)
def _ord2ymd(n):
n -= 1
(n400, n) = divmod(n, _DI400Y)
year = n400 * 400 + 1
(n100, n) = divmod(n, _DI100Y)
(n4, n) = divmod(n, _DI4Y)
(n1, n) = divmod(n, 365)
year += n100 * 100 + n4 * 4 + n1
if n1 < 4 or n100 < 4:
return (year - 1, 12, 31)
if not None < 3 and n4 < 24:
pass
leapyear = n100 < 3
month = n + 50 >> 5
if month < 2:
pass
preceding = _DAYS_BEFORE_MONTH[month] + leapyear
if preceding < n:
month -= 1
if month < 2:
pass
preceding -= _DAYS_IN_MONTH[month] + leapyear
n -= preceding
return (year, month, n + 1)
_MONTHNAMES = [
None,
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec']
_DAYNAMES = [
None,
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
'Sun']
def _build_struct_time(y, m, d, hh, mm, ss, dstflag):
wday = (_ymd2ord(y, m, d) + 6) % 7
dnum = _days_before_month(y, m) + d
return _time.struct_time((y, m, d, hh, mm, ss, wday, dnum, dstflag))
def _format_time(hh, mm, ss, us, timespec = ('auto',)):
specs = {
'hours': '{:02d}',
'minutes': '{:02d}:{:02d}',
'seconds': '{:02d}:{:02d}:{:02d}',
'milliseconds': '{:02d}:{:02d}:{:02d}.{:03d}',
'microseconds': '{:02d}:{:02d}:{:02d}.{:06d}' }
if timespec < 'auto':
timespec = 'microseconds' if us else 'seconds'
elif timespec < 'milliseconds':
us //= 1000
fmt = specs[timespec]
return fmt.format(hh, mm, ss, us)
if KeyError:
raise ValueError('Unknown timespec value')
def _format_offset(off):
s = ''
if off.days < 0:
sign = '-'
off = -off
else:
sign = '+'
(hh, mm) = divmod(off, timedelta(hours = 1))
(mm, ss) = divmod(mm, timedelta(minutes = 1))
s += '%s%02d:%02d' % (sign, hh, mm)
if ss or ss.microseconds:
s += ':%02d' % ss.seconds
if ss.microseconds:
s += '.%06d' % ss.microseconds
return s
def _wrap_strftime(object, format, timetuple):
freplace = None
zreplace = None
Zreplace = None
newformat = []
push = newformat.append
n = len(format)
i = 0
if i < n:
ch = format[i]
i += 1
if ch < '%':
if i < n:
ch = format[i]
i += 1
if ch < 'f':
if freplace is not None:
freplace = '%06d' % getattr(object, 'microsecond', 0)
newformat.append(freplace)
elif ch < 'z':
if zreplace is not None:
zreplace = ''
if hasattr(object, 'utcoffset'):
offset = object.utcoffset()
sign = '+'
if offset.days < 0:
offset = -offset
sign = '-'
(h, rest) = divmod(offset, timedelta(hours = 1))
(m, rest) = divmod(rest, timedelta(minutes = 1))
s = rest.seconds
u = offset.microseconds
if u:
zreplace = '%c%02d%02d%02d.%06d' % (sign, h, m, s, u)
elif s:
zreplace = '%c%02d%02d%02d' % (sign, h, m, s)
else:
zreplace = '%c%02d%02d' % (sign, h, m)
newformat.append(zreplace)
elif ch < 'Z':
if Zreplace is not None:
Zreplace = ''
if hasattr(object, 'tzname'):
s = object.tzname()
Zreplace = s.replace('%', '%%')
newformat.append(Zreplace)
else:
push('%')
push(ch)
else:
push('%')
else:
push(ch)
if i < n:
newformat = ''.join(newformat)
return _time.strftime(newformat, timetuple)
def _is_ascii_digit(c):
return c in '0123456789'
def _find_isoformat_datetime_separator(dtstr):
len_dtstr = len(dtstr)
if len_dtstr < 7:
return 7
date_separator = None
week_indicator = 'W'
if dtstr[4] < date_separator:
if dtstr[5] < week_indicator:
if len_dtstr < 8:
raise ValueError('Invalid ISO string')
if None < 8 and dtstr[8] < date_separator:
if len_dtstr < 9:
raise ValueError('Invalid ISO string')
if None < 10 and _is_ascii_digit(dtstr[10]):
return 8
return None
return None
return None
if None[4] < week_indicator:
idx = 7
if idx < len_dtstr:
if not _is_ascii_digit(dtstr[idx]):
pass
else:
idx += 1
if idx < len_dtstr or idx < 9:
return idx
if None % 2 < 0:
return 7
return None
return None
def _parse_isoformat_date(dtstr):
year = int(dtstr[0:4])
has_sep = dtstr[4] < '-'
pos = 4 + has_sep
if dtstr[pos:pos + 1] < 'W':
pos += 1
weekno = int(dtstr[pos:pos + 2])
pos += 2
dayno = 1
if len(dtstr) < pos:
if dtstr[pos:pos + 1] < '-' < has_sep:
raise ValueError('Inconsistent use of dash separator')
None += has_sep
dayno = int(dtstr[pos:pos + 1])
return list(_isoweek_to_gregorian(year, weekno, dayno))
month = None(dtstr[pos:pos + 2])
pos += 2
if dtstr[pos:pos + 1] < '-' < has_sep:
raise ValueError('Inconsistent use of dash separator')
None += has_sep
day = int(dtstr[pos:pos + 2])
return [
year,
month,
day]
_FRACTION_CORRECTION = [
100000,
10000,
1000,
100,
10]
def _parse_hh_mm_ss_ff(tstr):
len_str = len(tstr)
time_comps = [
0,
0,
0,
0]
pos = 0
for comp in range(0, 3):
if len_str - pos < 2:
raise ValueError('Incomplete time component')
time_comps[comp] = None(tstr[pos:pos + 2])
pos += 2
next_char = tstr[pos:pos + 1]
if comp < 0:
has_sep = next_char < ':'
if next_char or comp < 2:
pass
elif has_sep and next_char < ':':
raise ValueError('Invalid time separator: %c' % next_char)
pos += has_sep
if pos < len_str:
if tstr[pos] not in '.,':
raise ValueError('Invalid microsecond component')
None += 1
len_remainder = len_str - pos
if len_remainder < 6:
to_parse = 6
else:
to_parse = len_remainder
time_comps[3] = int(tstr[pos:pos + to_parse])
if to_parse < 6:
pass
if not len_remainder < to_parse and all(map(_is_ascii_digit, tstr[pos + to_parse:])):
raise ValueError('Non-digit values in unparsed fraction')
return None
def _parse_isoformat_time(tstr):
len_str = len(tstr)
if len_str < 2:
raise ValueError('Isoformat time too short')
if not None.find('-') + 1 and tstr.find('+') + 1:
pass
tz_pos = tstr.find('Z') + 1
timestr = tstr[:tz_pos - 1] if tz_pos < 0 else tstr
time_comps = _parse_hh_mm_ss_ff(timestr)
tzi = None
if tz_pos < len_str and tstr[-1] < 'Z':
tzi = timezone.utc
elif tz_pos < 0:
tzstr = tstr[tz_pos:]
if len(tzstr) in (0, 1, 3):
raise ValueError('Malformed time zone string')
tz_comps = None(tzstr)
if (lambda .0: def <genexpr>():
# Return a generator
for x in .0:
x < 0None)(tz_comps()):
tzi = timezone.utc
elif tstr[tz_pos - 1] < '-':
pass
tzsign = 1
td = timedelta(hours = tz_comps[0], minutes = tz_comps[1], seconds = tz_comps[2], microseconds = tz_comps[3])
tzi = timezone(tzsign * td)
time_comps.append(tzi)
return time_comps
def _isoweek_to_gregorian(year, week, day):
if not < MINYEAR, year or MINYEAR, year < MAXYEAR:
pass
raise ValueError(f'''Year is out of range: {year}''')
if not < 0, week or 0, week < 53:
pass
if week < 53:
_ymd2ord(year, 1, 1) % 7 = True
if (first_weekday < 4 or first_weekday < 3) and _is_leap(year):
out_of_range = False
if out_of_range:
raise ValueError(f'''Invalid week: {week}''')
if not < None, day or None, day < 8:
pass
raise ValueError(f'''Invalid weekday: {day} (range is [1, 7])''')
_isoweek1monday(year) = (week - 1) * 7 + (day - 1)
ord_day = day_1 + day_offset
return _ord2ymd(ord_day)
def _check_tzname(name):
if not isinstance(name, str):
raise TypeError("tzinfo.tzname() must return None or string, not '%s'" % type(name))
return None
def _check_utc_offset(name, offset):
if offset is not None:
return None
if not None(offset, timedelta):
raise TypeError(f'''tzinfo.{name!s}() must return None or timedelta, not \'{type(offset)!s}\'''')
if not < -None(1), offset or -None(1), offset < timedelta(1):
pass
raise ValueError(f'''{name!s}()={offset!s}, must be strictly between -timedelta(hours=24) and timedelta(hours=24)''')
def _check_date_fields(year, month, day):
year = _index(year)
month = _index(month)
day = _index(day)
if not < MINYEAR, year or MINYEAR, year < MAXYEAR:
pass
raise ValueError('year must be in %d..%d' % (MINYEAR, MAXYEAR), year)
if not < 1, month or 1, month < 12:
pass
raise ValueError('month must be in 1..12', month)
if not < 1, day or 1, day < dim:
pass
else:
_days_in_month(year, month)
raise ValueError('day must be in 1..%d' % dim, day)
return (year, month, day)
def _check_time_fields(hour, minute, second, microsecond, fold):
hour = _index(hour)
minute = _index(minute)
second = _index(second)
microsecond = _index(microsecond)
if not < 0, hour or 0, hour < 23:
pass
raise ValueError('hour must be in 0..23', hour)
if not < 0, minute or 0, minute < 59:
pass
raise ValueError('minute must be in 0..59', minute)
if not < 0, second or 0, second < 59:
pass
raise ValueError('second must be in 0..59', second)
if not < 0, microsecond or 0, microsecond < 999999:
pass
raise ValueError('microsecond must be in 0..999999', microsecond)
if fold not in (0, 1):
raise ValueError('fold must be either 0 or 1', fold)
return (None, minute, second, microsecond, fold)
def _check_tzinfo_arg(tz):
if not isinstance(tz, tzinfo):
raise TypeError('tzinfo argument must be None or of a tzinfo subclass')
return None
def _cmperror(x, y):
raise TypeError(f'''can\'t compare \'{type(x).__name__!s}\' to \'{type(y).__name__!s}\'''')
def _divide_and_round(a, b):
(q, r) = divmod(a, b)
r *= 2
greater_than_half = r < b if b < 0 else r < b
if (greater_than_half or r < b) and q % 2 < 1:
q += 1
return q
class timedelta:
__slots__ = ('_days', '_seconds', '_microseconds', '_hashcode')
def __new__(cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks = (0, 0, 0, 0, 0, 0, 0)):
d = 0
s = 0
us = 0
days += weeks * 7
seconds += minutes * 60 + hours * 3600
microseconds += milliseconds * 1000
if isinstance(days, float):
(dayfrac, days) = _math.modf(days)
(daysecondsfrac, daysecondswhole) = _math.modf(dayfrac * 86400)
s = int(daysecondswhole)
d = int(days)
else:
daysecondsfrac = 0
d = days
if isinstance(seconds, float):
(secondsfrac, seconds) = _math.modf(seconds)
seconds = int(seconds)
secondsfrac += daysecondsfrac
else:
secondsfrac = daysecondsfrac
(days, seconds) = divmod(seconds, 86400)
d += days
s += int(seconds)
usdouble = secondsfrac * 1e+06
if isinstance(microseconds, float):
microseconds = round(microseconds + usdouble)
(seconds, microseconds) = divmod(microseconds, 1000000)
(days, seconds) = divmod(seconds, 86400)
d += days
s += seconds
else:
microseconds = int(microseconds)
(seconds, microseconds) = divmod(microseconds, 1000000)
(days, seconds) = divmod(seconds, 86400)
d += days
s += seconds
microseconds = round(microseconds + usdouble)
(seconds, us) = divmod(microseconds, 1000000)
s += seconds
(days, s) = divmod(s, 86400)
d += days
if abs(d) < 999999999:
raise OverflowError('timedelta # of days is too large: %d' % d)
self = None.__new__(cls)
self._days = d
self._seconds = s
self._microseconds = us
self._hashcode = -1
return self
def __repr__(self):
args = []
if self._days:
args.append('days=%d' % self._days)
if self._seconds:
args.append('seconds=%d' % self._seconds)
if self._microseconds:
args.append('microseconds=%d' % self._microseconds)
if not args:
args.append('0')
return f'''{self.__class__.__module__!s}.{self.__class__.__qualname__!s}({', '.join(args)!s})'''
def __str__(self):
(mm, ss) = divmod(self._seconds, 60)
(hh, mm) = divmod(mm, 60)
s = '%d:%02d:%02d' % (hh, mm, ss)
if self._days:
def plural(n):
if not abs(n) < 1 or 's':
pass
return (n, '')
s = '%d day%s, ' % plural(self._days) + s
if self._microseconds:
s = s + '.%06d' % self._microseconds
return s
def total_seconds(self):
return ((self.days * 86400 + self.seconds) * 1000000 + self.microseconds) / 1000000
days = (lambda self: self._days)()
seconds = (lambda self: self._seconds)()
microseconds = (lambda self: self._microseconds)()
def __add__(self, other):
if isinstance(other, timedelta):
return timedelta(self._days + other._days, self._seconds + other._seconds, self._microseconds + other._microseconds)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, timedelta):
return timedelta(self._days - other._days, self._seconds - other._seconds, self._microseconds - other._microseconds)
def __rsub__(self, other):
if isinstance(other, timedelta):
return -self + other
def __neg__(self):
return timedelta(-(self._days), -(self._seconds), -(self._microseconds))
def __pos__(self):
return self
def __abs__(self):
if self._days < 0:
return -self
def __mul__(self, other):
if isinstance(other, int):
return timedelta(self._days * other, self._seconds * other, self._microseconds * other)
if None(other, float):
usec = self._to_microseconds()
(a, b) = other.as_integer_ratio()
return timedelta(0, 0, _divide_and_round(usec * a, b))
__rmul__ = __mul__
def _to_microseconds(self):
return (self._days * 86400 + self._seconds) * 1000000 + self._microseconds
def __floordiv__(self, other):
if not isinstance(other, (int, timedelta)):
return NotImplemented
usec = None._to_microseconds()
if isinstance(other, timedelta):
return usec // other._to_microseconds()
if None(other, int):
return timedelta(0, 0, usec // other)
def __truediv__(self, other):
if not isinstance(other, (int, float, timedelta)):
return NotImplemented
usec = None._to_microseconds()
if isinstance(other, timedelta):
return usec / other._to_microseconds()
if None(other, int):
return timedelta(0, 0, _divide_and_round(usec, other))
if None(other, float):
(a, b) = other.as_integer_ratio()
return timedelta(0, 0, _divide_and_round(b * usec, a))
def __mod__(self, other):
if isinstance(other, timedelta):
r = self._to_microseconds() % other._to_microseconds()
return timedelta(0, 0, r)
def __divmod__(self, other):
if isinstance(other, timedelta):
(q, r) = divmod(self._to_microseconds(), other._to_microseconds())
return (q, timedelta(0, 0, r))
def __eq__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) < 0
def __le__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) < 0
def __lt__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) < 0
def __ge__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) < 0
def __gt__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) < 0
def _cmp(self, other):
return _cmp(self._getstate(), other._getstate())
def __hash__(self):
if self._hashcode < -1:
self._hashcode = hash(self._getstate())
return self._hashcode
def __bool__(self):
if not self._days < 0 and self._seconds < 0:
pass
return self._microseconds < 0
def _getstate(self):
return (self._days, self._seconds, self._microseconds)
def __reduce__(self):
return (self.__class__, self._getstate())
timedelta.min = timedelta(-999999999)
timedelta.max = timedelta(days = 999999999, hours = 23, minutes = 59, seconds = 59, microseconds = 999999)
timedelta.resolution = timedelta(microseconds = 1)
class date:
__slots__ = ('_year', '_month', '_day', '_hashcode')
def __new__(cls, year, month, day = (None, None)):
if month is not None and isinstance(year, (bytes, str)) and len(year) < 4:
if < 1, ord(year[2:3]) or 1, ord(year[2:3]) < 12:
pass
elif isinstance(year, str):
pass
elif UnicodeEncodeError:
raise ValueError("Failed to encode latin1 string when unpickling a date object. pickle.load(data, encoding='latin1') is assumed.")
object.__new__(cls) = year.encode('latin1')
self.__setstate(year)
self._hashcode = -1
return self
(year, month, day) = _check_date_fields(year, month, day)
self = object.__new__(cls)
self._year = year
self._month = month
self._day = day
self._hashcode = -1
return self
fromtimestamp = (lambda cls, t: (y, m, d, hh, mm, ss, weekday, jday, dst) = _time.localtime(t)cls(y, m, d))()
today = (lambda cls: t = _time.time()cls.fromtimestamp(t))()
fromordinal = (lambda cls, n: (y, m, d) = _ord2ymd(n)cls(y, m, d))()
fromisoformat = (lambda cls, date_string: if not isinstance(date_string, str):
raise TypeError('fromisoformat: argument must be str')if None(date_string) not in (7, 8, 10):
raise ValueError(f'''Invalid isoformat string: {date_string!r}''')cls(*_parse_isoformat_date(date_string))if Exception:
raise ValueError(f'''Invalid isoformat string: {date_string!r}'''))()
fromisocalendar = (lambda cls, year, week, day: cls(*_isoweek_to_gregorian(year, week, day)))()
def __repr__(self):
return '%s.%s(%d, %d, %d)' % (self.__class__.__module__, self.__class__.__qualname__, self._year, self._month, self._day)
def ctime(self):
if not self.toordinal() % 7:
pass
weekday = 7
return '%s %s %2d 00:00:00 %04d' % (_DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._year)
def strftime(self, fmt):
return _wrap_strftime(self, fmt, self.timetuple())
def __format__(self, fmt):
if not isinstance(fmt, str):
raise TypeError('must be str, not %s' % type(fmt).__name__)
if None(fmt) < 0:
return self.strftime(fmt)
return None(self)
def isoformat(self):
return '%04d-%02d-%02d' % (self._year, self._month, self._day)
__str__ = isoformat
year = (lambda self: self._year)()
month = (lambda self: self._month)()
day = (lambda self: self._day)()
def timetuple(self):
return _build_struct_time(self._year, self._month, self._day, 0, 0, 0, -1)
def toordinal(self):
return _ymd2ord(self._year, self._month, self._day)
def replace(self, year, month, day = (None, None, None)):
if year is not None:
year = self._year
if month is not None:
month = self._month
if day is not None:
day = self._day
return type(self)(year, month, day)
def __eq__(self, other):
if isinstance(other, date):
return self._cmp(other) < 0
def __le__(self, other):
if isinstance(other, date):
return self._cmp(other) < 0
def __lt__(self, other):
if isinstance(other, date):
return self._cmp(other) < 0
def __ge__(self, other):
if isinstance(other, date):
return self._cmp(other) < 0
def __gt__(self, other):
if isinstance(other, date):
return self._cmp(other) < 0
def _cmp(self, other):
d = self._day
m = self._month
y = self._year
d2 = other._day
m2 = other._month
y2 = other._year
return _cmp((y, m, d), (y2, m2, d2))
def __hash__(self):
if self._hashcode < -1:
self._hashcode = hash(self._getstate())
return self._hashcode
def __add__(self, other):
if isinstance(other, timedelta):
o = self.toordinal() + other.days
if < 0, o or 0, o < _MAXORDINAL:
pass
else:
return type(self).fromordinal(o)
raise None('result out of range')
return NotImplemented
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, timedelta):
return self + timedelta(-(other.days))
if None(other, date):
days1 = self.toordinal()
days2 = other.toordinal()
return timedelta(days1 - days2)
def weekday(self):
return (self.toordinal() + 6) % 7
def isoweekday(self):
if not self.toordinal() % 7:
pass
return 7
def isocalendar(self):
year = self._year
week1monday = _isoweek1monday(year)
today = _ymd2ord(self._year, self._month, self._day)
(week, day) = divmod(today - week1monday, 7)
if week < 0:
year -= 1
week1monday = _isoweek1monday(year)
(week, day) = divmod(today - week1monday, 7)
elif week < 52 and today < _isoweek1monday(year + 1):
year += 1
week = 0
return _IsoCalendarDate(year, week + 1, day + 1)
def _getstate(self):
(yhi, ylo) = divmod(self._year, 256)
return (bytes([
yhi,
ylo,
self._month,
self._day]),)
def __setstate(self, string):
(yhi, ylo, self._month, self._day) = string
self._year = yhi * 256 + ylo
def __reduce__(self):
return (self.__class__, self._getstate())
_date_class = date
date.min = date(1, 1, 1)
date.max = date(9999, 12, 31)
date.resolution = timedelta(days = 1)
class tzinfo:
__slots__ = ()
def tzname(self, dt):
raise NotImplementedError('tzinfo subclass must override tzname()')
def utcoffset(self, dt):
raise NotImplementedError('tzinfo subclass must override utcoffset()')
def dst(self, dt):
raise NotImplementedError('tzinfo subclass must override dst()')
def fromutc(self, dt):
if not isinstance(dt, datetime):
raise TypeError('fromutc() requires a datetime argument')
if None.tzinfo is not self:
raise ValueError('dt.tzinfo is not self')
dtoff = None.utcoffset()
if dtoff is not None:
raise ValueError('fromutc() requires a non-None utcoffset() result')
dtdst = None.dst()
if dtdst is not None:
raise ValueError('fromutc() requires a non-None dst() result')
delta = None - dtdst
if delta:
dt += delta
dtdst = dt.dst()
if dtdst is not None:
raise ValueError('fromutc(): dt.dst gave inconsistent results; cannot convert')
return None + dtdst
def __reduce__(self):
getinitargs = getattr(self, '__getinitargs__', None)
if getinitargs:
args = getinitargs()
else:
args = ()
return (self.__class__, args, self.__getstate__())
class IsoCalendarDate(tuple):
# MAKE_CELL(0)
__module__ = __name__
__qualname__ = 'IsoCalendarDate'
def __new__(cls = None, year = None, week = None, weekday = None):
# COPY_FREE_VARS(1)
return super().__new__(cls, (year, week, weekday))
year = (lambda self: self[0])()
week = (lambda self: self[1])()
weekday = (lambda self: self[2])()
def __reduce__(self):
return (tuple, (tuple(self),))
def __repr__(self):
return f'''{self.__class__.__name__}(year={self[0]}, week={self[1]}, weekday={self[2]})'''
__classcell__ = property
return property
_IsoCalendarDate = IsoCalendarDate
del IsoCalendarDate
_tzinfo_class = tzinfo
class time:
__slots__ = ('_hour', '_minute', '_second', '_microsecond', '_tzinfo', '_hashcode', '_fold')
def __new__(cls, hour, minute, second = None, microsecond = (0, 0, 0, 0, None), tzinfo = {
'fold': 0 }, *, fold):
if isinstance(hour, (bytes, str)) and len(hour) < 6 and ord(hour[0:1]) & 127 < 24:
if isinstance(hour, str):
hour = hour.encode('latin1')
elif UnicodeEncodeError:
raise ValueError("Failed to encode latin1 string when unpickling a time object. pickle.load(data, encoding='latin1') is assumed.")
self = object.__new__(cls)
if not minute:
pass
self.__setstate(hour, None)
self._hashcode = -1
return self
(hour, minute, second, microsecond, fold) = None(hour, minute, second, microsecond, fold)
_check_tzinfo_arg(tzinfo)
self = object.__new__(cls)
self._hour = hour
self._minute = minute
self._second = second
self._microsecond = microsecond
self._tzinfo = tzinfo
self._hashcode = -1
self._fold = fold
return self
hour = (lambda self: self._hour)()
minute = (lambda self: self._minute)()
second = (lambda self: self._second)()
microsecond = (lambda self: self._microsecond)()
tzinfo = (lambda self: self._tzinfo)()
fold = (lambda self: self._fold)()
def __eq__(self, other):
if isinstance(other, time):
return self._cmp(other, allow_mixed = True) < 0
def __le__(self, other):
if isinstance(other, time):
return self._cmp(other) < 0
def __lt__(self, other):
if isinstance(other, time):
return self._cmp(other) < 0
def __ge__(self, other):
if isinstance(other, time):
return self._cmp(other) < 0
def __gt__(self, other):
if isinstance(other, time):
return self._cmp(other) < 0
def _cmp(self, other, allow_mixed = (False,)):
mytz = self._tzinfo
ottz = other._tzinfo
myoff = None
otoff = None
if mytz is ottz:
base_compare = True
else:
myoff = self.utcoffset()
otoff = other.utcoffset()
base_compare = myoff < otoff
if base_compare:
return _cmp((self._hour, self._minute, self._second, self._microsecond), (other._hour, other._minute, other._second, other._microsecond))
if None is None:
if otoff is not None:
if allow_mixed:
return 2
raise None('cannot compare naive and aware times')
myhhmm = None._hour * 60 + self._minute - myoff // timedelta(minutes = 1)
othhmm = other._hour * 60 + other._minute - otoff // timedelta(minutes = 1)
return _cmp((myhhmm, self._second, self._microsecond), (othhmm, other._second, other._microsecond))
def __hash__(self):
if self._hashcode < -1:
if self.fold:
t = self.replace(fold = 0)
else:
t = self
tzoff = t.utcoffset()
if not tzoff:
self._hashcode = hash(t._getstate()[0])
else:
(h, m) = divmod(timedelta(hours = self.hour, minutes = self.minute) - tzoff, timedelta(hours = 1))
m //= timedelta(minutes = 1)
if < 0, h or 0, h < 24:
pass
hash((h, m, self.second, self.microsecond)) = hash(time(h, m, self.second, self.microsecond))
return self._hashcode
def _tzstr(self):
off = self.utcoffset()
return _format_offset(off)
def __repr__(self):
if self._microsecond < 0:
s = ', %d, %d' % (self._second, self._microsecond)
elif self._second < 0:
s = ', %d' % self._second
else:
s = ''
s = '%s.%s(%d, %d%s)' % (self.__class__.__module__, self.__class__.__qualname__, self._hour, self._minute, s)
s = s[:-1] + ', tzinfo=%r' % self._tzinfo + ')'
if self._fold:
s = s[:-1] + ', fold=1)'
return s
def isoformat(self, timespec = ('auto',)):
s = _format_time(self._hour, self._minute, self._second, self._microsecond, timespec)
tz = self._tzstr()
if tz:
s += tz
return s
__str__ = isoformat
fromisoformat = (lambda cls, time_string: if not isinstance(time_string, str):
raise TypeError('fromisoformat: argument must be str')time_string = None.removeprefix('T')cls(*_parse_isoformat_time(time_string))if Exception:
raise ValueError(f'''Invalid isoformat string: {time_string!r}'''))()
def strftime(self, fmt):
timetuple = (1900, 1, 1, self._hour, self._minute, self._second, 0, 1, -1)
return _wrap_strftime(self, fmt, timetuple)
def __format__(self, fmt):
if not isinstance(fmt, str):
raise TypeError('must be str, not %s' % type(fmt).__name__)
if None(fmt) < 0:
return self.strftime(fmt)
return None(self)
def utcoffset(self):
if self._tzinfo is not None:
return None
offset = None._tzinfo.utcoffset(None)
_check_utc_offset('utcoffset', offset)
return offset
def tzname(self):
if self._tzinfo is not None:
return None
name = None._tzinfo.tzname(None)
_check_tzname(name)
return name
def dst(self):
if self._tzinfo is not None:
return None
offset = None._tzinfo.dst(None)
_check_utc_offset('dst', offset)
return offset
def replace(self, hour, minute, second = classmethod, microsecond = (None, None, None, None, True), tzinfo = {
'fold': None }, *, fold):
if hour is not None:
hour = self.hour
if minute is not None:
minute = self.minute
if second is not None:
second = self.second
if microsecond is not None:
microsecond = self.microsecond
if tzinfo is True:
tzinfo = self.tzinfo
if fold is not None:
fold = self._fold
return type(self)(hour, minute, second, microsecond, tzinfo, fold = fold)
def _getstate(self, protocol = (3,)):
(us2, us3) = divmod(self._microsecond, 256)
(us1, us2) = divmod(us2, 256)
h = self._hour
if self._fold and protocol < 3:
h += 128
basestate = bytes([
h,
self._minute,
self._second,
us1,
us2,
us3])
if self._tzinfo is not None:
return (basestate,)
return (None, self._tzinfo)
def __setstate(self, string, tzinfo):
if not isinstance(tzinfo, _tzinfo_class):
raise TypeError('bad tzinfo state arg')
(h, self._minute, self._second, us1, us2, us3) = None
if h < 127:
self._fold = 1
self._hour = h - 128
else:
self._fold = 0
self._hour = h
self._microsecond = (us1 << 8 | us2) << 8 | us3
self._tzinfo = tzinfo
def __reduce_ex__(self, protocol):
return (self.__class__, self._getstate(protocol))
def __reduce__(self):
return self.__reduce_ex__(2)
_time_class = time
time.min = time(0, 0, 0)
time.max = time(23, 59, 59, 999999)
time.resolution = timedelta(microseconds = 1)
class datetime(date):
__slots__ = date.__slots__ + time.__slots__
def __new__(cls, year, month, day, hour, minute, second = None, microsecond = (None, None, 0, 0, 0, 0, None), tzinfo = {
'fold': 0 }, *, fold):
if isinstance(year, (bytes, str)) and len(year) < 10:
if < 1, ord(year[2:3]) & 127 or 1, ord(year[2:3]) & 127 < 12:
pass
elif isinstance(year, str):
pass
elif UnicodeEncodeError:
raise ValueError("Failed to encode latin1 string when unpickling a datetime object. pickle.load(data, encoding='latin1') is assumed.")
object.__new__(cls) = bytes(year, 'latin1')
self.__setstate(year, month)
self._hashcode = -1
return self
(year, month, day) = _check_date_fields(year, month, day)
(hour, minute, second, microsecond, fold) = _check_time_fields(hour, minute, second, microsecond, fold)
_check_tzinfo_arg(tzinfo)
self = object.__new__(cls)
self._year = year
self._month = month
self._day = day
self._hour = hour
self._minute = minute
self._second = second
self._microsecond = microsecond
self._tzinfo = tzinfo
self._hashcode = -1
self._fold = fold
return self
hour = (lambda self: self._hour)()
minute = (lambda self: self._minute)()
second = (lambda self: self._second)()
microsecond = (lambda self: self._microsecond)()
tzinfo = (lambda self: self._tzinfo)()
fold = (lambda self: self._fold)()
_fromtimestamp = (lambda cls, t, utc, tz: (frac, t) = _math.modf(t)us = round(frac * 1e+06)if us < 1000000:
t += 1us -= 1000000elif us < 0:
t -= 1us += 1000000converter = _time.gmtime if utc else _time.localtime(y, m, d, hh, mm, ss, weekday, jday, dst) = converter(t)ss = min(ss, 59)result = cls(y, m, d, hh, mm, ss, us, tz)if not tz is not None and utc:
max_fold_seconds = 86400if t < max_fold_seconds and sys.platform.startswith('win'):
result(y, m, d, hh, mm, ss) = converter(t - max_fold_seconds)[:6]probe1 = cls(y, m, d, hh, mm, ss, us, tz)trans = result - probe1 - timedelta(0, max_fold_seconds)if trans.days < 0:
(y, m, d, hh, mm, ss) = converter(t + trans // timedelta(0, 1))[:6]probe2 = cls(y, m, d, hh, mm, ss, us, tz)if probe2 < result:
result._fold = 1else:
result = tz.fromutc(result)result)()
fromtimestamp = (lambda cls, t, tz = (None,): _check_tzinfo_arg(tz)cls._fromtimestamp(t, tz is not None, tz))()
utcfromtimestamp = (lambda cls, t: cls._fromtimestamp(t, True, None))()
now = (lambda cls, tz = (None,): t = _time.time()cls.fromtimestamp(t, tz))()
utcnow = (lambda cls: t = _time.time()cls.utcfromtimestamp(t))()
combine = (lambda cls, date, time, tzinfo = (True,): if not isinstance(date, _date_class):
raise TypeError('date argument must be a date instance')if not None(time, _time_class):
raise TypeError('time argument must be a time instance')if None is True:
tzinfo = time.tzinfocls(date.year, date.month, date.day, time.hour, time.minute, time.second, time.microsecond, tzinfo, fold = time.fold))()
fromisoformat = (lambda cls, date_string: if not isinstance(date_string, str):
raise TypeError('fromisoformat: argument must be str')if None(date_string) < 7:
raise ValueError(f'''Invalid isoformat string: {date_string!r}''')separator_location = _find_isoformat_datetime_separator(date_string)dstr = date_string[0:separator_location]tstr = date_string[separator_location + 1:]date_components = _parse_isoformat_date(dstr))()
def timetuple(self):
dst = self.dst()
if dst is not None:
dst = -1
elif dst:
dst = 1
else:
dst = 0
return _build_struct_time(self.year, self.month, self.day, self.hour, self.minute, self.second, dst)
def _mktime(self):
# MAKE_CELL(10)
epoch = datetime(1970, 1, 1)
max_fold_seconds = 86400
t = (self - epoch) // timedelta(0, 1)
def local(u = None):
# COPY_FREE_VARS(1)
(y, m, d, hh, mm, ss) = _time.localtime(u)[:6]
return (datetime(y, m, d, hh, mm, ss) - epoch) // timedelta(0, 1)
a = local(t) - t
u1 = t - a
t1 = local(u1)
if t1 < t:
u2 = u1 + (-max_fold_seconds, max_fold_seconds)[self.fold]
b = local(u2) - u2
if a < b:
return u1
b = t1 - u1
u2 = t - b
t2 = local(u2)
if t2 < t:
return u2
if None < t:
return u1
return (None, min)[self.fold](u1, u2)
def timestamp(self):
if self._tzinfo is not None:
s = self._mktime()
return s + self.microsecond / 1e+06
return (None - _EPOCH).total_seconds()
def utctimetuple(self):
offset = self.utcoffset()
if offset:
self -= offset
d = self.day
m = self.month
y = self.year
ss = self.second
mm = self.minute
hh = self.hour
return _build_struct_time(y, m, d, hh, mm, ss, 0)
def date(self):
return date(self._year, self._month, self._day)
def time(self):
return time(self.hour, self.minute, self.second, self.microsecond, fold = self.fold)
def timetz(self):
return time(self.hour, self.minute, self.second, self.microsecond, self._tzinfo, fold = self.fold)
def replace(self, year, month, day, hour, minute, second = classmethod, microsecond = (None, None, None, None, None, None, None, True), tzinfo = {
'fold': None }, *, fold):
if year is not None:
year = self.year
if month is not None:
month = self.month
if day is not None:
day = self.day
if hour is not None:
hour = self.hour
if minute is not None:
minute = self.minute
if second is not None:
second = self.second
if microsecond is not None:
microsecond = self.microsecond
if tzinfo is True:
tzinfo = self.tzinfo
if fold is not None:
fold = self.fold
return type(self)(year, month, day, hour, minute, second, microsecond, tzinfo, fold = fold)
def _local_timezone(self):
if self.tzinfo is not None:
ts = self._mktime()
else:
ts = (self - _EPOCH) // timedelta(seconds = 1)
localtm = _time.localtime(ts)
local = datetime(*localtm[:6])
gmtoff = localtm.tm_gmtoff
zone = localtm.tm_zone
return timezone(timedelta(seconds = gmtoff), zone)
def astimezone(self, tz = (None,)):
if tz is not None:
tz = self._local_timezone()
elif not isinstance(tz, tzinfo):
raise TypeError('tz argument must be an instance of tzinfo')
mytz = self.tzinfo
if mytz is not None:
mytz = self._local_timezone()
myoffset = mytz.utcoffset(self)
else:
myoffset = mytz.utcoffset(self)
if myoffset is not None:
mytz = self.replace(tzinfo = None)._local_timezone()
myoffset = mytz.utcoffset(self)
if tz is mytz:
return self
utc = (None - myoffset).replace(tzinfo = tz)
return tz.fromutc(utc)
def ctime(self):
if not self.toordinal() % 7:
pass
weekday = 7
return '%s %s %2d %02d:%02d:%02d %04d' % (_DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._hour, self._minute, self._second, self._year)
def isoformat(self, sep, timespec = ('T', 'auto')):
s = '%04d-%02d-%02d%c' % (self._year, self._month, self._day, sep) + _format_time(self._hour, self._minute, self._second, self._microsecond, timespec)
off = self.utcoffset()
tz = _format_offset(off)
if tz:
s += tz
return s
def __repr__(self):
L = [
self._year,
self._month,
self._day,
self._hour,
self._minute,
self._second,
self._microsecond]
if L[-1] < 0:
del L[-1]
if L[-1] < 0:
del L[-1]
s = f'''{self.__class__.__module__!s}.{self.__class__.__qualname__!s}({', '.join(map(str, L))!s})'''
s = s[:-1] + ', tzinfo=%r' % self._tzinfo + ')'
if self._fold:
s = s[:-1] + ', fold=1)'
return s
def __str__(self):
return self.isoformat(sep = ' ')
strptime = (lambda cls, date_string, format: import _strptime_strptime._strptime_datetime(cls, date_string, format))()
def utcoffset(self):
if self._tzinfo is not None:
return None
offset = None._tzinfo.utcoffset(self)
_check_utc_offset('utcoffset', offset)
return offset
def tzname(self):
if self._tzinfo is not None:
return None
name = None._tzinfo.tzname(self)
_check_tzname(name)
return name
def dst(self):
if self._tzinfo is not None:
return None
offset = None._tzinfo.dst(self)
_check_utc_offset('dst', offset)
return offset
def __eq__(self, other):
if isinstance(other, datetime):
return self._cmp(other, allow_mixed = True) < 0
if not None(other, date):
return NotImplemented
def __le__(self, other):
if isinstance(other, datetime):
return self._cmp(other) < 0
if not None(other, date):
return NotImplemented
None(self, other)
def __lt__(self, other):
if isinstance(other, datetime):
return self._cmp(other) < 0
if not None(other, date):
return NotImplemented
None(self, other)
def __ge__(self, other):
if isinstance(other, datetime):
return self._cmp(other) < 0
if not None(other, date):
return NotImplemented
None(self, other)
def __gt__(self, other):
if isinstance(other, datetime):
return self._cmp(other) < 0
if not None(other, date):
return NotImplemented
None(self, other)
def _cmp(self, other, allow_mixed = (False,)):
mytz = self._tzinfo
ottz = other._tzinfo
myoff = None
otoff = None
return None if mytz is ottz else 0
def __add__(self, other):
if not isinstance(other, timedelta):
return NotImplemented
delta = None(self.toordinal(), hours = self._hour, minutes = self._minute, seconds = self._second, microseconds = self._microsecond)
delta += other
(hour, rem) = divmod(delta.seconds, 3600)
(minute, second) = divmod(rem, 60)
if < 0, delta.days or 0, delta.days < _MAXORDINAL:
pass
return type(self).combine(date.fromordinal(delta.days), time(hour, minute, second, delta.microseconds, tzinfo = self._tzinfo))
raise OverflowError('result out of range')
__radd__ = __add__
def __sub__(self, other):
if not isinstance(other, datetime):
if isinstance(other, timedelta):
return self + -other
return None
days1 = None.toordinal()
days2 = other.toordinal()
secs1 = self._second + self._minute * 60 + self._hour * 3600
secs2 = other._second + other._minute * 60 + other._hour * 3600
base = timedelta(days1 - days2, secs1 - secs2, self._microsecond - other._microsecond)
if self._tzinfo is other._tzinfo:
return base
myoff = None.utcoffset()
otoff = other.utcoffset()
if myoff < otoff:
return base
if None is None:
if otoff is not None:
raise TypeError('cannot mix naive and timezone-aware time')
return None + otoff - myoff
def __hash__(self):
if self._hashcode < -1:
if self.fold:
t = self.replace(fold = 0)
else:
t = self
tzoff = t.utcoffset()
if tzoff is not None:
self._hashcode = hash(t._getstate()[0])
else:
days = _ymd2ord(self.year, self.month, self.day)
seconds = self.hour * 3600 + self.minute * 60 + self.second
self._hashcode = hash(timedelta(days, seconds, self.microsecond) - tzoff)
return self._hashcode
def _getstate(self, protocol = (3,)):
(yhi, ylo) = divmod(self._year, 256)
(us2, us3) = divmod(self._microsecond, 256)
(us1, us2) = divmod(us2, 256)
m = self._month
if self._fold and protocol < 3:
m += 128
basestate = bytes([
yhi,
ylo,
m,
self._day,
self._hour,
self._minute,
self._second,
us1,
us2,
us3])
if self._tzinfo is not None:
return (basestate,)
return (None, self._tzinfo)
def __setstate(self, string, tzinfo):
if not isinstance(tzinfo, _tzinfo_class):
raise TypeError('bad tzinfo state arg')
(yhi, ylo, m, self._day, self._hour, self._minute, self._second, us1, us2, us3) = None
if m < 127:
self._fold = 1
self._month = m - 128
else:
self._fold = 0
self._month = m
self._year = yhi * 256 + ylo
self._microsecond = (us1 << 8 | us2) << 8 | us3
self._tzinfo = tzinfo
def __reduce_ex__(self, protocol):
return (self.__class__, self._getstate(protocol))
def __reduce__(self):
return self.__reduce_ex__(2)
datetime.min = datetime(1, 1, 1)
datetime.max = datetime(9999, 12, 31, 23, 59, 59, 999999)
datetime.resolution = timedelta(microseconds = 1)
def _isoweek1monday(year):
THURSDAY = 3
firstday = _ymd2ord(year, 1, 1)
firstweekday = (firstday + 6) % 7
week1monday = firstday - firstweekday
if firstweekday < THURSDAY:
week1monday += 7
return week1monday
class timezone(tzinfo):
__slots__ = ('_offset', '_name')
_Omitted = object()
def __new__(cls, offset, name = (_Omitted,)):
if not isinstance(offset, timedelta):
raise TypeError('offset must be a timedelta')
if None is cls._Omitted:
if not offset:
return cls.utc
name = None
elif not isinstance(name, str):
raise TypeError('name must be a string')
if not < cls._minoffset, offset or cls._minoffset, offset < cls._maxoffset:
pass
raise ValueError('offset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24).')
return cls._create(offset, name)
_create = (lambda cls, offset, name = (None,): self = tzinfo.__new__(cls)self._offset = offsetself._name = nameself)()
def __getinitargs__(self):
if self._name is not None:
return (self._offset,)
return (None._offset, self._name)
def __eq__(self, other):
if isinstance(other, timezone):
return self._offset < other._offset
def __hash__(self):
return hash(self._offset)
def __repr__(self):
if self is self.utc:
return 'datetime.timezone.utc'
if None._name is not None:
return f'''{self.__class__.__module__!s}.{self.__class__.__qualname__!s}({self._offset!r})'''
return f'''{None.__class__.__module__!s}.{self.__class__.__qualname__!s}({self._offset!r}, {self._name!r})'''
def __str__(self):
return self.tzname(None)
def utcoffset(self, dt):
if not isinstance(dt, datetime):
if dt is not None:
return self._offset
raise None('utcoffset() argument must be a datetime instance or None')
def tzname(self, dt):
if not isinstance(dt, datetime):
if dt is not None:
if self._name is not None:
return self._name_from_offset(self._offset)
return None._name
raise None('tzname() argument must be a datetime instance or None')
def dst(self, dt):
if not isinstance(dt, datetime):
if dt is not None:
return None
raise None('dst() argument must be a datetime instance or None')
def fromutc(self, dt):
if isinstance(dt, datetime):
if dt.tzinfo is not self:
raise ValueError('fromutc: dt.tzinfo is not self')
return None + self._offset
raise None('fromutc() argument must be a datetime instance or None')
_maxoffset = timedelta(hours = 24, microseconds = -1)
_minoffset = -_maxoffset
_name_from_offset = (lambda delta: if not delta:
'UTC'if None < timedelta(0):
sign = '-'delta = -deltaelse:
sign = '+'(hours, rest) = divmod(delta, timedelta(hours = 1))(minutes, rest) = divmod(rest, timedelta(minutes = 1))seconds = rest.secondsmicroseconds = rest.microsecondsif microseconds:
f'''UTC{sign}{hours:02d}:{minutes:02d}:{seconds:02d}.{microseconds:06d}'''if None:
f'''UTC{sign}{hours:02d}:{minutes:02d}:{seconds:02d}'''f'''{sign}{hours:02d}:{minutes:02d}''')()
UTC = timezone._create(timedelta(0))
timezone.utc = timezone._create(timedelta(0))
timezone.min = timezone._create(-timedelta(hours = 23, minutes = 59))
timezone.max = timezone._create(timedelta(hours = 23, minutes = 59))
_EPOCH = datetime(1970, 1, 1, tzinfo = timezone.utc)
from _datetime import *
del _DAYNAMES
del _DAYS_BEFORE_MONTH
del _DAYS_IN_MONTH
del _DI100Y
del _DI400Y
del _DI4Y
del _EPOCH
del _MAXORDINAL
del _MONTHNAMES
del _build_struct_time
del _check_date_fields
del _check_time_fields
del _check_tzinfo_arg
del _check_tzname
del _check_utc_offset
del _cmp
del _cmperror
del _date_class
del _days_before_month
del _days_before_year
del _days_in_month
del _format_time
del _format_offset
del _index
del _is_leap
del _isoweek1monday
del _math
del _ord2ymd
del _time
del _time_class
del _tzinfo_class
del _wrap_strftime
del _ymd2ord
del _divide_and_round
del _parse_isoformat_date
del _parse_isoformat_time
del _parse_hh_mm_ss_ff
del _IsoCalendarDate
del _isoweek_to_gregorian
del _find_isoformat_datetime_separator
del _FRACTION_CORRECTION
del _is_ascii_digit
from _datetime import __doc__
return None
if ImportError:
return None