o ?c@sBdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl Z ddl m Z mZddlmZddlmZd d lmZd d lmZgd ZGd ddeZGdddeZGdddeZGdddeZGdddeZeZd!ddZGdddeZeZ ddZ!Gddde"Z#Gdd d e$Z%dS)"a This module offers a generic date/time string parser which is able to parse most known formats to represent a date and/or time. This module attempts to be forgiving with regards to unlikely input formats, returning a datetime object even for dates which are ambiguous. If an element of a date/time stamp is omitted, the following rules are applied: - If AM or PM is left unspecified, a 24-hour clock is assumed, however, an hour on a 12-hour clock (``0 <= hour <= 12``) *must* be specified if AM or PM is specified. - If a time zone is omitted, a timezone-naive datetime is returned. If any other elements are missing, they are taken from the :class:`datetime.datetime` object passed to the parameter ``default``. If this results in a day number exceeding the valid number of days per month, the value falls back to the end of the month. Additional resources about date/time string formats can be found below: - `A summary of the international standard date and time notation `_ - `W3C Date and Time Formats `_ - `Time Formats (Planetary Rings Node) `_ - `CPAN ParseDate module `_ - `Java SimpleDateFormat Class `_ )unicode_literalsN) monthrange)StringIO) integer_types text_type)Decimal)warn) relativedelta)tz)parse parserinfo ParserErrorc@sneZdZedZddZddZddZdd Z d d Z e d d Z e ddZ e ddZe ddZdS)_timelexz([.,])cCsjt|ttfr |}t|trt|}nt|dddur'tdj|j j d||_ g|_ g|_ d|_dS)Nreadz8Parser must be a string or character stream, not {itype})ZitypeF) isinstancebytes bytearraydecoderrgetattr TypeErrorformat __class____name__instream charstack tokenstackeof)selfrrr/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/dateutil/parser/_parser.py__init__>s   z_timelex.__init__cCs|jr |jdSd}d}d}|js|jr|jd}n|jd}|dkr0|jd}|dks&|s6d|_n|sS|}||rBd}n||rJd}n||rRd }nn|dkrud}||rc||7}n|d krn||7}d }n|j |n|dkr||r||7}nt|d ks|d krt |d kr||7}d}n_|j |n[|d krd}|d ks||r||7}nD||r|dd kr||7}d}n2|j |n.|dkr|d ks||r||7}n||r|dd kr||7}d }n|j |n|jr|dvr.|s| d dks|ddvr.|j |}|d}|ddD] }|r,|j |q!|dkrA| d dkrA|d d }|S)a This function breaks the time string into lexical units (tokens), which can be parsed by the parser. Lexical units are demarcated by changes in the character set, so any continuous string of letters is considered one unit, any continuous string of numbers is considered one unit. The main complication arises from the fact that dots ('.') can be used both as separators (e.g. "Sep.20.2009") or decimal points (e.g. "4:30:21.447"). As such, it is necessary to read the full context of any dot-separated strings before breaking it into tokens; as such, this function maintains a "token stack", for when the ambiguous context demands that multiple tokens be parsed at once. rFNTa0 .a.,r 0.)r(r*z.,)rpoprrrriswordisnumisspaceappendlencount_split_decimalsplitreplace)rZ seenletterstokenstatenextcharltokrrr get_tokenMs                 K    z_timelex.get_tokencCs|SNrrrrr __iter__sz_timelex.__iter__cCs|}|dur t|Sr<)r; StopIteration)rr6rrr __next__sz_timelex.__next__cCs|Sr<)r@r=rrr nextsz _timelex.nextcCs t||Sr<)list)clssrrr r4s z_timelex.splitcC|S)z5 Whether or not the next character is part of a word )isalpharCr8rrr r-z_timelex.iswordcCrE)z0 Whether the next character is part of a number )isdigitrGrrr r.rHz_timelex.isnumcCrE)z* Whether the next character is whitespace )r/rGrrr r/rHz_timelex.isspaceN)r __module__ __qualname__recompiler3r!r;r>r@rA classmethodr4r-r.r/rrrr r:s m   rc@s,eZdZddZddZddZddZd S) _resultbasecCs|jD]}t||dqdSr<) __slots__setattr)rattrrrr r!s z_resultbase.__init__cCsJg}|jD]}t||}|dur|d|t|fqd|d|fS)Nz%s=%s%s(%s), )rPrr0reprjoin)r classnamer9rRvaluerrr _reprs  z_resultbase._reprcstfddjDS)Nc3s|] }t|duVqdSr<)r).0rRr=rr sz&_resultbase.__len__..)sumrPr=rr=r __len__s z_resultbase.__len__cCs||jjSr<)rYrrr=rrr __repr__z_resultbase.__repr__N)rrJrKr!rYr]r^rrrr rOs  rOc@seZdZdZgdZgdZgdZgdZddgZgdZ d gZ iZ d$d d Z d dZ ddZddZddZddZddZddZddZddZd%dd Zd!d"Zd#S)&r a Class which handles what inputs are accepted. Subclass this to customize the language and acceptable values for each parameter. :param dayfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (``True``) or month (``False``). If ``yearfirst`` is set to ``True``, this distinguishes between YDM and YMD. Default is ``False``. :param yearfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the year. If ``True``, the first number is taken to be the year, otherwise the last number is taken to be the year. Default is ``False``. )r&r'r);-/'atonandadmtofstndrdth))MonZMonday)TueZTuesday)WedZ Wednesday)ThuZThursday)FriZFriday)SatZSaturday)SunZSunday) )JanJanuary)FebFebruary)MarZMarch)AprZApril)Mayr|)JunZJune)JulZJuly)AugZAugust)SepZSeptZ September)OctZOctober)NovZNovember)DecZDecember))hhourhours)rhminuteminutes)rDsecondseconds)amr$)Zpmp)UTCGMTZzrjFcCs||j|_||j|_||j|_||j|_||j |_ ||j |_ ||j |_||_||_tj|_|jdd|_dS)Nd)_convertJUMP_jumpWEEKDAYS _weekdaysMONTHS_monthsHMS_hmsAMPM_ampmUTCZONE_utczonePERTAIN_pertaindayfirst yearfirsttime localtimetm_year_year_century)rrrrrr r!&s zparserinfo.__init__cCsHi}t|D]\}}t|tr|D]}|||<qq|||<q|Sr<) enumeratertuplelower)rlstdctivrrr r5s zparserinfo._convertcC||jvSr<)rrrnamerrr jump?r_zparserinfo.jumpcC&z|j|WStyYdSwr<)rrKeyErrorrrrr weekdayBs  zparserinfo.weekdaycCs*z |j|dWStyYdSwNr")rrrrrrr monthIs  zparserinfo.monthcCrr<)rrrrrrr hmsP  zparserinfo.hmscCrr<)rrrrrrr ampmVrzparserinfo.ampmcCrr<)rrrrrr pertain\r_zparserinfo.pertaincCrr<)rrrrrr utczone_r_zparserinfo.utczonecCs||jvrdS|j|S)Nr)rTZOFFSETgetrrrr tzoffsetbs  zparserinfo.tzoffsetcCsV|dksJ|dkr)|s)||j7}||jdkr|d8}|S||jdkr)|d7}|S)zt Converts two-digit years to year within [-50, 49] range of self._year (current local time) rr2)rr)ryearcentury_specifiedrrr convertyearhs   zparserinfo.convertyearcCsv|jdur||j|j|_|jdkr|jr |jdks |jdkr(d|_d|_dS|jdkr9|jr9||jr9d|_dS)NrrrrT)rrrrtznamer)rresrrr validate|s zparserinfo.validateN)FF)F)rrJrK__doc__rrrrrrrrr!rrrrrrrrrrrrrrr r s0     r csfeZdZfddZeddZeddZeddZd d Zdfd d Z ddZ ddZ Z S)_ymdcs4t|j|j|i|d|_d|_d|_d|_dS)NF)superrr!rdstridxmstridxystridx)rargskwargsrrr r!s  z _ymd.__init__cC |jduSr<)rr=rrr has_year z _ymd.has_yearcCrr<)rr=rrr has_monthrz_ymd.has_monthcCrr<)rr=rrr has_dayrz _ymd.has_daycCs|jrdS|jsd|kodkSS|js-||j}d|ko*td|dkSS||j}||j}d|koEt||dkSS)NFr"i)rrrrrr)rrXrrrrr could_be_days "  "z_ymd.could_be_dayNcst|dr|rt|dkrd|_|dvrt|d}n|dkr.d|_|dvr,t|d}t|j|t||dkrM|j rDtdt|d |_ dS|d kra|j rXtd t|d |_ dS|dkru|j rltd t|d |_dSdS) Nr]r T)NYrrMzMonth is already setr"DzDay is already setzYear is already set)hasattrrIr1r ValueErrorrrr0intrrrrrr)rvallabelrrr r0s4 z _ymd.appendcstdkr>tdkr>fddtdD}fdddD}t|t|kr/dks2JJ|d}|d}||<ttksHJfd d D}|d |d |d fS)z Try to resolve the identities of year/month/day elements using ystridx, mstridx, and dstridx, if enough of these are specified. r csg|] }|vr|qSr)valuesrZxstridsrr sz._ymd._resolve_from_stridxs..csg|]}|vr|qSrrrrrr rs)yrhdr"rcsi|] }||qSrr)rZkeyrrrr sz._ymd._resolve_from_stridxs..rrhr)r1ranger)rrmissingrroutrrr _resolve_from_stridxss$z_ymd._resolve_from_stridxsc Cst|}d\}}}d|jfd|jfd|jff}dd|D}t|t|kr,dks9nt|dkr>t|d kr>||S|j}|dkrItd |d ksU|durz|d krz|durd||}||d } n|d} |d ksp|dury| d krw| }n| }n|d kr|dd kr|\}}n|d d kr|\}}n|r|d d kr|\}}n|\}}n|dkrE|dkr|d d kr|\}}}n|\}}}n|d kr|dd ks|r|d d kr|\}}}nl|\}}}nf|d kr|d d kr|\}}}nV|\}}}nP|dd ks|jdks|r)|d d kr)|d d kr)|r#|d d kr#|\}}}n"|\}}}n|dd ks:|r@|d d kr@|\}}}n|\}}}|||fS)N)NNNrrhrcSsi|] \}}|dur||qSr<r)rZrrrrr rsz$_ymd.resolve_ymd..rrr zMore than three YMD valuesr"r )r1rrrrr) rrrZlen_ymdrrdayrrotherrrr resolve_ymds~                       "   z_ymd.resolve_ymdr<) rrJrKr!propertyrrrrr0rr __classcell__rrrr rs    rc@seZdZd)ddZ  d*ddZGdddeZ  d+d d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(ZdS),parserNcCs|pt|_dSr<)r info)rrrrr r!9szparser.__init__Fc Ks|durtjjddddd}|j|fi|\}}|dur$td|t|dkr/td|z|||}WntyV} zt tt | d|| WYd} ~ nd} ~ ww|s`| |||}| ddrj||fS|S) aW Parse the date/time string into a :class:`datetime.datetime` object. :param timestr: Any date/time string using the supported formats. :param default: The default datetime object, if this is a datetime object and not ``None``, elements specified in ``timestr`` replace elements in the default object. :param ignoretz: If set ``True``, time zones in parsed strings are ignored and a naive :class:`datetime.datetime` object is returned. :param tzinfos: Additional time zone names / aliases which may be present in the string. This argument maps time zone names (and optionally offsets from those time zones) to time zones. This parameter can be a dictionary with timezone aliases mapping time zone names to time zones or a function taking two parameters (``tzname`` and ``tzoffset``) and returning a time zone. The timezones to which the names are mapped can be an integer offset from UTC in seconds or a :class:`tzinfo` object. .. doctest:: :options: +NORMALIZE_WHITESPACE >>> from dateutil.parser import parse >>> from dateutil.tz import gettz >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")} >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos) datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200)) >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos) datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago')) This parameter is ignored if ``ignoretz`` is set. :param \*\*kwargs: Keyword arguments as passed to ``_parse()``. :return: Returns a :class:`datetime.datetime` object or, if the ``fuzzy_with_tokens`` option is ``True``, returns a tuple, the first element being a :class:`datetime.datetime` object, the second a tuple containing the fuzzy tokens. :raises ParserError: Raised for invalid or unknown string format, if the provided :class:`tzinfo` is not in a valid format, or if an invalid date would be created. :raises TypeError: Raised for non-string or character stream input. :raises OverflowError: Raised if the parsed date exceeds the largest valid C integer on your system. Nr)rrr microsecondzUnknown string format: %sz"String does not contain a date: %sz: %sfuzzy_with_tokensF) datetimenowr5_parserr1 _build_naiversix raise_fromstr_build_tzawarer) rtimestrdefaultZignoretztzinfosrrskipped_tokensreterrr r <s(@   & z parser.parsec@eZdZgdZdS)zparser._result) rrrrrrrrrrrany_unused_tokensNrrJrKrPrrrr _result r c Csh|rd}|j}|dur|j}|dur|j}|}t|}g} t} t|} d} za| | krt|| } zt| }Wn t yEd}Ynw|durV| || || ||} n| || durk| || }||_ n| || dur| || }| |d| d| kr || ddvr|| d}| || d| d| kr|| d|kr| || d | d7} | d7} n| d | kr || d|| dkrd kr nn||| dr || d rt|| d }t||}| |d n | d 7} n^||| durB||| }||j|j|}|r8||j||_||_n4|r@| | n*||j|j|j|| r|| |_||j|_| d| kr|| dd vrd || dd k|| d<d|_||jrd|_n|jdurX|| d vrXd|| d k}t|| d}|d krt|| ddd}t|| ddd}n=| d| kr|| ddkrt|| d}t|| d}| d7} n|dkrt|| ddd}d}nt |||d|d|_| d| krS||| drS|| ddkrS|| ddkrSdt|| d krS||j|jd|| d rS|| d |_| d 7} | d7} n||| sg|sgt || | | d7} | | ks0| ||\}}}| j|_||_||_ ||_Wn t t fyYdSw|!|sdS|r|"|| }|t#|fS|dfS)a Private method which performs the heavy lifting of parsing, called from ``parse()``, which passes on its ``kwargs`` to this function. :param timestr: The string to parse. :param dayfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (``True``) or month (``False``). If ``yearfirst`` is set to ``True``, this distinguishes between YDM and YMD. If set to ``None``, this value is retrieved from the current :class:`parserinfo` object (which itself defaults to ``False``). :param yearfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the year. If ``True``, the first number is taken to be the year, otherwise the last number is taken to be the year. If this is set to ``None``, the value is retrieved from the current :class:`parserinfo` object (which itself defaults to ``False``). :param fuzzy: Whether to allow fuzzy parsing, allowing for string like "Today is January 1, 2047 at 8:21:00AM". :param fuzzy_with_tokens: If ``True``, ``fuzzy`` is automatically set to True, and the parser will return a tuple where the first element is the parsed :class:`datetime.datetime` datetimestamp and the second element is a tuple containing the portions of the string which were ignored: .. doctest:: >>> from dateutil.parser import parse >>> parse("Today is January 1, 2047 at 8:21:00AM", fuzzy_with_tokens=True) (datetime.datetime(2047, 1, 1, 8, 21), (u'Today is ', u' ', u'at ')) TNrrr")rarbr rr&r+rarr+r":<())NN)$rrrr rr4rr1floatr_parse_numeric_tokenrrr0rrIrrrr _ampm_validr _adjust_ampm_could_be_tznamerrrrrrrr IndexErrorr_recombine_skippedr)rrrrfuzzyrrrr9 skipped_idxsymdlen_lr value_reprrXsepr val_is_ampmsignallen_liZ hour_offsetZ min_offsetrrrrrr rs)        :                z parser._parsec Csh||}z||}Wnty%} zttd| WYd} ~ nd} ~ wwt|} t|} t|dkrr| dvrr|jdurr|d| ksV||ddkrr|||ddurr||} t| dd|_| dkrpt| dd|_ |S| dks| dkr|| d dkr||} |sd ||vr| | dd| | dd| | dd|St| dd|_t| dd|_ | | dd\|_ |_|S| d vr||} | | ddd | | dd| | dd | d krt| d d |_t| d d|_ | dkrt| dd|_ |S|j|||dddurF|j|||dd} ||||| \}}|durD|||||S|d| kr||ddkrt||_|||d}||\|_ |_ |d| kr||ddkr| ||d\|_ |_|d7}|d7}|S|d| kr'||ddvr'||d}| ||d| kr!|||ds!||dr| ||dn|||d}|dur| |dnt|d| kr||d|kr|||d}|dur| |dn | ||d|d7}|d7}|d7}|S|d| ks8|||drm|d| krb|||ddurbt|}|||||d|_|d7}n| ||d7}|S|||ddurd|krdkrnnt|}|||||d|_|d7}|S||r| ||S|st|S)NzUnknown numeric tokenr)r r r"rr r r')rrr' rT) allow_jump)rarbr'rr) _to_decimal Exceptionrrrr1rrrrfindr0_parsemsrr _find_hms_idx _parse_hms _assign_hms_parse_min_secrrIrrrr)rtokensidxrrrrr!rXrr%r rDhms_idxrr"rrrr rks k"b[   M D  7  "   "&  4 zparser._parse_numeric_tokencCst|}|d|kr|||ddur|d}|S|r<|d|kr<||ddkr<|||ddur<|d}|S|dkrQ|||ddurQ|d}|Sd|kr]|dkrxnn||ddkrx|||ddurx|d}|Sd}|S)Nr"r r&r)r1r)rr5r4rr*r r6rrr r0s&"  ,zparser._find_hms_idxcCs~||}|dkrt||_|drtd|d|_dSdS|dkr.||\|_|_dS|dkr=||\|_|_dSdS)Nrr"rr )r,rrrr3rr/r)rrr!rrXrrr r2s  zparser._assign_hmscCsB|duo |duo |duo t|dko tdd|Dp ||jjvS)Nrcss|]}|tjvVqdSr<)stringascii_uppercaserrrr r[%sz*parser._could_be_tzname..)r1allrr)rrrrr6rrr r s  zparser._could_be_tznamecCs^d}|r |dur d}|dur|rd}|Stdd|kr"dks-n|r)d}|Std|S)z For fuzzy parsing, 'a' or 'am' (both valid English words) may erroneously trigger the AM/PM flag. Deal with that here. TNFz%No hour specified with AM or PM flag.rrz)Invalid hour specified for 12-hour clock.)r)rrrrr#rrr r(s  zparser._ampm_validcCs4|dkr|dkr|d7}|S|dkr|dkrd}|S)Nrr"rr)rrrrrr rDs zparser._adjust_ampmcCs,t|}d}|d}|rtd|}||fS)Nr"r)r)rrXrrZ sec_remainderrrr r3Ks  zparser._parse_min_seccCsX|dur d}|}||fS||kr|||}|}||fS|||d}|}||fSr)r)rr5r4rr6rZnew_idxrrr r1Ws zparser._parse_hmscCsBd|vr t|dfS|d\}}t|t|ddddfS)z9Parse a I[.F] seconds value into (seconds, microseconds).r'rr&r%N)rr4ljust)rrXrfrrr r/ms  zparser._parsemsc Cs^zt|}|s tdW|Sty.}zd|}tt||WYd}~dSd}~ww)Nz*Converted decimal value is infinite or NaNzCould not convert %s to decimal)r is_finiterr-rr)rrZ decimal_valuermsgrrr r,uszparser._to_decimalcCstt|r |||}n||}t|tjs|dur|}|St|tr)t|}|St|tr6t ||}|St d)Nz9Offset must be tzinfo subclass, tz string, or int offset.) callablerrrtzinforr tzstrrrr)rrrrZtzdatar?rrr _build_tzinfos    zparser._build_tzinfocCst|s |r#|j|vr#|||j|j}|j|d}|||j}|S|jrR|jtjvrR|jtd}|||j}||jkrP|j|j j vrP|jtj d}|S|jdkr`|jtj d}|S|jrq|jt|j|jd}|S|js{|js{|}|S|jrt j dj|jdtd|}|S)N)r?rztzname {tzname} identified but not understood. Pass `tzinfos` argument in order to correctly return a timezone-aware datetime. In a future version, this will raise an exception.)r)category)r>rrArr5_assign_tznamerr ZtzlocalrrrwarningsrrUnknownTimezoneWarning)rnaiverrr?Zawarerrr rs< "    zparser._build_tzawarec Csi}dD]}t||}|dur|||<qd|vrK|jdur |jn|j}|jdur+|jn|j}|jdur6|jn|j}|t||dkrKt||d|d<|jdi|} |jdurd|jsd| tj|jd} | S)N)rrrrrrrrr")rr)rrrrrr5rr ) rrrreplrRrXZcyearZcmonthZcdayrFrrr rs  zparser._build_naivecCs.||krtj|dd}||kr|S|S)Nr")fold)rr Zenfold)rdtrZnew_dtrrr rCs  zparser._assign_tznamecCs^g}tt|D]$\}}|dkr%|d||dkr%|d|||d<q|||q|S)z >>> tokens = ["foo", " ", "bar", " ", "19June2000", "baz"] >>> skipped_idxs = [0, 1, 2, 5] >>> _recombine_skipped(tokens, skipped_idxs) ["foo bar", "baz"] rr"r+)rsortedr0)rr4rrrr5rrr rs zparser._recombine_skippedr<)NFN)NNFF)rrJrKr!r rOr rrr0r2rrrr3r1r/r,rArrrCrrrrr r8s4  Y R" ( rcKs,|r t|j|fi|Stj|fi|S)a Parse a string in one of the supported formats, using the ``parserinfo`` parameters. :param timestr: A string containing a date/time stamp. :param parserinfo: A :class:`parserinfo` object containing parameters for the parser. If ``None``, the default arguments to the :class:`parserinfo` constructor are used. The ``**kwargs`` parameter takes the following keyword arguments: :param default: The default datetime object, if this is a datetime object and not ``None``, elements specified in ``timestr`` replace elements in the default object. :param ignoretz: If set ``True``, time zones in parsed strings are ignored and a naive :class:`datetime` object is returned. :param tzinfos: Additional time zone names / aliases which may be present in the string. This argument maps time zone names (and optionally offsets from those time zones) to time zones. This parameter can be a dictionary with timezone aliases mapping time zone names to time zones or a function taking two parameters (``tzname`` and ``tzoffset``) and returning a time zone. The timezones to which the names are mapped can be an integer offset from UTC in seconds or a :class:`tzinfo` object. .. doctest:: :options: +NORMALIZE_WHITESPACE >>> from dateutil.parser import parse >>> from dateutil.tz import gettz >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")} >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos) datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200)) >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos) datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago')) This parameter is ignored if ``ignoretz`` is set. :param dayfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (``True``) or month (``False``). If ``yearfirst`` is set to ``True``, this distinguishes between YDM and YMD. If set to ``None``, this value is retrieved from the current :class:`parserinfo` object (which itself defaults to ``False``). :param yearfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the year. If ``True``, the first number is taken to be the year, otherwise the last number is taken to be the year. If this is set to ``None``, the value is retrieved from the current :class:`parserinfo` object (which itself defaults to ``False``). :param fuzzy: Whether to allow fuzzy parsing, allowing for string like "Today is January 1, 2047 at 8:21:00AM". :param fuzzy_with_tokens: If ``True``, ``fuzzy`` is automatically set to True, and the parser will return a tuple where the first element is the parsed :class:`datetime.datetime` datetimestamp and the second element is a tuple containing the portions of the string which were ignored: .. doctest:: >>> from dateutil.parser import parse >>> parse("Today is January 1, 2047 at 8:21:00AM", fuzzy_with_tokens=True) (datetime.datetime(2047, 1, 1, 8, 21), (u'Today is ', u' ', u'at ')) :return: Returns a :class:`datetime.datetime` object or, if the ``fuzzy_with_tokens`` option is ``True``, returns a tuple, the first element being a :class:`datetime.datetime` object, the second a tuple containing the fuzzy tokens. :raises ParserError: Raised for invalid or unknown string formats, if the provided :class:`tzinfo` is not in a valid format, or if an invalid date would be created. :raises OverflowError: Raised if the parsed date exceeds the largest valid C integer on your system. )rr DEFAULTPARSER)rr rrrr r s_r c@s$eZdZGdddeZddZdS) _tzparserc@s4eZdZgdZGdddeZddZddZdS) z_tzparser._result)stdabbr stdoffsetdstabbr dstoffsetstartendc@r)z_tzparser._result._attr)rweekrydayjydayrrNr rrrr _attrbr rVcCs |dS)N)rYr=rrr r^f z_tzparser._result.__repr__cCs"t|||_||_dSr<)rOr!rVrQrRr=rrr r!is  z_tzparser._result.__init__N)rrJrKrPrOrVr^r!rrrr r ]s  r c s|}ddtd|Dt}zt}d}||kr$|}||kr?dd|Ds?|d7}||kr?dd|Dr.||kr|jsTd}d|||_n d }d|||_t|D]}| |qd|}||kr|d vs|dd vr|d vrd |d k} | ||d7}nd} t|} | dkrt ||t |dddt |ddd| nK|d|kr|ddkrt ||t |dt |dd| | ||d7}n| dkr t ||t |ddd| nWdS| ||d7}|jrnnn||ks||krJt||D]}|dkr;d|<q.|dksFJ|d7}||krQnZd dkr`dkr)nndd|dDs)|j |jfD]o} t || _| ||d7}|dkrt |dd} | ||d7}nt |} | ||d7}| r| | _t |dd| _nt || _| ||d7}t || _| ||d7}qt||kr|dvrd|d k} | ||d7}nd} | ||jt || |_td|ddd d!d"tjn ddkr|d d#dkrd$d|dDs|j |jfD]S} |d%krj| ||d7}t || _nr|d&kr| ||d7}t || _| ||d7}|d'vsJ| ||d7}t || _| jd(krd| _| ||d7}|d'vsJ| ||d7}t |dd| _n t |d| _| ||d7}||kr|d#kr| ||d7}t|} | dkrt |dddt |ddd| _nh|d|krp|ddkrpt |dt |dd| _| ||d7}|d|kro|ddkro| ||d7}| jt |7_n| dkrt |ddd| _nWdS| ||d7}||ks|dksJ|d7}qO||ksJWntttfyYdSwtt||} fd)d*| D ddh |_!|S)+NcSsg|]}|r|qSrrrrrr rpz#_tzparser.parse..z([,:.]|[a-zA-Z]+|[0-9]+)rcSsg|]}|dvr|qS)z0123456789:,-+rrrrr rzs r"rNrWrPr  0123456789)r"r+rr+r r rrrr`r)r' cSs*g|]}|dkr|D]}|dvr |q qS)r)z 0123456789+-rrZrrrrr rs  ra)rarrzParsed time zone "%s"z5is in a non-standard dateutil-specific format, which z3is now deprecated; support for parsing this format z6will be removed in future versions. It is recommended z2that you switch to a standard format like the GNU zTZ variable format.rbcSs*g|]}|dvr|D]}|dvr |q qS))r)rbJrr'rarrZrr\rrr rs  r^r)rar'rcsh|]}|qSrr)rZnr9rr *rYz"_tzparser.parse..)"r rLr4rBr1rMrVrOrr0rQrr2rQrRrrSrrrrNrPrr ZDeprecatedTzFormatWarningrUrTrrAssertionErrorset differenceissubsetr)rr@rZ used_idxsr rjZoffattriir$r%rrXZ unused_idxsrr`r r nsV              5 "            (            &       z_tzparser.parseN)rrJrKrOr r rrrr rL[s rLcCs t|Sr<)DEFAULTTZPARSERr )r@rrr _parsetz1rXrics(eZdZdZfddZddZZS)rzException subclass used for any failure to parse a datetime string. This is a subclass of :py:exc:`ValueError`, and should be raised any time earlier versions of ``dateutil`` would have raised ``ValueError``. .. versionadded:: 2.8.1 c s@z |jd|jddWSttfytt|YSw)Nrr")rrrrr__str__r=rrr rj=s zParserError.__str__cCs&ddd|jD}d|jj|fS)NrTcss|]}d|VqdS)z'%s'Nr)rZargrrr r[Dsz'ParserError.__repr__..rS)rVrrr)rrrrr r^CszParserError.__repr__)rrJrKrrjr^rrrrr r5s rc@seZdZdZdS)rEzhRaised when the parser finds a timezone it cannot parse into a tzinfo. .. versionadded:: 2.7.0 N)rrJrKrrrrr rEHsrEr<)&r __future__rrrLr7rrDcalendarriorrrrdecimalrrrWr r __all__objectrrOr rBrrrKr rLrhrirrRuntimeWarningrErrrr sJ       "/@ eT