%L i~dZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl Z ddl m Z mZddlmZddlmZd d lmZd d lmZgd ZGd deZGddeZGddeZGddeZGddeZeZddZGddeZeZ dZ!Gdde"Z#Gdde$Z%y) 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 ParserErrorceZdZejdZdZdZdZdZ dZ e dZ e dZ e d Ze d Zy ) _timelexz([.,])c8t|ttfr|j}t|tr t |}ns h 2 3(H h *)H Xvt , 4&&,f83E3E3N3Nf&OQ Q! c|jr|jjdSd}d}d}|js'|jr|jjd}nA|jj d}|dk(r!|jj d}|dk(r!|s d|_n|sC|}|j |rd}n|j|rd}nw|j|rd }npnn|dk(rEd}|j |r||z }nA|d k(r ||z }d }n3|jj|n$|dk(rS|j|r||z }n|d k(s|d k(rt|d k\r||z }d}n|jj|n|d k(r[d}|d k(s|j |r||z }n|j|r|dd k(r||z }d}nz|jj|nl|dk(rY|d k(s|j|r||z }n=|j |r|dd k(r||z }d }n|jj|n|js'|dvre|s|jd dkDs|ddvrH|jj|}|d}|ddD] }|s|jj|"|dk(r&|jd dk(r|jd 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.,)r popr!rrriswordisnumisspaceappendlencount_split_decimalsplitreplace)r" seenletterstokenstatenextcharltoks r# get_tokenz_timelex.get_tokenMs ????&&q) ) (( ~~>>--a0==--a0&(#}}11!4H&(!;;x(EZZ)E\\(+E## ;;x(X%E_X%E ENN))(3#::h'X%E_SSZ1_X%E ENN))(3$# s?dkk(&;X%EZZ)eBi3.>X%E ENN))(3$s?djj&:X%E[[*uRyC/?X%E ENN))(3S((V \ !{ekk#6F6J',RyD'8##))%0AaDEu 0OO**3/ 0 D=U[[-2MM#s+E r%c|SNr"s r#__iter__z_timelex.__iter__s r%c6|j}|t|SrC)rA StopIteration)r"r<s r#__next__z_timelex.__next__s  =  r%c"|jSrC)rIrEs r#nextz _timelex.nexts}}r%c$t||SrC)list)clsss r#r9z_timelex.splitsCF|r%c"|jS)z5 Whether or not the next character is part of a word )isalpharNr>s r#r2z_timelex.isword!!r%c"|jS)z0 Whether the next character is part of a number )isdigitrRs r#r3z_timelex.isnumrSr%c"|jS)z* Whether the next character is whitespace )r4rRs r#r4z_timelex.isspacerSr%N)r __module__ __qualname__recompiler8r$rArFrIrK classmethodr9r2r3r4rDr%r#rr:s}RZZ)N kZ""""""r%rc$eZdZdZdZdZdZy) _resultbasec@|jD]}t||dyrC) __slots__setattr)r"attrs r#r$z_resultbase.__init__s!NN &D D$ % &r%cg}|jD]0}t||}||j|dt|2|ddj |dS)N=(, ))r_rr5reprjoin)r" classnamer?ravalues r#_reprz_resultbase._reprsV NN 8DD$'E D$u+67 8%diil33r%c@tfdjDS)Nc3:K|]}t|duywrC)r).0rar"s r# z&_resultbase.__len__..s%0D$'t30s)sumr_rEs`r#__len__z_resultbase.__len__s!0 $00 1r%cL|j|jjSrC)rkrrrEs r#__repr__z_resultbase.__repr__szz$..1122r%N)rrWrXr$rkrqrsrDr%r#r]r]s&413r%r]ceZdZdZgdZgdZgdZgdZddgZgdZ d gZ iZ dd Z d Z d Zd ZdZdZdZdZdZdZddZdZy)ra 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))MonMonday)TueTuesday)Wed Wednesday)ThuThursday)FriFriday)SatSaturday)SunSunday) )JanJanuary)FebFebruary)MarMarch)AprApril)Mayr)JunJune)JulJuly)AugAugust)SepSept September)OctOctober)NovNovember)DecDecember))hhourhours)r}minuteminutes)rOsecondseconds)amr))pmp)UTCGMTZzrcT|j|j|_|j|j|_|j|j |_|j|j|_|j|j|_ |j|j|_ |j|j|_||_||_t#j$j&|_|j(dzdz|_y)Nd)_convertJUMP_jumpWEEKDAYS _weekdaysMONTHS_monthsHMS_hmsAMPM_ampmUTCZONE_utczonePERTAIN_pertaindayfirst yearfirsttime localtimetm_year_year_century)r"rrs r#r$zparserinfo.__init__&s]]499- t}}5}}T[[1 MM$((+ ]]499-  dll3  dll3   "^^%--  c)C/ r%ci}t|D]C\}}t|tr|D]}|||j<1|||j<E|SrC) enumeratertuplelower)r"lstdctivs r#rzparserinfo._convert5s^cN #DAq!U#'A%&C N'"#AGGI  #  r%c:|j|jvSrC)rrr"names r#jumpzparserinfo.jump?szz|tzz))r%c\ |j|jS#t$rYywxYwrC)rrKeyErrorrs r#weekdayzparserinfo.weekdayBs1 >>$**,/ /     ++cb |j|jdzS#t$rYywxYwNr')rrrrs r#monthzparserinfo.monthIs6 << -1 1   s " ..c\ |j|jS#t$rYywxYwrC)rrrrs r#hmszparserinfo.hmsPs. 99TZZ\* *  rc\ |j|jS#t$rYywxYwrC)rrrrs r#ampmzparserinfo.ampmVs. ::djjl+ +  rc:|j|jvSrC)rrrs r#pertainzparserinfo.pertain\zz|t}},,r%c:|j|jvSrC)rrrs r#utczonezparserinfo.utczone_rr%cV||jvry|jj|S)Nr)rTZOFFSETgetrs r#tzoffsetzparserinfo.tzoffsetbs& 4== }}  &&r%c|dk\sJ|dkrA|s?||jz }||jdzk\r|dz}|S||jdz kr|dz }|S)zt Converts two-digit years to year within [-50, 49] range of self._year (current local time) rr2)rr)r"yearcentury_specifieds r# convertyearzparserinfo.convertyearhshqyy #:/ DMM !DtzzB&   R'  r%c||j+|j|j|j|_|jdk(r |jr|jdk(s|jdk(rd|_d|_y|jdk7r.|jr"|j |jrd|_y)NrrrrT)rrrrtznamer)r"ress r#validatezparserinfo.validate|s 88 ''#2G2GHCH \\Q szzjjC3::#4CJCL\\Q 3::$,,szz2JCLr%N)FF)F)rrWrX__doc__rrrrrrrrr$rrrrrrrrrrrrDr%r#rrs$ $D#H #F 'C   D&GfGH 0*  --' ( r%rcleZdZfdZedZedZedZdZd fd Z dZ dZ xZ S) _ymdcpt|j| |i|d|_d|_d|_d|_y)NF)superrr$rdstridxmstridxystridx)r"argskwargsrs r#r$z _ymd.__init__s8 dnnd,d=f=!&   r%c|jduSrC)rrEs r#has_yearz _ymd.has_year||4''r%c|jduSrC)rrEs r# has_monthz_ymd.has_monthrr%c|jduSrC)rrEs r#has_dayz _ymd.has_dayrr%c:|jry|jsd|cxkxrdkScS|js,||j}d|cxkxrt d|dkScS||j}||j }d|cxkxrt ||dkScS)NFr'i)r rrrrr)r"rjrrs r# could_be_dayz_ymd.could_be_days <<## ## #&E;D%!8!;; ;; ;&E %D;D%!8!;; ;; ;r%c*t|dr7|jrDt|dkDr6d|_|dvr t |d}n|dkDrd|_|dvr t |d}t |j |t||dk(r+|jr t dt|d z |_ y|d k(r+|jr t d t|d z |_ y|dk(r+|jr t d t|d z |_yy) Nrqr T)NYrrMzMonth is already setr'DzDay is already setzYear is already set)hasattrrUr6r ValueErrorrrr5intrrr rrr)r"vallabelrs r#r5z _ymd.appends 3 "{{}SA)-& +$U++ 3Y%)D "K' ''E dnnd*3s84 C<~~ !788t9q=DL c\|| !566t9q=DL c\}} !677t9q=DLr%ct|dk(r~t|dk(rptdDcgc]}||jvs|}}dDcgc] }||vs| }}t|t|cxk(rdk(sJJ|d}|d}|||<t|t|k(sJ|Dcic] }|||| }}|jd|jd|jdfScc}wcc}wcc}w) z Try to resolve the identities of year/month/day elements using ystridx, mstridx, and dstridx, if enough of these are specified. r )yr}dr'rrr}r)r6rangevaluesr)r"stridsxmissingkeyrouts r#_resolve_from_stridxsz_ymd._resolve_from_stridxss t9>c&kQ."'(GQav}}.FqGGG-A&1ACAw<3s80q0 00 00a&C!*CF3K4yCK'''178#sD%%88 cggclCGGCL99HA9sC.C. C3C3*C8ct|}d\}}}d|jfd|jfd|jff}|D cic] \}} |  ||  }}} t|t|cxk(rdkDsnt|dk(rt|dk(r|j |S|j} |dkDr t d|d k(s| -|dk(r(| || }|| d z } n|d} |d kDs| | d kDr| }n| }n|dk(r2|dd kDr|\}}n|d d kDr|\}}n|r|d d kr|\}}n|\}}n|dk(r| dk(r|d d kDr|\}}}n|\}}}n| d k(r |dd kDs |r|dd kr|\}}}n|\}}}n{| dk(r|d d kDr|\}}}ng|\}}}n`|dd kDs!|jdk(s|r(|d d kr |dd kr|r|dd kr|\}}}n&|\}}}n|dd kDs |r|d d kr|\}}}n|\}}}|||fScc} }w) N)NNNrr}rrrr zMore than three YMD valuesr'r  )r6rrrr!r) r"rrlen_ymdrrdayrrrrothers r# resolve_ymdz_ymd.resolve_ymdsd)-eS % % %',2ExsCS_#s(EE IV (q (TaCK1$4--f5 5,, Q;9: : \g1gl"W Wq[)Q{go2: DC \Aw|" ea2" td1gm! U" s \!|7R<'+$E4'+$E3A7R>> 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) datetimenowr:_parserr6 _build_naiversix raise_fromstr_build_tzawarer) r"timestrdefaultignoretztzinfosrrskipped_tokensretes r#r z parser.parse<s@ ?''++-551Q=>A6OG*dkk't!|| d z}t#|j%|}| j|d n | d z } n|j'|| }|j'|| }|j)|j*|j&|}|r*|j-|j*||_||_n^|r[| j| nH|j/|j*|j0|j2|| r~|| |_|j3|j0|_| dz| kr|| dzd vrd || dzd k(|| dz<d|_|j5|j0rd|_n|j*V|| d vrNd|| d k(}t|| dz}|d k(r)t!|| dzdd}t!|| dzdd}nb| dz| kr3|| dzdk(r(t!|| dz}t!|| dz}| dz } n'|dkrt!|| dzdd}d}n t|||dz|dzzz|_| dz| kr|j7|| dzrj|| dzdk(r_|| dzdk(rTdt|| d zkr@|j/|j*|j0d|| d zr|| d z|_| d z } | dz } n2|j7|| s |s t|| j| | dz } | | kr}| j9||\}}}| j:|_||_||_ ||_|jC|sy|r|jE|| }|tG|fS|dfS#t$rd}YwxYw#t@tf$rYywxYw)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')rvrwr rr+r+rvrIr0r':<rdrf)NN)$r.rrrErr9rr6floatr_parse_numeric_tokenrrr5rrUrr8rr _ampm_validr _adjust_ampm_could_be_tznamerrrrr'rrr% IndexErrorr_recombine_skippedr)r"r:rrfuzzyr1r.rr? skipped_idxsymdlen_lr value_reprrjsepr val_is_ampmsignallen_li hour_offset min_offsetrr%r>s r#r4z parser._parsesR Eyy  }}H  Illn NN7 # fA H e)qT !!*-E$11!Qc3NA\\!A$'3 LL1.E"'CKZZ!%1 JJqt,EJJuc*1uu}QU8z1"#AE(CJJqQx0 1uu}1q5S # 1QU8 4 !QFA!eem!a%Aa!eH0K0K"ll1QU84 !Qx//1(+Aa!eH '*4+;+;E+B'C # 4 5!%FAYYqt_0 IIadOE"&"2"2388SXXu"MK"#'#4#4SXXu#E#($++A.**388SZZqQRtT!"1CJ#'==#!a%'+ << 3*.CJXX)adj.@$QqTS[1F 1q5]F{&)!AE(2A,&7 %(1q5!"%6 Q1QU8s?&)!AE(m %(1q5] Q1&)!AE(2A,&7 %& (11#)[4-?*r/-Q#RCLA  IIaAh/Aa!eHOa!eHOQq1uX. 11#((CJJ26!a%B&'q1uX QFA))AaD/U$W--!''*Qye)~ #y(C D%$'$9$9C !CHCICG }}S! !44Q ENn-- -9 U"! E!@J'  s=, U48 U"Q*U4/|j| dd|j| dd|j| dd|St| dd|_t| dd|_ |j| dd\|_ |_|S| d vr||} |j| ddd |j| dd|j| dd | d kDr>t| d d |_t| d d|_ | dkDrt| dd|_ |S|j|||dC|j|||d} |j!|||| \}}||j#||||S|dz| kr||dzdk(rt|_|j||dz}|j%|\|_ |_ |dz| kr4||dzdk(r)|j||dz\|_ |_|dz }|dz }|S|dz| kr||dzdvr||dz}|j||dz| kr|j'||dzs||dzj)r|j||dzn6|j+||dz}||j|dn t |dz| krS||dz|k(rH|j+||dz}||j|dn|j||dz|dz }|dz }|dz }|S|dz| k\s|j'||dzrt|dz| krT|j-||dz=t}|j/||j-||dz|_|dz }n|j|dz }|S|j-||dzLdcxkrdkrAnn>t|}|j/||j-||dz|_|dz }|S|j1r|j||S|s t |S#t$r*} tjt d| Yd} ~ 1d} ~ wwxYw)NzUnknown numeric tokenr)r rGr'rKr rGr,)r#rrc r#T) allow_jump)rvrwr,rr) _to_decimal Exceptionr6r7rr6rrrrfindr5_parsemsrr0 _find_hms_idx _parse_hms _assign_hms_parse_min_secrrUrrrRr )r"tokensidxr.rXrrVrZrjr@r^rYrOhms_idxrr[rs r#rPzparser._parse_numeric_tokenksC[  C$$Z0EZF  HMf. HH  1W S1Wo$hhvcAg'/s A1Ra5zCH{ 12Z V Sq[VaZF3K,<, B B CsT U$U  Uct|}|dz|kr|j||dz|dz}|S|r1|dz|kr)||dzdk(r|j||dz|dz}|S|dkDr|j||dz |dz }|Sd|cxkr|dz k(r,nn)||dz dk(r|j||dz |dz }|Sd}|S)Nr'r r+r)r6r)r"rqrpr.rfrYrrs r#rlzparser._find_hms_idxs F  q55=TXXfSUm4@AgG2/SUU]vc!e}/Chhvc!e}%1AgG&#1W&Q-0< !eG# q VCE]c%9hhvc!e}%1AgG Gr%c|j|}|dk(r-t||_|dzrtd|dzz|_yy|dk(r|j |\|_|_y|dk(r|j |\|_|_yy)Nrr'rMr )rhrrrrorrkr0)r"rrZrrjs r#rnzparser._assign_hmss  , !85zCHqy UQY0 AX'+':':5'A $SZ AX,0MM*,E )SZr%c|duxrH|duxrB|duxr<t|dkxr,td|Dxs||jjvS)NrNc3@K|]}|tjvywrC)stringascii_uppercase)rnrs r#roz*parser._could_be_tzname..%s@QQ&000@s)r6allr.r)r"rrrr<s r#rSzparser._could_be_tzname sfD 0$0D 0E a0@%@@/TYY...  1r%cxd}|r|d}||rd}|Stdd|cxkrdksn|rd}|Std|S)z For fuzzy parsing, 'a' or 'am' (both valid English words) may erroneously trigger the AM/PM flag. Deal with that here. TFz%No hour specified with AM or PM flag.rr#z)Invalid hour specified for 12-hour clock.)r)r"rrrVr\s r#rQzparser._ampm_valid(sn   T%K <# !!HIIdb# !!LMMr%c@|dkr |dk(r|dz }|S|dk(r|dk(rd}|S)Nr#r'rrD)r"rrs r#rRzparser._adjust_ampmDs8 "9 BJD RZDAID r%cNt|}d}|dz}|rtd|z}||fS)Nr'rM)r)r"rjrr sec_remainders r#rozparser._parse_min_secKs8U m+,Fr%c|d}|}||fS||kDr|j||}|}||fS|j||dz}|}||fSr)r)r"rqrpr.rrrnew_idxs r#rmzparser._parse_hmsWss ?CG~s]((6'?+CG ~((6'?+a/CG~r%cd|vr t|dfS|jd\}}t|t|jddddfS)z9Parse a I[.F] seconds value into (seconds, microseconds).r,rrbr*N)rr9ljust)r"rjrfs r#rkzparser._parsemsmsO e u:q= ;;s#DAqq63qwwq#r233 3r%c t|}|js td |S#t$r.}d|z}t j t||Yd}~yd}~wwxYw)Nz*Converted decimal value is infinite or NaNzCould not convert %s to decimal)r is_finiterrir6r7)r"r decimal_valuer@msgs r#rhzparser._to_decimalush !#CLM!**, !MNN- !  /3c9C NN:c?A . . /s&+ A"$AA"cBt|r |||}n|j|}t|tjs||}|St|t rt j|}|St|trt j||}|Std)Nz9Offset must be tzinfo subclass, tz string, or int offset.) callablerrr2tzinforr tzstrrrr)r"r=rrtzdatars r# _build_tzinfozparser._build_tzinfos G VX.F[[(F fhoo .&.F  *XXf%F   .[[0F -. .r%c,t|s|re|j|vrW|j||j|j}|j |}|j ||j}|S|jr|jt jvr|j tj}|j ||j}|j|jk7rB|j|jjvr |j tj}|S|jdk(r"|j tj}|S|jr<|j tj|j|j}|S|js|js|}|S|jr7tjdj|jt|}S)N)rrztzname {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)rrrrr:_assign_tznamerr tzlocalr.rrwarningsr rUnknownTimezoneWarning)r"naiverr=rawares r#r9zparser._build_tzawares W 'cjjG.C''S\\JFMMM0E''szz:ED AZZCJJ$++5MMM6E''szz:E #**,JJ$))"3"33 RVV 4. +\\Q MMM0E( %\\MMSZZ)NMOE" CLLE ZZ MM'(.vSZZv'@#9  ; E r%ci}dD]}t||}||||<d|vr|j |jn |j}|j |jn |j}|j |jn |j}|t ||dkDrt ||d|d<|j di|} |j /|js#| tj|j z} | S)N)rrr%rrrr0r%r')rrD)rrrr%rr:rr ) r"rr;replrarjcyearcmonthcdayrs r#r5zparser._build_naives8 #DC&E "T  #  %(HH$4GLL#((E&)ii&7W]]SYYF"%''/7;;swwDj/22(7:U '$' ;; "377M77 LLE r%c|j|k7r,tj|d}|j|k(r|S|S)Nr')fold)rr enfold)r"dtrnew_dts r#rzparser._assign_tznames8 99;& YYr*F}}&(  r%cg}tt|D];\}}|dkDr|dz ||dz k(r|d||z|d<(|j||=|S)z >>> tokens = ["foo", " ", "bar", " ", "19June2000", "baz"] >>> skipped_idxs = [0, 1, 2, 5] >>> _recombine_skipped(tokens, skipped_idxs) ["foo bar", "baz"] rr'r0)rsortedr5)r"rprWr>rrqs r#rUzparser._recombine_skippedss| 45 3FAs1uqLQ$77%3B%7&+%Er"%%fSk2  3 r%rC)NFN)NNFF)rrWrXr$r r]rEr4rPrlrnrSrQrRrormrkrhrr9r5rrUrDr%r#r,r,8s)&*&*WrG+G DI!&ObAF DF 18  ,4 !$$&P2r%r,c j|rt|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. )r,r DEFAULTPARSER)r:rrs r#r r s;~'vj!'':6::""75f55r%c(eZdZGddeZdZy) _tzparserc6eZdZgdZGddeZdZdZy)_tzparser._result)stdabbr stdoffsetdstabbr dstoffsetstartendceZdZgdZy)_tzparser._result._attr)rweekrydayjydayr%rNrDrDr%r#_attrrbs 9Ir%rc$|jdS)N)rkrEs r#rsz_tzparser._result.__repr__fs::b> !r%ctj||j|_|j|_yrC)r]r$rrrrEs r#r$z_tzparser._result.__init__is*   &DJzz|DHr%N)rrWrXr_r]rrsr$rDr%r#rEr]s%  9K 9 " $r%rEc |j}tjd|Dcgc]}|s| }}t} t |}d}||kr|}||kr9||Dcgc]}|dvr| c}s"|dz }||kr||Dcgc]}|dvr| c}s"||k7r|j sd} dj ||||_nd} dj ||||_t|D]} |j| |}||kr%||dvs ||dd vr||dvr"d ||d k(} |j||dz }nd } t ||} | d k(r8t|| t||dddzt||dddzz| zn|dz|krV||dzdk(rKt|| t||dzt||dzdzz| z|j||dz }n)| dkr#t|| t||dddz| zny|j||dz }|jrnn||kr||kr.t||D]}||dk(s d||<||dk(sJ|dz }||k\rnd|jdcxkrdkrnn||dD cgc]}|dk7s |D]} | dvr|  c} }s|j|jfD]}t|||_|j||dz }||dk(r+t||dzd z}|j||dz }nt||}|j||dz }|r!||_t||dz dz|_nt|||_|j||dz }t|||_|j||dz }||kr_||dvr"d||d k(} |j||dz }nd} |j||j(t||| zz|_t-d|zdzdzdzdzd zt.j0n|jddk(r||djd!dkr||dD cgc]}|d"vs|D]} | d vr|  c} }s|j|jfD]}||d#k(r*|j||dz }t|||_n||d$k(r|j||dz }t|||_|j||dz }||d%vsJ|j||dz }t|||_|j d&k(rd |_|j||dz }||d%vsJ|j||dz }t||dz dz|_nt||dz|_|j||dz }||kr7||d!k(r.|j||dz }t ||} | d k(r/t||dddzt||dddzz|_n|dz|kr||dzdk(rt||dzt||dzdzz|_|j||dz }|dz|krd||dzdk(rY|j||dz }|xj&t||z c_n!| dkrt||dddz|_ny|j||dz }||k(s ||dk(sJ|dz }||k\sJt=t|j?|}|Dchc]}|| c}jAddh |_!|Scc}wcc}wcc}wcc} }wcc} }w#t6t8t:f$rYywxYwcc}w)'Nz([,:.]|[a-zA-Z]+|[0-9]+)rz0123456789:,-+r'rrrrH 0123456789)r'r0rIr0rGr rLrMrKrur.rc z 0123456789+-rv)rvrIrJzParsed 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.rw)r.rwJrr,rvrKrr)rvr,rN)"rErYr9rMr6rrhrrr5r`rr7rrrrrr%rrrr r DeprecatedTzFormatWarningrrrTrAssertionErrorset differenceissubsetrC)r"rrrr? used_idxsrYrjoffattriir]r^rrj unused_idxsns r#r z_tzparser.parsenslln!4Q4:-&-QqTS[%9F%,,Q/FA%'F!$QqT!Q;#C3qtBQx=43G36qtABx=23E4FIO3PQUU]qQx3#C%(1Y%5%(1q5]R%7&8;A%BC&,,Q/FA#q[#C$'!RaMD$86$AC$(!((+Q{{ee)j5yq%#Ats{"!#ts{"{QEzqwws|(q("#AB%>Q18 !>Qn%<>q>))SWW-A!!A$iAG$$Q'FAts{ #Aa!eH  2!((+Q #AaD $$Q'FA!&%(1Y]a$7 #AaD $$Q'FA 1YAF$$Q'FA+,u9tz)!(1!5!((+Q!"$$Q'%(]]S1Y5G%GCM-5LMJKNNJ J + + -/,H,H J ''#,!#!" C(8A(="#AB%$?aQqT$?$H$H#c$S S w J)C)C|>V.Ds;##;srdrf)rhrrr)r"rs r#rszParserError.__repr__Cs/yy;;;>>22D99r%)rrWrXrrrsr)r*s@r#rr5s6 :r%rceZdZdZy)rzhRaised when the parser finds a timezone it cannot parse into a tzinfo. .. versionadded:: 2.7.0 N)rrWrXrrDr%r#rrHsr%rrC)&r __future__rr2rYrwrrcalendarriorr6rrdecimalrr rr r __all__objectrr]rrMrr,rr rrrrrRuntimeWarningrrDr%r#rs:(  ( 0 ^"v^"B3&3,VVrk 4k \x Vx v b6JPPf+(:*:&^r%