<s> from browser import window <EOL> import javascript <EOL> date = javascript . JSConstructor ( window . Date ) <EOL> _STRUCT_TM_ITEMS = <NUM_LIT:9> <EOL> def _get_day_of_year ( arg ) : <EOL> """<STR_LIT>""" <EOL> ml = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> ] <EOL> if arg [ <NUM_LIT:0> ] % <NUM_LIT:4> == <NUM_LIT:0> : <EOL> ml [ <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> i = <NUM_LIT:1> <EOL> yday = <NUM_LIT:0> <EOL> while i < arg [ <NUM_LIT:1> ] : <EOL> yday += ml [ i - <NUM_LIT:1> ] <EOL> i += <NUM_LIT:1> <EOL> yday += arg [ <NUM_LIT:2> ] <EOL> return yday <EOL> def _get_week_of_year ( arg ) : <EOL> """<STR_LIT>""" <EOL> d1 = date ( arg [ <NUM_LIT:0> ] , arg [ <NUM_LIT:1> ] - <NUM_LIT:1> , arg [ <NUM_LIT:2> ] ) <EOL> d0 = date ( arg [ <NUM_LIT:0> ] , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> firstday = d0 . getDay ( ) <EOL> if firstday == <NUM_LIT:0> : firstday = <NUM_LIT:7> <EOL> firstweek = <NUM_LIT:8> - firstday <EOL> doy = arg [ <NUM_LIT:7> ] <EOL> if firstday != <NUM_LIT:1> : <EOL> doy = doy - firstweek <EOL> if doy % <NUM_LIT:7> == <NUM_LIT:0> : <EOL> week_number = doy // <NUM_LIT:7> <EOL> else : <EOL> week_number = doy // <NUM_LIT:7> + <NUM_LIT:1> <EOL> return week_number <EOL> def _check_struct_time ( t ) : <EOL> mm = t [ <NUM_LIT:1> ] <EOL> if mm == <NUM_LIT:0> : mm = <NUM_LIT:1> <EOL> if - <NUM_LIT:1> > mm > <NUM_LIT> : raise ValueError ( "<STR_LIT>" ) <EOL> dd = t [ <NUM_LIT:2> ] <EOL> if dd == <NUM_LIT:0> : dd = <NUM_LIT:1> <EOL> if - <NUM_LIT:1> > dd > <NUM_LIT:32> : raise ValueError ( "<STR_LIT>" ) <EOL> hh = t [ <NUM_LIT:3> ] <EOL> if - <NUM_LIT:1> > hh > <NUM_LIT> : raise ValueError ( "<STR_LIT>" ) <EOL> minu = t [ <NUM_LIT:4> ] <EOL> if - <NUM_LIT:1> > minu > <NUM_LIT> : raise ValueError ( "<STR_LIT>" ) <EOL> ss = t [ <NUM_LIT:5> ] <EOL> if - <NUM_LIT:1> > ss > <NUM_LIT> : raise ValueError ( "<STR_LIT>" ) <EOL> wd = t [ <NUM_LIT:6> ] % <NUM_LIT:7> <EOL> if wd < - <NUM_LIT:2> : raise ValueError ( "<STR_LIT>" ) <EOL> dy = t [ <NUM_LIT:7> ] <EOL> if dy == <NUM_LIT:0> : dy = <NUM_LIT:1> <EOL> if - <NUM_LIT:1> > dy > <NUM_LIT> : raise ValueError ( "<STR_LIT>" ) <EOL> return t [ <NUM_LIT:0> ] , mm , dd , hh , minu , ss , wd , dy , t [ - <NUM_LIT:1> ] <EOL> def _is_dst ( secs = None ) : <EOL> "<STR_LIT>" <EOL> d = date ( ) <EOL> if secs is not None : <EOL> d = date ( secs * <NUM_LIT:1000> ) <EOL> jan = date ( d . getFullYear ( ) , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> jul = date ( d . getFullYear ( ) , <NUM_LIT:6> , <NUM_LIT:1> ) <EOL> dst = int ( d . getTimezoneOffset ( ) < max ( abs ( jan . getTimezoneOffset ( ) ) , abs ( jul . getTimezoneOffset ( ) ) ) ) <EOL> return dst <EOL> def _get_tzname ( ) : <EOL> "<STR_LIT>" <EOL> d = date ( ) <EOL> d = d . toTimeString ( ) <EOL> try : <EOL> d = d . split ( '<STR_LIT:(>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:)>' ) [ <NUM_LIT:0> ] <EOL> return ( d , '<STR_LIT>' ) <EOL> except : <EOL> return ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _set_altzone ( ) : <EOL> d = date ( ) <EOL> jan = date ( d . getFullYear ( ) , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> jul = date ( d . getFullYear ( ) , <NUM_LIT:6> , <NUM_LIT:1> ) <EOL> result = timezone - ( jan . getTimezoneOffset ( ) - jul . getTimezoneOffset ( ) ) * <NUM_LIT> <EOL> return result <EOL> def _check_input ( t ) : <EOL> if t and isinstance ( t , struct_time ) and len ( t . args ) == <NUM_LIT:9> : <EOL> t = t . args <EOL> elif t and isinstance ( t , tuple ) and len ( t ) == <NUM_LIT:9> : <EOL> t = t <EOL> elif t and isinstance ( t , struct_time ) and len ( t . args ) != <NUM_LIT:9> : <EOL> raise TypeError ( "<STR_LIT>" . format ( len ( t . args ) ) ) <EOL> elif t and isinstance ( t , tuple ) and len ( t ) != <NUM_LIT:9> : <EOL> raise TypeError ( "<STR_LIT>" . format ( len ( t . args ) ) ) <EOL> elif t and not isinstance ( t , ( tuple , struct_time ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> t = localtime ( ) . args <EOL> return t <EOL> daylight = _is_dst ( ) <EOL> timezone = date ( ) . getTimezoneOffset ( ) * <NUM_LIT> <EOL> tzname = _get_tzname ( ) <EOL> altzone = _set_altzone ( ) if daylight else timezone <EOL> def asctime ( t = None ) : <EOL> weekdays = { <NUM_LIT:0> : "<STR_LIT>" , <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:2> : "<STR_LIT>" , <NUM_LIT:3> : "<STR_LIT>" , <EOL> <NUM_LIT:4> : "<STR_LIT>" , <NUM_LIT:5> : "<STR_LIT>" , <NUM_LIT:6> : "<STR_LIT>" } <EOL> months = { <NUM_LIT:1> : '<STR_LIT>' , <NUM_LIT:2> : '<STR_LIT>' , <NUM_LIT:3> : '<STR_LIT>' , <NUM_LIT:4> : '<STR_LIT>' , <NUM_LIT:5> : '<STR_LIT>' , <NUM_LIT:6> : '<STR_LIT>' , <EOL> <NUM_LIT:7> : '<STR_LIT>' , <NUM_LIT:8> : '<STR_LIT>' , <NUM_LIT:9> : '<STR_LIT>' , <NUM_LIT:10> : '<STR_LIT>' , <NUM_LIT:11> : '<STR_LIT>' , <NUM_LIT:12> : '<STR_LIT>' } <EOL> t = _check_input ( t ) <EOL> t = _check_struct_time ( t ) <EOL> result = "<STR_LIT>" % ( <EOL> weekdays [ t [ <NUM_LIT:6> ] ] , months [ t [ <NUM_LIT:1> ] ] , t [ <NUM_LIT:2> ] , t [ <NUM_LIT:3> ] , t [ <NUM_LIT:4> ] , t [ <NUM_LIT:5> ] , t [ <NUM_LIT:0> ] ) <EOL> return result <EOL> def ctime ( timestamp = None ) : <EOL> if timestamp is None : <EOL> timestamp = date ( ) . getTime ( ) / <NUM_LIT> <EOL> d = date ( <NUM_LIT:0> ) <EOL> d . setUTCSeconds ( timestamp ) <EOL> jan = date ( d . getFullYear ( ) , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> jul = date ( d . getFullYear ( ) , <NUM_LIT:6> , <NUM_LIT:1> ) <EOL> dst = int ( d . getTimezoneOffset ( ) < max ( jan . getTimezoneOffset ( ) , jul . getTimezoneOffset ( ) ) ) <EOL> d = date ( <NUM_LIT:0> ) <EOL> d . setUTCSeconds ( timestamp + ( <NUM_LIT:1> + dst ) * <NUM_LIT> ) <EOL> weekdays = { <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:2> : "<STR_LIT>" , <NUM_LIT:3> : "<STR_LIT>" , <NUM_LIT:4> : "<STR_LIT>" , <EOL> <NUM_LIT:5> : "<STR_LIT>" , <NUM_LIT:6> : "<STR_LIT>" , <NUM_LIT:0> : "<STR_LIT>" } <EOL> months = { <NUM_LIT:0> : '<STR_LIT>' , <NUM_LIT:1> : '<STR_LIT>' , <NUM_LIT:2> : '<STR_LIT>' , <NUM_LIT:3> : '<STR_LIT>' , <NUM_LIT:4> : '<STR_LIT>' , <NUM_LIT:5> : '<STR_LIT>' , <EOL> <NUM_LIT:6> : '<STR_LIT>' , <NUM_LIT:7> : '<STR_LIT>' , <NUM_LIT:8> : '<STR_LIT>' , <NUM_LIT:9> : '<STR_LIT>' , <NUM_LIT:10> : '<STR_LIT>' , <NUM_LIT:11> : '<STR_LIT>' } <EOL> result = "<STR_LIT>" % ( weekdays [ d . getUTCDay ( ) ] , <EOL> months [ d . getUTCMonth ( ) ] , d . getUTCDate ( ) , <EOL> d . getUTCHours ( ) , d . getUTCMinutes ( ) , d . getUTCSeconds ( ) , <EOL> d . getUTCFullYear ( ) ) <EOL> return result <EOL> def gmtime ( secs = None ) : <EOL> d = date ( ) <EOL> if secs is not None : <EOL> d = date ( secs * <NUM_LIT:1000> ) <EOL> wday = d . getUTCDay ( ) - <NUM_LIT:1> if d . getUTCDay ( ) - <NUM_LIT:1> >= <NUM_LIT:0> else <NUM_LIT:6> <EOL> tmp = struct_time ( [ d . getUTCFullYear ( ) , <EOL> d . getUTCMonth ( ) + <NUM_LIT:1> , d . getUTCDate ( ) , <EOL> d . getUTCHours ( ) , d . getUTCMinutes ( ) , d . getUTCSeconds ( ) , <EOL> wday , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> tmp . args [ <NUM_LIT:7> ] = _get_day_of_year ( tmp . args ) <EOL> return tmp <EOL> def localtime ( secs = None ) : <EOL> d = date ( ) <EOL> if secs is not None : <EOL> d = date ( secs * <NUM_LIT:1000> ) <EOL> dst = _is_dst ( secs ) <EOL> wday = d . getDay ( ) - <NUM_LIT:1> if d . getDay ( ) - <NUM_LIT:1> >= <NUM_LIT:0> else <NUM_LIT:6> <EOL> tmp = struct_time ( [ d . getFullYear ( ) , <EOL> d . getMonth ( ) + <NUM_LIT:1> , d . getDate ( ) , <EOL> d . getHours ( ) , d . getMinutes ( ) , d . getSeconds ( ) , <EOL> wday , <NUM_LIT:0> , dst ] ) <EOL> tmp . args [ <NUM_LIT:7> ] = _get_day_of_year ( tmp . args ) <EOL> return tmp <EOL> def mktime ( t ) : <EOL> if isinstance ( t , struct_time ) : <EOL> d1 = date ( t . tm_year , t . tm_mon - <NUM_LIT:1> , t . tm_mday , <EOL> t . tm_hour , t . tm_min , t . tm_sec , <NUM_LIT:0> ) . getTime ( ) <EOL> elif isinstance ( t , tuple ) : <EOL> d1 = date ( t [ <NUM_LIT:0> ] , t [ <NUM_LIT:1> ] - <NUM_LIT:1> , t [ <NUM_LIT:2> ] , t [ <NUM_LIT:3> ] , t [ <NUM_LIT:4> ] , t [ <NUM_LIT:5> ] , <NUM_LIT:0> ) . getTime ( ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> d2 = date ( <NUM_LIT:0> ) . getTime ( ) <EOL> return ( d1 - d2 ) / <NUM_LIT> <EOL> def monotonic ( ) : <EOL> return javascript . JSObject ( window . performance . now ) ( ) / <NUM_LIT> <EOL> def perf_counter ( ) : <EOL> return float ( date ( ) . getTime ( ) / <NUM_LIT> ) <EOL> def time ( ) : <EOL> return float ( date ( ) . getTime ( ) / <NUM_LIT:1000> ) <EOL> def sleep ( secs ) : <EOL> start = date ( ) . getTime ( ) <EOL> while date ( ) . getTime ( ) - start < secs * <NUM_LIT> : <EOL> pass <EOL> def strftime ( _format , t = None ) : <EOL> def ns ( t , nb ) : <EOL> res = str ( t ) <EOL> while len ( res ) < nb : <EOL> res = '<STR_LIT:0>' + res <EOL> return res <EOL> t = _check_input ( t ) <EOL> t = _check_struct_time ( t ) <EOL> YY = ns ( t [ <NUM_LIT:0> ] , <NUM_LIT:4> ) <EOL> yy = ns ( t [ <NUM_LIT:0> ] , <NUM_LIT:4> ) [ <NUM_LIT:2> : ] <EOL> mm = ns ( t [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> dd = ns ( t [ <NUM_LIT:2> ] , <NUM_LIT:2> ) <EOL> HH = t [ <NUM_LIT:3> ] <EOL> HH24 = ns ( HH , <NUM_LIT:2> ) <EOL> HH12 = ns ( HH % <NUM_LIT:12> , <NUM_LIT:2> ) <EOL> if HH12 == <NUM_LIT:0> : HH12 = <NUM_LIT:12> <EOL> AMPM = '<STR_LIT>' if <NUM_LIT:0> <= HH < <NUM_LIT:12> else '<STR_LIT>' <EOL> MM = ns ( t [ <NUM_LIT:4> ] , <NUM_LIT:2> ) <EOL> SS = ns ( t [ <NUM_LIT:5> ] , <NUM_LIT:2> ) <EOL> DoY = ns ( t [ <NUM_LIT:7> ] , <NUM_LIT:3> ) <EOL> w = t [ <NUM_LIT:6> ] + <NUM_LIT:1> if t [ <NUM_LIT:6> ] < <NUM_LIT:6> else <NUM_LIT:0> <EOL> W = ns ( _get_week_of_year ( t ) , <NUM_LIT:2> ) <EOL> abb_weekdays = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> full_weekdays = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> abb_months = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> full_months = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> res = _format <EOL> res = res . replace ( "<STR_LIT>" , HH24 ) <EOL> res = res . replace ( "<STR_LIT>" , HH12 ) <EOL> res = res . replace ( "<STR_LIT>" , AMPM ) <EOL> res = res . replace ( "<STR_LIT>" , MM ) <EOL> res = res . replace ( "<STR_LIT>" , SS ) <EOL> res = res . replace ( "<STR_LIT>" , YY ) <EOL> res = res . replace ( "<STR_LIT>" , yy ) <EOL> res = res . replace ( "<STR_LIT>" , mm ) <EOL> res = res . replace ( "<STR_LIT>" , dd ) <EOL> res = res . replace ( "<STR_LIT>" , abb_weekdays [ w ] ) <EOL> res = res . replace ( "<STR_LIT>" , full_weekdays [ w ] ) <EOL> res = res . replace ( "<STR_LIT>" , abb_months [ int ( mm ) - <NUM_LIT:1> ] ) <EOL> res = res . replace ( "<STR_LIT>" , full_months [ int ( mm ) - <NUM_LIT:1> ] ) <EOL> res = res . replace ( "<STR_LIT>" , DoY ) <EOL> res = res . replace ( "<STR_LIT>" , str ( w ) ) <EOL> res = res . replace ( "<STR_LIT>" , W ) <EOL> res = res . replace ( "<STR_LIT>" , mm + '<STR_LIT:/>' + dd + '<STR_LIT:/>' + yy ) <EOL> res = res . replace ( "<STR_LIT>" , HH24 + '<STR_LIT::>' + MM + '<STR_LIT::>' + SS ) <EOL> res = res . replace ( "<STR_LIT>" , abb_weekdays [ w ] + '<STR_LIT:U+0020>' + abb_months [ int ( mm ) - <NUM_LIT:1> ] + <EOL> '<STR_LIT:U+0020>' + dd + '<STR_LIT:U+0020>' + HH24 + '<STR_LIT::>' + MM + '<STR_LIT::>' + SS + '<STR_LIT:U+0020>' + YY ) <EOL> res = res . replace ( "<STR_LIT>" , '<STR_LIT:%>' ) <EOL> return res <EOL> class struct_time : <EOL> def __init__ ( self , args ) : <EOL> if len ( args ) != <NUM_LIT:9> : <EOL> raise TypeError ( "<STR_LIT>" % len ( args ) ) <EOL> self . args = args <EOL> @ property <EOL> def tm_year ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] <EOL> @ property <EOL> def tm_mon ( self ) : <EOL> return self . args [ <NUM_LIT:1> ] <EOL> @ property <EOL> def tm_mday ( self ) : <EOL> return self . args [ <NUM_LIT:2> ] <EOL> @ property <EOL> def tm_hour ( self ) : <EOL> return self . args [ <NUM_LIT:3> ] <EOL> @ property <EOL> def tm_min ( self ) : <EOL> return self . args [ <NUM_LIT:4> ] <EOL> @ property <EOL> def tm_sec ( self ) : <EOL> return self . args [ <NUM_LIT:5> ] <EOL> @ property <EOL> def tm_wday ( self ) : <EOL> return self . args [ <NUM_LIT:6> ] <EOL> @ property <EOL> def tm_yday ( self ) : <EOL> return self . args [ <NUM_LIT:7> ] <EOL> @ property <EOL> def tm_isdst ( self ) : <EOL> return self . args [ <NUM_LIT:8> ] <EOL> def __getitem__ ( self , i ) : <EOL> return self . args [ i ] <EOL> def __iter__ ( self ) : <EOL> return iter ( self . args ) <EOL> def __repr__ ( self ) : <EOL> return ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) . format ( * self . args ) <EOL> def __str__ ( self ) : <EOL> return self . __repr__ ( ) <EOL> def to_struct_time ( * arg ) : <EOL> arg = list ( arg ) <EOL> ml = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> ] <EOL> if arg [ <NUM_LIT:0> ] % <NUM_LIT:4> == <NUM_LIT:0> : <EOL> ml [ <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> i = <NUM_LIT:1> <EOL> yday = <NUM_LIT:0> <EOL> while i < arg [ <NUM_LIT:1> ] : <EOL> yday += ml [ i - <NUM_LIT:1> ] <EOL> i += <NUM_LIT:1> <EOL> yday += arg [ <NUM_LIT:2> ] <EOL> arg . append ( yday ) <EOL> arg . append ( - <NUM_LIT:1> ) <EOL> return struct_time ( tuple ( arg ) ) <EOL> def strptime ( string , _format ) : <EOL> import _strptime <EOL> return _strptime . _strptime_datetime ( to_struct_time , string , _format ) <EOL> _clock_msg = """<STR_LIT>""" <EOL> def _clock_xx ( url ) : <EOL> raise NotImplementedError ( _clock_msg % url ) <EOL> clock = lambda : _clock_xx ( "<STR_LIT>" ) <EOL> clock_getres = lambda : _clock_xx ( "<STR_LIT>" ) <EOL> clock_gettime = lambda : _clock_xx ( "<STR_LIT>" ) <EOL> clock_settime = lambda : _clock_xx ( "<STR_LIT>" ) <EOL> CLOCK_HIGHRES = _clock_msg % "<STR_LIT>" <EOL> CLOCK_MONOTONIC = _clock_msg % "<STR_LIT>" <EOL> CLOCK_MONOTONIC_RAW = _clock_msg % "<STR_LIT>" <EOL> CLOCK_PROCESS_CPUTIME_ID = _clock_msg % "<STR_LIT>" <EOL> CLOCK_REALTIME = _clock_msg % "<STR_LIT>" <EOL> CLOCK_THREAD_CPUTIME_ID = _clock_msg % "<STR_LIT>" <EOL> get_clock_info = lambda : _clock_xx ( "<STR_LIT>" ) <EOL> process_time = lambda : _clock_xx ( "<STR_LIT>" ) <EOL> def tzset ( ) : <EOL> raise NotImplementedError ( ) </s>
