<s> """<STR_LIT>""" <EOL> import datetime , time , calendar <EOL> import re <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> ZERO = datetime . timedelta ( <NUM_LIT:0> ) <EOL> class tzinfo ( datetime . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , minutesEast = <NUM_LIT:0> , name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . minutesEast = minutesEast <EOL> self . offset = datetime . timedelta ( minutes = minutesEast ) <EOL> self . name = name <EOL> def utcoffset ( self , dt ) : <EOL> """<STR_LIT>""" <EOL> return self . offset <EOL> def dst ( self , dt ) : <EOL> """<STR_LIT>""" <EOL> return ZERO <EOL> def tzname ( self , dt ) : <EOL> """<STR_LIT>""" <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . minutesEast == <NUM_LIT:0> : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" % ( self . minutesEast , repr ( self . name ) ) <EOL> UTC_TZ = tzinfo ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> date_re_str = r'<STR_LIT>' <EOL> time_re_str = r'<STR_LIT>' <EOL> def make_re ( * parts ) : <EOL> return re . compile ( r'<STR_LIT>' + '<STR_LIT>' . join ( parts ) + r'<STR_LIT>' ) <EOL> date_re = make_re ( date_re_str ) <EOL> datetime_re = make_re ( date_re_str , r'<STR_LIT>' , time_re_str ) <EOL> def parse_date ( s ) : <EOL> """<STR_LIT>""" <EOL> m = date_re . match ( s ) <EOL> if m : <EOL> ( y , m , d ) = m . groups ( ) <EOL> return datetime . date ( int ( y ) , int ( m ) , int ( d ) ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' , s ) <EOL> def _offset_to_tzname ( offset ) : <EOL> """<STR_LIT>""" <EOL> offset = int ( offset ) <EOL> if offset < <NUM_LIT:0> : <EOL> tzsign = '<STR_LIT:->' <EOL> else : <EOL> tzsign = '<STR_LIT:+>' <EOL> offset = abs ( offset ) <EOL> tzhour = offset / <NUM_LIT> <EOL> tzmin = offset % <NUM_LIT> <EOL> return '<STR_LIT>' % ( tzsign , tzhour , tzmin ) <EOL> def parse_datetime ( s ) : <EOL> """<STR_LIT>""" <EOL> m = datetime_re . match ( s ) <EOL> if m : <EOL> ( y , m , d , hour , min , sec , ignore1 , frac_sec , wholetz , ignore2 , tzsign , tzhour , tzmin ) = m . groups ( ) <EOL> if frac_sec : <EOL> frac_sec = float ( "<STR_LIT>" + frac_sec ) <EOL> else : <EOL> frac_sec = <NUM_LIT:0> <EOL> microsec = int ( ( frac_sec * <NUM_LIT> ) + <NUM_LIT:0.5> ) <EOL> if wholetz == '<STR_LIT:z>' or wholetz == '<STR_LIT>' : <EOL> tz = UTC_TZ <EOL> else : <EOL> tzhour = int ( tzhour ) <EOL> tzmin = int ( tzmin ) <EOL> offset = tzhour * <NUM_LIT> + tzmin <EOL> if offset == <NUM_LIT:0> : <EOL> tz = UTC_TZ <EOL> else : <EOL> if tzhour > <NUM_LIT> or tzmin > <NUM_LIT> or offset > <NUM_LIT> : <EOL> raise ValueError ( '<STR_LIT>' , s , wholetz ) <EOL> if tzsign == '<STR_LIT:->' : <EOL> offset = - offset <EOL> tz = tzinfo ( offset , _offset_to_tzname ( offset ) ) <EOL> return datetime . datetime ( int ( y ) , int ( m ) , int ( d ) , <EOL> int ( hour ) , int ( min ) , int ( sec ) , microsec , <EOL> tz ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' , s ) <EOL> def now ( ) : <EOL> """<STR_LIT>""" <EOL> return utcfromtimestamp ( time . time ( ) ) <EOL> def utcfromtimestamp ( unix_epoch_timestamp ) : <EOL> """<STR_LIT>""" <EOL> ( y , m , d , hour , min , sec ) = time . gmtime ( unix_epoch_timestamp ) [ : <NUM_LIT:6> ] <EOL> return datetime . datetime ( y , m , d , hour , min , sec , <NUM_LIT:0> , UTC_TZ ) <EOL> def utctotimestamp ( dt ) : <EOL> """<STR_LIT>""" <EOL> return calendar . timegm ( dt . utctimetuple ( ) ) <EOL> def datetimetostr ( dt ) : <EOL> """<STR_LIT>""" <EOL> if dt . utcoffset ( ) is not None : <EOL> return dt . isoformat ( ) <EOL> else : <EOL> return "<STR_LIT>" % dt . isoformat ( ) <EOL> def timestamptostr ( ts ) : <EOL> """<STR_LIT>""" <EOL> return datetimetostr ( utcfromtimestamp ( ts ) ) <EOL> def strtotimestamp ( s ) : <EOL> """<STR_LIT>""" <EOL> return utctotimestamp ( parse_datetime ( s ) ) </s>
