<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import datetime <EOL> import string <EOL> import time <EOL> import collections <EOL> import re <EOL> from io import StringIO <EOL> from calendar import monthrange , isleap <EOL> from six import text_type , binary_type , integer_types <EOL> from . import relativedelta <EOL> from . import tz <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> class _timelex ( object ) : <EOL> _split_decimal = re . compile ( "<STR_LIT>" ) <EOL> def __init__ ( self , instream ) : <EOL> if isinstance ( instream , binary_type ) : <EOL> instream = instream . decode ( ) <EOL> if isinstance ( instream , text_type ) : <EOL> instream = StringIO ( instream ) <EOL> if getattr ( instream , '<STR_LIT>' , None ) is None : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( itype = instream . __class__ . __name__ ) ) <EOL> self . instream = instream <EOL> self . charstack = [ ] <EOL> self . tokenstack = [ ] <EOL> self . eof = False <EOL> def get_token ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . tokenstack : <EOL> return self . tokenstack . pop ( <NUM_LIT:0> ) <EOL> seenletters = False <EOL> token = None <EOL> state = None <EOL> while not self . eof : <EOL> if self . charstack : <EOL> nextchar = self . charstack . pop ( <NUM_LIT:0> ) <EOL> else : <EOL> nextchar = self . instream . read ( <NUM_LIT:1> ) <EOL> while nextchar == '<STR_LIT:\x00>' : <EOL> nextchar = self . instream . read ( <NUM_LIT:1> ) <EOL> if not nextchar : <EOL> self . eof = True <EOL> break <EOL> elif not state : <EOL> token = nextchar <EOL> if self . isword ( nextchar ) : <EOL> state = '<STR_LIT:a>' <EOL> elif self . isnum ( nextchar ) : <EOL> state = '<STR_LIT:0>' <EOL> elif self . isspace ( nextchar ) : <EOL> token = '<STR_LIT:U+0020>' <EOL> break <EOL> else : <EOL> break <EOL> elif state == '<STR_LIT:a>' : <EOL> seenletters = True <EOL> if self . isword ( nextchar ) : <EOL> token += nextchar <EOL> elif nextchar == '<STR_LIT:.>' : <EOL> token += nextchar <EOL> state = '<STR_LIT>' <EOL> else : <EOL> self . charstack . append ( nextchar ) <EOL> break <EOL> elif state == '<STR_LIT:0>' : <EOL> if self . isnum ( nextchar ) : <EOL> token += nextchar <EOL> elif nextchar == '<STR_LIT:.>' or ( nextchar == '<STR_LIT:U+002C>' and len ( token ) >= <NUM_LIT:2> ) : <EOL> token += nextchar <EOL> state = '<STR_LIT>' <EOL> else : <EOL> self . charstack . append ( nextchar ) <EOL> break <EOL> elif state == '<STR_LIT>' : <EOL> seenletters = True <EOL> if nextchar == '<STR_LIT:.>' or self . isword ( nextchar ) : <EOL> token += nextchar <EOL> elif self . isnum ( nextchar ) and token [ - <NUM_LIT:1> ] == '<STR_LIT:.>' : <EOL> token += nextchar <EOL> state = '<STR_LIT>' <EOL> else : <EOL> self . charstack . append ( nextchar ) <EOL> break <EOL> elif state == '<STR_LIT>' : <EOL> if nextchar == '<STR_LIT:.>' or self . isnum ( nextchar ) : <EOL> token += nextchar <EOL> elif self . isword ( nextchar ) and token [ - <NUM_LIT:1> ] == '<STR_LIT:.>' : <EOL> token += nextchar <EOL> state = '<STR_LIT>' <EOL> else : <EOL> self . charstack . append ( nextchar ) <EOL> break <EOL> if ( state in ( '<STR_LIT>' , '<STR_LIT>' ) and ( seenletters or token . count ( '<STR_LIT:.>' ) > <NUM_LIT:1> or <EOL> token [ - <NUM_LIT:1> ] in '<STR_LIT>' ) ) : <EOL> l = self . _split_decimal . split ( token ) <EOL> token = l [ <NUM_LIT:0> ] <EOL> for tok in l [ <NUM_LIT:1> : ] : <EOL> if tok : <EOL> self . tokenstack . append ( tok ) <EOL> if state == '<STR_LIT>' and token . count ( '<STR_LIT:.>' ) == <NUM_LIT:0> : <EOL> token = token . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:.>' ) <EOL> return token <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> token = self . get_token ( ) <EOL> if token is None : <EOL> raise StopIteration <EOL> return token <EOL> def next ( self ) : <EOL> return self . __next__ ( ) <EOL> @ classmethod <EOL> def split ( cls , s ) : <EOL> return list ( cls ( s ) ) <EOL> @ classmethod <EOL> def isword ( cls , nextchar ) : <EOL> """<STR_LIT>""" <EOL> return nextchar . isalpha ( ) <EOL> @ classmethod <EOL> def isnum ( cls , nextchar ) : <EOL> """<STR_LIT>""" <EOL> return nextchar . isdigit ( ) <EOL> @ classmethod <EOL> def isspace ( cls , nextchar ) : <EOL> """<STR_LIT>""" <EOL> return nextchar . isspace ( ) <EOL> class _resultbase ( object ) : <EOL> def __init__ ( self ) : <EOL> for attr in self . __slots__ : <EOL> setattr ( self , attr , None ) <EOL> def _repr ( self , classname ) : <EOL> l = [ ] <EOL> for attr in self . __slots__ : <EOL> value = getattr ( self , attr ) <EOL> if value is not None : <EOL> l . append ( "<STR_LIT>" % ( attr , repr ( value ) ) ) <EOL> return "<STR_LIT>" % ( classname , "<STR_LIT:U+002CU+0020>" . join ( l ) ) <EOL> def __len__ ( self ) : <EOL> return ( sum ( getattr ( self , attr ) is not None <EOL> for attr in self . __slots__ ) ) <EOL> def __repr__ ( self ) : <EOL> return self . _repr ( self . __class__ . __name__ ) <EOL> class parserinfo ( object ) : <EOL> """<STR_LIT>""" <EOL> JUMP = [ "<STR_LIT:U+0020>" , "<STR_LIT:.>" , "<STR_LIT:U+002C>" , "<STR_LIT:;>" , "<STR_LIT:->" , "<STR_LIT:/>" , "<STR_LIT:'>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:m>" , "<STR_LIT:t>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> WEEKDAYS = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> MONTHS = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> HMS = [ ( "<STR_LIT:h>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:m>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:s>" , "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> AMPM = [ ( "<STR_LIT>" , "<STR_LIT:a>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:p>" ) ] <EOL> UTCZONE = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> PERTAIN = [ "<STR_LIT>" ] <EOL> TZOFFSET = { } <EOL> def __init__ ( self , dayfirst = False , yearfirst = False ) : <EOL> self . _jump = self . _convert ( self . JUMP ) <EOL> self . _weekdays = self . _convert ( self . WEEKDAYS ) <EOL> self . _months = self . _convert ( self . MONTHS ) <EOL> self . _hms = self . _convert ( self . HMS ) <EOL> self . _ampm = self . _convert ( self . AMPM ) <EOL> self . _utczone = self . _convert ( self . UTCZONE ) <EOL> self . _pertain = self . _convert ( self . PERTAIN ) <EOL> self . dayfirst = dayfirst <EOL> self . yearfirst = yearfirst <EOL> self . _year = time . localtime ( ) . tm_year <EOL> self . _century = self . _year // <NUM_LIT:100> * <NUM_LIT:100> <EOL> def _convert ( self , lst ) : <EOL> dct = { } <EOL> for i , v in enumerate ( lst ) : <EOL> if isinstance ( v , tuple ) : <EOL> for v in v : <EOL> dct [ v . lower ( ) ] = i <EOL> else : <EOL> dct [ v . lower ( ) ] = i <EOL> return dct <EOL> def jump ( self , name ) : <EOL> return name . lower ( ) in self . _jump <EOL> def weekday ( self , name ) : <EOL> if len ( name ) >= <NUM_LIT:3> : <EOL> try : <EOL> return self . _weekdays [ name . lower ( ) ] <EOL> except KeyError : <EOL> pass <EOL> return None <EOL> def month ( self , name ) : <EOL> if len ( name ) >= <NUM_LIT:3> : <EOL> try : <EOL> return self . _months [ name . lower ( ) ] + <NUM_LIT:1> <EOL> except KeyError : <EOL> pass <EOL> return None <EOL> def hms ( self , name ) : <EOL> try : <EOL> return self . _hms [ name . lower ( ) ] <EOL> except KeyError : <EOL> return None <EOL> def ampm ( self , name ) : <EOL> try : <EOL> return self . _ampm [ name . lower ( ) ] <EOL> except KeyError : <EOL> return None <EOL> def pertain ( self , name ) : <EOL> return name . lower ( ) in self . _pertain <EOL> def utczone ( self , name ) : <EOL> return name . lower ( ) in self . _utczone <EOL> def tzoffset ( self , name ) : <EOL> if name in self . _utczone : <EOL> return <NUM_LIT:0> <EOL> return self . TZOFFSET . get ( name ) <EOL> def convertyear ( self , year , century_specified = False ) : <EOL> if year < <NUM_LIT:100> and not century_specified : <EOL> year += self . _century <EOL> if abs ( year - self . _year ) >= <NUM_LIT:50> : <EOL> if year < self . _year : <EOL> year += <NUM_LIT:100> <EOL> else : <EOL> year -= <NUM_LIT:100> <EOL> return year <EOL> def validate ( self , res ) : <EOL> if res . year is not None : <EOL> res . year = self . convertyear ( res . year , res . century_specified ) <EOL> if res . tzoffset == <NUM_LIT:0> and not res . tzname or res . tzname == '<STR_LIT>' : <EOL> res . tzname = "<STR_LIT>" <EOL> res . tzoffset = <NUM_LIT:0> <EOL> elif res . tzoffset != <NUM_LIT:0> and res . tzname and self . utczone ( res . tzname ) : <EOL> res . tzoffset = <NUM_LIT:0> <EOL> return True <EOL> class _ymd ( list ) : <EOL> def __init__ ( self , tzstr , * args , ** kwargs ) : <EOL> super ( self . __class__ , self ) . __init__ ( * args , ** kwargs ) <EOL> self . century_specified = False <EOL> self . tzstr = tzstr <EOL> @ staticmethod <EOL> def token_could_be_year ( token , year ) : <EOL> try : <EOL> return int ( token ) == year <EOL> except ValueError : <EOL> return False <EOL> @ staticmethod <EOL> def find_potential_year_tokens ( year , tokens ) : <EOL> return [ token for token in tokens if _ymd . token_could_be_year ( token , year ) ] <EOL> def find_probable_year_index ( self , tokens ) : <EOL> """<STR_LIT>""" <EOL> for index , token in enumerate ( self ) : <EOL> potential_year_tokens = _ymd . find_potential_year_tokens ( token , tokens ) <EOL> if len ( potential_year_tokens ) == <NUM_LIT:1> and len ( potential_year_tokens [ <NUM_LIT:0> ] ) > <NUM_LIT:2> : <EOL> return index <EOL> def append ( self , val ) : <EOL> if hasattr ( val , '<STR_LIT>' ) : <EOL> if val . isdigit ( ) and len ( val ) > <NUM_LIT:2> : <EOL> self . century_specified = True <EOL> elif val > <NUM_LIT:100> : <EOL> self . century_specified = True <EOL> super ( self . __class__ , self ) . append ( int ( val ) ) <EOL> def resolve_ymd ( self , mstridx , yearfirst , dayfirst ) : <EOL> len_ymd = len ( self ) <EOL> year , month , day = ( None , None , None ) <EOL> if len_ymd > <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif len_ymd == <NUM_LIT:1> or ( mstridx != - <NUM_LIT:1> and len_ymd == <NUM_LIT:2> ) : <EOL> if mstridx != - <NUM_LIT:1> : <EOL> month = self [ mstridx ] <EOL> del self [ mstridx ] <EOL> if len_ymd > <NUM_LIT:1> or mstridx == - <NUM_LIT:1> : <EOL> if self [ <NUM_LIT:0> ] > <NUM_LIT> : <EOL> year = self [ <NUM_LIT:0> ] <EOL> else : <EOL> day = self [ <NUM_LIT:0> ] <EOL> elif len_ymd == <NUM_LIT:2> : <EOL> if self [ <NUM_LIT:0> ] > <NUM_LIT> : <EOL> year , month = self <EOL> elif self [ <NUM_LIT:1> ] > <NUM_LIT> : <EOL> month , year = self <EOL> elif dayfirst and self [ <NUM_LIT:1> ] <= <NUM_LIT:12> : <EOL> day , month = self <EOL> else : <EOL> month , day = self <EOL> elif len_ymd == <NUM_LIT:3> : <EOL> if mstridx == <NUM_LIT:0> : <EOL> month , day , year = self <EOL> elif mstridx == <NUM_LIT:1> : <EOL> if self [ <NUM_LIT:0> ] > <NUM_LIT> or ( yearfirst and self [ <NUM_LIT:2> ] <= <NUM_LIT> ) : <EOL> year , month , day = self <EOL> else : <EOL> day , month , year = self <EOL> elif mstridx == <NUM_LIT:2> : <EOL> if self [ <NUM_LIT:1> ] > <NUM_LIT> : <EOL> day , year , month = self <EOL> else : <EOL> year , day , month = self <EOL> else : <EOL> if self [ <NUM_LIT:0> ] > <NUM_LIT> or self . find_probable_year_index ( _timelex . split ( self . tzstr ) ) == <NUM_LIT:0> or ( yearfirst and self [ <NUM_LIT:1> ] <= <NUM_LIT:12> and self [ <NUM_LIT:2> ] <= <NUM_LIT> ) : <EOL> if dayfirst and self [ <NUM_LIT:2> ] <= <NUM_LIT:12> : <EOL> year , day , month = self <EOL> else : <EOL> year , month , day = self <EOL> elif self [ <NUM_LIT:0> ] > <NUM_LIT:12> or ( dayfirst and self [ <NUM_LIT:1> ] <= <NUM_LIT:12> ) : <EOL> day , month , year = self <EOL> else : <EOL> month , day , year = self <EOL> return year , month , day <EOL> class parser ( object ) : <EOL> def __init__ ( self , info = None ) : <EOL> self . info = info or parserinfo ( ) <EOL> def parse ( self , timestr , default = None , ignoretz = False , tzinfos = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if default is None : <EOL> effective_dt = datetime . datetime . now ( ) <EOL> default = datetime . datetime . now ( ) . replace ( hour = <NUM_LIT:0> , minute = <NUM_LIT:0> , <EOL> second = <NUM_LIT:0> , microsecond = <NUM_LIT:0> ) <EOL> else : <EOL> effective_dt = default <EOL> res , skipped_tokens = self . _parse ( timestr , ** kwargs ) <EOL> if res is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( res ) == <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> repl = { } <EOL> for attr in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> value = getattr ( res , attr ) <EOL> if value is not None : <EOL> repl [ attr ] = value <EOL> if '<STR_LIT>' not in repl : <EOL> cyear = default . year if res . year is None else res . year <EOL> cmonth = default . month if res . month is None else res . month <EOL> cday = default . day if res . day is None else res . day <EOL> if cday > monthrange ( cyear , cmonth ) [ <NUM_LIT:1> ] : <EOL> repl [ '<STR_LIT>' ] = monthrange ( cyear , cmonth ) [ <NUM_LIT:1> ] <EOL> ret = default . replace ( ** repl ) <EOL> if res . weekday is not None and not res . day : <EOL> ret = ret + relativedelta . relativedelta ( weekday = res . weekday ) <EOL> if not ignoretz : <EOL> if ( isinstance ( tzinfos , collections . Callable ) or <EOL> tzinfos and res . tzname in tzinfos ) : <EOL> if isinstance ( tzinfos , collections . Callable ) : <EOL> tzdata = tzinfos ( res . tzname , res . tzoffset ) <EOL> else : <EOL> tzdata = tzinfos . get ( res . tzname ) <EOL> if isinstance ( tzdata , datetime . tzinfo ) : <EOL> tzinfo = tzdata <EOL> elif isinstance ( tzdata , text_type ) : <EOL> tzinfo = tz . tzstr ( tzdata ) <EOL> elif isinstance ( tzdata , integer_types ) : <EOL> tzinfo = tz . tzoffset ( res . tzname , tzdata ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ret = ret . replace ( tzinfo = tzinfo ) <EOL> elif res . tzname and res . tzname in time . tzname : <EOL> ret = ret . replace ( tzinfo = tz . tzlocal ( ) ) <EOL> elif res . tzoffset == <NUM_LIT:0> : <EOL> ret = ret . replace ( tzinfo = tz . tzutc ( ) ) <EOL> elif res . tzoffset : <EOL> ret = ret . replace ( tzinfo = tz . tzoffset ( res . tzname , res . tzoffset ) ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) : <EOL> return ret , skipped_tokens <EOL> else : <EOL> return ret <EOL> class _result ( _resultbase ) : <EOL> __slots__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def _parse ( self , timestr , dayfirst = None , yearfirst = None , fuzzy = False , <EOL> fuzzy_with_tokens = False ) : <EOL> """<STR_LIT>""" <EOL> if fuzzy_with_tokens : <EOL> fuzzy = True <EOL> info = self . info <EOL> if dayfirst is None : <EOL> dayfirst = info . dayfirst <EOL> if yearfirst is None : <EOL> yearfirst = info . yearfirst <EOL> res = self . _result ( ) <EOL> l = _timelex . split ( timestr ) <EOL> last_skipped_token_i = - <NUM_LIT:2> <EOL> skipped_tokens = list ( ) <EOL> try : <EOL> ymd = _ymd ( timestr ) <EOL> mstridx = - <NUM_LIT:1> <EOL> len_l = len ( l ) <EOL> i = <NUM_LIT:0> <EOL> while i < len_l : <EOL> try : <EOL> value_repr = l [ i ] <EOL> value = float ( value_repr ) <EOL> except ValueError : <EOL> value = None <EOL> if value is not None : <EOL> len_li = len ( l [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> if ( len ( ymd ) == <NUM_LIT:3> and len_li in ( <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> and res . hour is None and ( i >= len_l or ( l [ i ] != '<STR_LIT::>' and <EOL> info . hms ( l [ i ] ) is None ) ) ) : <EOL> s = l [ i - <NUM_LIT:1> ] <EOL> res . hour = int ( s [ : <NUM_LIT:2> ] ) <EOL> if len_li == <NUM_LIT:4> : <EOL> res . minute = int ( s [ <NUM_LIT:2> : ] ) <EOL> elif len_li == <NUM_LIT:6> or ( len_li > <NUM_LIT:6> and l [ i - <NUM_LIT:1> ] . find ( '<STR_LIT:.>' ) == <NUM_LIT:6> ) : <EOL> s = l [ i - <NUM_LIT:1> ] <EOL> if not ymd and l [ i - <NUM_LIT:1> ] . find ( '<STR_LIT:.>' ) == - <NUM_LIT:1> : <EOL> ymd . append ( s [ : <NUM_LIT:2> ] ) <EOL> ymd . append ( s [ <NUM_LIT:2> : <NUM_LIT:4> ] ) <EOL> ymd . append ( s [ <NUM_LIT:4> : ] ) <EOL> else : <EOL> res . hour = int ( s [ : <NUM_LIT:2> ] ) <EOL> res . minute = int ( s [ <NUM_LIT:2> : <NUM_LIT:4> ] ) <EOL> res . second , res . microsecond = _parsems ( s [ <NUM_LIT:4> : ] ) <EOL> elif len_li in ( <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT> ) : <EOL> s = l [ i - <NUM_LIT:1> ] <EOL> ymd . append ( s [ : <NUM_LIT:4> ] ) <EOL> ymd . append ( s [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> ymd . append ( s [ <NUM_LIT:6> : <NUM_LIT:8> ] ) <EOL> if len_li > <NUM_LIT:8> : <EOL> res . hour = int ( s [ <NUM_LIT:8> : <NUM_LIT:10> ] ) <EOL> res . minute = int ( s [ <NUM_LIT:10> : <NUM_LIT:12> ] ) <EOL> if len_li > <NUM_LIT:12> : <EOL> res . second = int ( s [ <NUM_LIT:12> : ] ) <EOL> elif ( ( i < len_l and info . hms ( l [ i ] ) is not None ) or <EOL> ( i + <NUM_LIT:1> < len_l and l [ i ] == '<STR_LIT:U+0020>' and <EOL> info . hms ( l [ i + <NUM_LIT:1> ] ) is not None ) ) : <EOL> if l [ i ] == '<STR_LIT:U+0020>' : <EOL> i += <NUM_LIT:1> <EOL> idx = info . hms ( l [ i ] ) <EOL> while True : <EOL> if idx == <NUM_LIT:0> : <EOL> res . hour = int ( value ) <EOL> if value % <NUM_LIT:1> : <EOL> res . minute = int ( <NUM_LIT> * ( value % <NUM_LIT:1> ) ) <EOL> elif idx == <NUM_LIT:1> : <EOL> res . minute = int ( value ) <EOL> if value % <NUM_LIT:1> : <EOL> res . second = int ( <NUM_LIT> * ( value % <NUM_LIT:1> ) ) <EOL> elif idx == <NUM_LIT:2> : <EOL> res . second , res . microsecond = _parsems ( value_repr ) <EOL> i += <NUM_LIT:1> <EOL> if i >= len_l or idx == <NUM_LIT:2> : <EOL> break <EOL> try : <EOL> value_repr = l [ i ] <EOL> value = float ( value_repr ) <EOL> except ValueError : <EOL> break <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> idx += <NUM_LIT:1> <EOL> if i < len_l : <EOL> newidx = info . hms ( l [ i ] ) <EOL> if newidx is not None : <EOL> idx = newidx <EOL> elif ( i == len_l and l [ i - <NUM_LIT:2> ] == '<STR_LIT:U+0020>' and <EOL> info . hms ( l [ i - <NUM_LIT:3> ] ) is not None ) : <EOL> idx = info . hms ( l [ i - <NUM_LIT:3> ] ) + <NUM_LIT:1> <EOL> if idx == <NUM_LIT:1> : <EOL> res . minute = int ( value ) <EOL> if value % <NUM_LIT:1> : <EOL> res . second = int ( <NUM_LIT> * ( value % <NUM_LIT:1> ) ) <EOL> elif idx == <NUM_LIT:2> : <EOL> res . second , res . microsecond = _parsems ( value_repr ) <EOL> i += <NUM_LIT:1> <EOL> elif i + <NUM_LIT:1> < len_l and l [ i ] == '<STR_LIT::>' : <EOL> res . hour = int ( value ) <EOL> i += <NUM_LIT:1> <EOL> value = float ( l [ i ] ) <EOL> res . minute = int ( value ) <EOL> if value % <NUM_LIT:1> : <EOL> res . second = int ( <NUM_LIT> * ( value % <NUM_LIT:1> ) ) <EOL> i += <NUM_LIT:1> <EOL> if i < len_l and l [ i ] == '<STR_LIT::>' : <EOL> res . second , res . microsecond = _parsems ( l [ i + <NUM_LIT:1> ] ) <EOL> i += <NUM_LIT:2> <EOL> elif i < len_l and l [ i ] in ( '<STR_LIT:->' , '<STR_LIT:/>' , '<STR_LIT:.>' ) : <EOL> sep = l [ i ] <EOL> ymd . append ( value_repr ) <EOL> i += <NUM_LIT:1> <EOL> if i < len_l and not info . jump ( l [ i ] ) : <EOL> try : <EOL> ymd . append ( l [ i ] ) <EOL> except ValueError : <EOL> value = info . month ( l [ i ] ) <EOL> if value is not None : <EOL> ymd . append ( value ) <EOL> assert mstridx == - <NUM_LIT:1> <EOL> mstridx = len ( ymd ) - <NUM_LIT:1> <EOL> else : <EOL> return None , None <EOL> i += <NUM_LIT:1> <EOL> if i < len_l and l [ i ] == sep : <EOL> i += <NUM_LIT:1> <EOL> value = info . month ( l [ i ] ) <EOL> if value is not None : <EOL> ymd . append ( value ) <EOL> mstridx = len ( ymd ) - <NUM_LIT:1> <EOL> assert mstridx == - <NUM_LIT:1> <EOL> else : <EOL> ymd . append ( l [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> elif i >= len_l or info . jump ( l [ i ] ) : <EOL> if i + <NUM_LIT:1> < len_l and info . ampm ( l [ i + <NUM_LIT:1> ] ) is not None : <EOL> res . hour = int ( value ) <EOL> if res . hour < <NUM_LIT:12> and info . ampm ( l [ i + <NUM_LIT:1> ] ) == <NUM_LIT:1> : <EOL> res . hour += <NUM_LIT:12> <EOL> elif res . hour == <NUM_LIT:12> and info . ampm ( l [ i + <NUM_LIT:1> ] ) == <NUM_LIT:0> : <EOL> res . hour = <NUM_LIT:0> <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> ymd . append ( value ) <EOL> i += <NUM_LIT:1> <EOL> elif info . ampm ( l [ i ] ) is not None : <EOL> res . hour = int ( value ) <EOL> if res . hour < <NUM_LIT:12> and info . ampm ( l [ i ] ) == <NUM_LIT:1> : <EOL> res . hour += <NUM_LIT:12> <EOL> elif res . hour == <NUM_LIT:12> and info . ampm ( l [ i ] ) == <NUM_LIT:0> : <EOL> res . hour = <NUM_LIT:0> <EOL> i += <NUM_LIT:1> <EOL> elif not fuzzy : <EOL> return None , None <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> value = info . weekday ( l [ i ] ) <EOL> if value is not None : <EOL> res . weekday = value <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> value = info . month ( l [ i ] ) <EOL> if value is not None : <EOL> ymd . append ( value ) <EOL> assert mstridx == - <NUM_LIT:1> <EOL> mstridx = len ( ymd ) - <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> if i < len_l : <EOL> if l [ i ] in ( '<STR_LIT:->' , '<STR_LIT:/>' ) : <EOL> sep = l [ i ] <EOL> i += <NUM_LIT:1> <EOL> ymd . append ( l [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> if i < len_l and l [ i ] == sep : <EOL> i += <NUM_LIT:1> <EOL> ymd . append ( l [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> elif ( i + <NUM_LIT:3> < len_l and l [ i ] == l [ i + <NUM_LIT:2> ] == '<STR_LIT:U+0020>' <EOL> and info . pertain ( l [ i + <NUM_LIT:1> ] ) ) : <EOL> try : <EOL> value = int ( l [ i + <NUM_LIT:3> ] ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> ymd . append ( str ( info . convertyear ( value ) ) ) <EOL> i += <NUM_LIT:4> <EOL> continue <EOL> value = info . ampm ( l [ i ] ) <EOL> if value is not None : <EOL> val_is_ampm = True <EOL> if fuzzy and res . ampm is not None : <EOL> val_is_ampm = False <EOL> if res . hour is None : <EOL> if fuzzy : <EOL> val_is_ampm = False <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> elif not <NUM_LIT:0> <= res . hour <= <NUM_LIT:12> : <EOL> if fuzzy : <EOL> val_is_ampm = False <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> if val_is_ampm : <EOL> if value == <NUM_LIT:1> and res . hour < <NUM_LIT:12> : <EOL> res . hour += <NUM_LIT:12> <EOL> elif value == <NUM_LIT:0> and res . hour == <NUM_LIT:12> : <EOL> res . hour = <NUM_LIT:0> <EOL> res . ampm = value <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> if ( res . hour is not None and len ( l [ i ] ) <= <NUM_LIT:5> and <EOL> res . tzname is None and res . tzoffset is None and <EOL> not [ x for x in l [ i ] if x not in <EOL> string . ascii_uppercase ] ) : <EOL> res . tzname = l [ i ] <EOL> res . tzoffset = info . tzoffset ( res . tzname ) <EOL> i += <NUM_LIT:1> <EOL> if i < len_l and l [ i ] in ( '<STR_LIT:+>' , '<STR_LIT:->' ) : <EOL> l [ i ] = ( '<STR_LIT:+>' , '<STR_LIT:->' ) [ l [ i ] == '<STR_LIT:+>' ] <EOL> res . tzoffset = None <EOL> if info . utczone ( res . tzname ) : <EOL> res . tzname = None <EOL> continue <EOL> if res . hour is not None and l [ i ] in ( '<STR_LIT:+>' , '<STR_LIT:->' ) : <EOL> signal = ( - <NUM_LIT:1> , <NUM_LIT:1> ) [ l [ i ] == '<STR_LIT:+>' ] <EOL> i += <NUM_LIT:1> <EOL> len_li = len ( l [ i ] ) <EOL> if len_li == <NUM_LIT:4> : <EOL> res . tzoffset = int ( l [ i ] [ : <NUM_LIT:2> ] ) * <NUM_LIT> + int ( l [ i ] [ <NUM_LIT:2> : ] ) * <NUM_LIT> <EOL> elif i + <NUM_LIT:1> < len_l and l [ i + <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> res . tzoffset = int ( l [ i ] ) * <NUM_LIT> + int ( l [ i + <NUM_LIT:2> ] ) * <NUM_LIT> <EOL> i += <NUM_LIT:2> <EOL> elif len_li <= <NUM_LIT:2> : <EOL> res . tzoffset = int ( l [ i ] [ : <NUM_LIT:2> ] ) * <NUM_LIT> <EOL> else : <EOL> return None , None <EOL> i += <NUM_LIT:1> <EOL> res . tzoffset *= signal <EOL> if ( i + <NUM_LIT:3> < len_l and <EOL> info . jump ( l [ i ] ) and l [ i + <NUM_LIT:1> ] == '<STR_LIT:(>' and l [ i + <NUM_LIT:3> ] == '<STR_LIT:)>' and <EOL> <NUM_LIT:3> <= len ( l [ i + <NUM_LIT:2> ] ) <= <NUM_LIT:5> and <EOL> not [ x for x in l [ i + <NUM_LIT:2> ] <EOL> if x not in string . ascii_uppercase ] ) : <EOL> res . tzname = l [ i + <NUM_LIT:2> ] <EOL> i += <NUM_LIT:4> <EOL> continue <EOL> if not ( info . jump ( l [ i ] ) or fuzzy ) : <EOL> return None , None <EOL> if last_skipped_token_i == i - <NUM_LIT:1> : <EOL> skipped_tokens [ - <NUM_LIT:1> ] += l [ i ] <EOL> else : <EOL> skipped_tokens . append ( l [ i ] ) <EOL> last_skipped_token_i = i <EOL> i += <NUM_LIT:1> <EOL> year , month , day = ymd . resolve_ymd ( mstridx , yearfirst , dayfirst ) <EOL> if year is not None : <EOL> res . year = year <EOL> res . century_specified = ymd . century_specified <EOL> if month is not None : <EOL> res . month = month <EOL> if day is not None : <EOL> res . day = day <EOL> except ( IndexError , ValueError , AssertionError ) : <EOL> return None , None <EOL> if not info . validate ( res ) : <EOL> return None , None <EOL> if fuzzy_with_tokens : <EOL> return res , tuple ( skipped_tokens ) <EOL> else : <EOL> return res , None <EOL> DEFAULTPARSER = parser ( ) <EOL> def parse ( timestr , parserinfo = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if parserinfo : <EOL> return parser ( parserinfo ) . parse ( timestr , ** kwargs ) <EOL> else : <EOL> return DEFAULTPARSER . parse ( timestr , ** kwargs ) <EOL> class _tzparser ( object ) : <EOL> class _result ( _resultbase ) : <EOL> __slots__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:start>" , "<STR_LIT:end>" ] <EOL> class _attr ( _resultbase ) : <EOL> __slots__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:time>" ] <EOL> def __repr__ ( self ) : <EOL> return self . _repr ( "<STR_LIT>" ) <EOL> def __init__ ( self ) : <EOL> _resultbase . __init__ ( self ) <EOL> self . start = self . _attr ( ) <EOL> self . end = self . _attr ( ) <EOL> def parse ( self , tzstr ) : <EOL> res = self . _result ( ) <EOL> l = _timelex . split ( tzstr ) <EOL> try : <EOL> len_l = len ( l ) <EOL> i = <NUM_LIT:0> <EOL> while i < len_l : <EOL> j = i <EOL> while j < len_l and not [ x for x in l [ j ] <EOL> if x in "<STR_LIT>" ] : <EOL> j += <NUM_LIT:1> <EOL> if j != i : <EOL> if not res . stdabbr : <EOL> offattr = "<STR_LIT>" <EOL> res . stdabbr = "<STR_LIT>" . join ( l [ i : j ] ) <EOL> else : <EOL> offattr = "<STR_LIT>" <EOL> res . dstabbr = "<STR_LIT>" . join ( l [ i : j ] ) <EOL> i = j <EOL> if ( i < len_l and ( l [ i ] in ( '<STR_LIT:+>' , '<STR_LIT:->' ) or l [ i ] [ <NUM_LIT:0> ] in <EOL> "<STR_LIT>" ) ) : <EOL> if l [ i ] in ( '<STR_LIT:+>' , '<STR_LIT:->' ) : <EOL> signal = ( <NUM_LIT:1> , - <NUM_LIT:1> ) [ l [ i ] == '<STR_LIT:+>' ] <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> signal = - <NUM_LIT:1> <EOL> len_li = len ( l [ i ] ) <EOL> if len_li == <NUM_LIT:4> : <EOL> setattr ( res , offattr , ( int ( l [ i ] [ : <NUM_LIT:2> ] ) * <NUM_LIT> + <EOL> int ( l [ i ] [ <NUM_LIT:2> : ] ) * <NUM_LIT> ) * signal ) <EOL> elif i + <NUM_LIT:1> < len_l and l [ i + <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> setattr ( res , offattr , <EOL> ( int ( l [ i ] ) * <NUM_LIT> + int ( l [ i + <NUM_LIT:2> ] ) * <NUM_LIT> ) * signal ) <EOL> i += <NUM_LIT:2> <EOL> elif len_li <= <NUM_LIT:2> : <EOL> setattr ( res , offattr , <EOL> int ( l [ i ] [ : <NUM_LIT:2> ] ) * <NUM_LIT> * signal ) <EOL> else : <EOL> return None <EOL> i += <NUM_LIT:1> <EOL> if res . dstabbr : <EOL> break <EOL> else : <EOL> break <EOL> if i < len_l : <EOL> for j in range ( i , len_l ) : <EOL> if l [ j ] == '<STR_LIT:;>' : <EOL> l [ j ] = '<STR_LIT:U+002C>' <EOL> assert l [ i ] == '<STR_LIT:U+002C>' <EOL> i += <NUM_LIT:1> <EOL> if i >= len_l : <EOL> pass <EOL> elif ( <NUM_LIT:8> <= l . count ( '<STR_LIT:U+002C>' ) <= <NUM_LIT:9> and <EOL> not [ y for x in l [ i : ] if x != '<STR_LIT:U+002C>' <EOL> for y in x if y not in "<STR_LIT>" ] ) : <EOL> for x in ( res . start , res . end ) : <EOL> x . month = int ( l [ i ] ) <EOL> i += <NUM_LIT:2> <EOL> if l [ i ] == '<STR_LIT:->' : <EOL> value = int ( l [ i + <NUM_LIT:1> ] ) * - <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> value = int ( l [ i ] ) <EOL> i += <NUM_LIT:2> <EOL> if value : <EOL> x . week = value <EOL> x . weekday = ( int ( l [ i ] ) - <NUM_LIT:1> ) % <NUM_LIT:7> <EOL> else : <EOL> x . day = int ( l [ i ] ) <EOL> i += <NUM_LIT:2> <EOL> x . time = int ( l [ i ] ) <EOL> i += <NUM_LIT:2> <EOL> if i < len_l : <EOL> if l [ i ] in ( '<STR_LIT:->' , '<STR_LIT:+>' ) : <EOL> signal = ( - <NUM_LIT:1> , <NUM_LIT:1> ) [ l [ i ] == "<STR_LIT:+>" ] <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> signal = <NUM_LIT:1> <EOL> res . dstoffset = ( res . stdoffset + int ( l [ i ] ) ) * signal <EOL> elif ( l . count ( '<STR_LIT:U+002C>' ) == <NUM_LIT:2> and l [ i : ] . count ( '<STR_LIT:/>' ) <= <NUM_LIT:2> and <EOL> not [ y for x in l [ i : ] if x not in ( '<STR_LIT:U+002C>' , '<STR_LIT:/>' , '<STR_LIT>' , '<STR_LIT:M>' , <EOL> '<STR_LIT:.>' , '<STR_LIT:->' , '<STR_LIT::>' ) <EOL> for y in x if y not in "<STR_LIT>" ] ) : <EOL> for x in ( res . start , res . end ) : <EOL> if l [ i ] == '<STR_LIT>' : <EOL> i += <NUM_LIT:1> <EOL> x . jyday = int ( l [ i ] ) <EOL> elif l [ i ] == '<STR_LIT:M>' : <EOL> i += <NUM_LIT:1> <EOL> x . month = int ( l [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> assert l [ i ] in ( '<STR_LIT:->' , '<STR_LIT:.>' ) <EOL> i += <NUM_LIT:1> <EOL> x . week = int ( l [ i ] ) <EOL> if x . week == <NUM_LIT:5> : <EOL> x . week = - <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> assert l [ i ] in ( '<STR_LIT:->' , '<STR_LIT:.>' ) <EOL> i += <NUM_LIT:1> <EOL> x . weekday = ( int ( l [ i ] ) - <NUM_LIT:1> ) % <NUM_LIT:7> <EOL> else : <EOL> x . yday = int ( l [ i ] ) + <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> if i < len_l and l [ i ] == '<STR_LIT:/>' : <EOL> i += <NUM_LIT:1> <EOL> len_li = len ( l [ i ] ) <EOL> if len_li == <NUM_LIT:4> : <EOL> x . time = ( int ( l [ i ] [ : <NUM_LIT:2> ] ) * <NUM_LIT> + int ( l [ i ] [ <NUM_LIT:2> : ] ) * <NUM_LIT> ) <EOL> elif i + <NUM_LIT:1> < len_l and l [ i + <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> x . time = int ( l [ i ] ) * <NUM_LIT> + int ( l [ i + <NUM_LIT:2> ] ) * <NUM_LIT> <EOL> i += <NUM_LIT:2> <EOL> if i + <NUM_LIT:1> < len_l and l [ i + <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> i += <NUM_LIT:2> <EOL> x . time += int ( l [ i ] ) <EOL> elif len_li <= <NUM_LIT:2> : <EOL> x . time = ( int ( l [ i ] [ : <NUM_LIT:2> ] ) * <NUM_LIT> ) <EOL> else : <EOL> return None <EOL> i += <NUM_LIT:1> <EOL> assert i == len_l or l [ i ] == '<STR_LIT:U+002C>' <EOL> i += <NUM_LIT:1> <EOL> assert i >= len_l <EOL> except ( IndexError , ValueError , AssertionError ) : <EOL> return None <EOL> return res <EOL> DEFAULTTZPARSER = _tzparser ( ) <EOL> def _parsetz ( tzstr ) : <EOL> return DEFAULTTZPARSER . parse ( tzstr ) <EOL> def _parsems ( value ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:.>" not in value : <EOL> return int ( value ) , <NUM_LIT:0> <EOL> else : <EOL> i , f = value . split ( "<STR_LIT:.>" ) <EOL> return int ( i ) , int ( f . ljust ( <NUM_LIT:6> , "<STR_LIT:0>" ) [ : <NUM_LIT:6> ] ) </s>
