<s> """<STR_LIT>""" <EOL> import math <EOL> from time import localtime <EOL> from datetime import date , datetime , time , timedelta <EOL> from _mysql import string_literal <EOL> Date = date <EOL> Time = time <EOL> TimeDelta = timedelta <EOL> Timestamp = datetime <EOL> DateTimeDeltaType = timedelta <EOL> DateTimeType = datetime <EOL> def DateFromTicks ( ticks ) : <EOL> """<STR_LIT>""" <EOL> return date ( * localtime ( ticks ) [ : <NUM_LIT:3> ] ) <EOL> def TimeFromTicks ( ticks ) : <EOL> """<STR_LIT>""" <EOL> return time ( * localtime ( ticks ) [ <NUM_LIT:3> : <NUM_LIT:6> ] ) <EOL> def TimestampFromTicks ( ticks ) : <EOL> """<STR_LIT>""" <EOL> return datetime ( * localtime ( ticks ) [ : <NUM_LIT:6> ] ) <EOL> format_TIME = format_DATE = str <EOL> def format_TIMEDELTA ( v ) : <EOL> seconds = int ( v . seconds ) % <NUM_LIT> <EOL> minutes = int ( v . seconds / <NUM_LIT> ) % <NUM_LIT> <EOL> hours = int ( v . seconds / <NUM_LIT> ) % <NUM_LIT> <EOL> return '<STR_LIT>' % ( v . days , hours , minutes , seconds ) <EOL> def format_TIMESTAMP ( d ) : <EOL> return d . isoformat ( "<STR_LIT:U+0020>" ) <EOL> def DateTime_or_None ( s ) : <EOL> if '<STR_LIT:U+0020>' in s : <EOL> sep = '<STR_LIT:U+0020>' <EOL> elif '<STR_LIT:T>' in s : <EOL> sep = '<STR_LIT:T>' <EOL> else : <EOL> return Date_or_None ( s ) <EOL> try : <EOL> d , t = s . split ( sep , <NUM_LIT:1> ) <EOL> if '<STR_LIT:.>' in t : <EOL> t , ms = t . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> ms = ms . ljust ( <NUM_LIT:6> , '<STR_LIT:0>' ) <EOL> else : <EOL> ms = <NUM_LIT:0> <EOL> return datetime ( * [ int ( x ) for x in d . split ( '<STR_LIT:->' ) + t . split ( '<STR_LIT::>' ) + [ ms ] ] ) <EOL> except ( SystemExit , KeyboardInterrupt ) : <EOL> raise <EOL> except : <EOL> return Date_or_None ( s ) <EOL> def TimeDelta_or_None ( s ) : <EOL> try : <EOL> h , m , s = s . split ( '<STR_LIT::>' ) <EOL> if '<STR_LIT:.>' in s : <EOL> s , ms = s . split ( '<STR_LIT:.>' ) <EOL> ms = ms . ljust ( <NUM_LIT:6> , '<STR_LIT:0>' ) <EOL> else : <EOL> ms = <NUM_LIT:0> <EOL> h , m , s , ms = int ( h ) , int ( m ) , int ( s ) , int ( ms ) <EOL> td = timedelta ( hours = abs ( h ) , minutes = m , seconds = s , <EOL> microseconds = ms ) <EOL> if h < <NUM_LIT:0> : <EOL> return - td <EOL> else : <EOL> return td <EOL> except ValueError : <EOL> return None <EOL> def Time_or_None ( s ) : <EOL> try : <EOL> h , m , s = s . split ( '<STR_LIT::>' ) <EOL> if '<STR_LIT:.>' in s : <EOL> s , ms = s . split ( '<STR_LIT:.>' ) <EOL> ms = ms . ljust ( <NUM_LIT:6> , '<STR_LIT:0>' ) <EOL> else : <EOL> ms = <NUM_LIT:0> <EOL> h , m , s , ms = int ( h ) , int ( m ) , int ( s ) , int ( ms ) <EOL> return time ( hour = h , minute = m , second = s , <EOL> microsecond = ms ) <EOL> except ValueError : <EOL> return None <EOL> def Date_or_None ( s ) : <EOL> try : <EOL> return date ( * [ int ( x ) for x in s . split ( '<STR_LIT:->' , <NUM_LIT:2> ) ] ) <EOL> except ( SystemExit , KeyboardInterrupt ) : <EOL> raise <EOL> except : <EOL> return None <EOL> def DateTime2literal ( d , c ) : <EOL> """<STR_LIT>""" <EOL> return string_literal ( format_TIMESTAMP ( d ) , c ) <EOL> def DateTimeDelta2literal ( d , c ) : <EOL> """<STR_LIT>""" <EOL> return string_literal ( format_TIMEDELTA ( d ) , c ) <EOL> def mysql_timestamp_converter ( s ) : <EOL> """<STR_LIT>""" <EOL> if s [ <NUM_LIT:4> ] == '<STR_LIT:->' : return DateTime_or_None ( s ) <EOL> s = s + "<STR_LIT:0>" * ( <NUM_LIT> - len ( s ) ) <EOL> parts = map ( int , filter ( None , ( s [ : <NUM_LIT:4> ] , s [ <NUM_LIT:4> : <NUM_LIT:6> ] , s [ <NUM_LIT:6> : <NUM_LIT:8> ] , <EOL> s [ <NUM_LIT:8> : <NUM_LIT:10> ] , s [ <NUM_LIT:10> : <NUM_LIT:12> ] , s [ <NUM_LIT:12> : <NUM_LIT> ] ) ) ) <EOL> try : <EOL> return Timestamp ( * parts ) <EOL> except ( SystemExit , KeyboardInterrupt ) : <EOL> raise <EOL> except : <EOL> return None </s>
