3 6cY @sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl m Z mZddl mZyddlmZmZWnek rdZZYnXejdZejjdZejZGd d d ejZGd d d ejZGd dde ZGdddeZGdddeZ Gddde Z!Gddde Z"Gddde"Z#GdddeZ$Gddde Z%GdddeZ&ej'dkrd d!gZ(d"d#d$d%gZ)ngZ(gZ)d0d&d'Z*d1d(d)Z+d2d*d+Z,d,d-Z-Gd.d/d/eZ.dS)3a{ This module offers timezone implementations subclassing the abstract :py:`datetime.tzinfo` type. There are classes to handle tzfile format files (usually are in :file:`/etc/localtime`, :file:`/usr/share/zoneinfo`, etc), TZ environment string (in all known formats), given ranges (with help from relative deltas), local machine timezone, fixed offset timezone, and UTC timezone. N) string_types)tzname_in_python2_tzinfo_total_seconds) tzrangebaseenfold)_validate_fromutc_inputs)tzwin tzwinlocalc@sbeZdZdZddZddZeddZdd Ze d d Z d d Z dZ ddZ ddZejZdS)tzutczD This is a tzinfo object that represents the UTC time zone. cCstS)N)ZERO)selfdtr/usr/lib/python3.6/tz.py utcoffset$sztzutc.utcoffsetcCstS)N)r )rrrrrdst'sz tzutc.dstcCsdS)NUTCr)rrrrrtzname*sz tzutc.tznamecCsdS)a6 Whether or not the "wall time" of a given datetime is ambiguous in this zone. :param dt: A :py:class:`datetime.datetime`, naive or time zone aware. :return: Returns ``True`` if ambiguous, ``False`` otherwise. .. versionadded:: 2.6.0 Fr)rrrrr is_ambiguous.sztzutc.is_ambiguouscCs|S)z Fast track version of fromutc() returns the original ``dt`` object for any valid :py:class:`datetime.datetime` object. r)rrrrrfromutc>sz tzutc.fromutccCs0t|ttfstSt|tp.t|to.|jtkS)N) isinstancer tzoffsetNotImplemented_offsetr )rotherrrr__eq__Fs z tzutc.__eq__NcCs ||k S)Nr)rrrrr__ne__Osz tzutc.__ne__cCs d|jjS)Nz%s()) __class____name__)rrrr__repr__Rsztzutc.__repr__)r __module__ __qualname____doc__rrrrrr rr__hash__rr!object __reduce__rrrrr s  r c@sjeZdZdZddZddZddZedd Ze d d Z d d Z ddZ dZ ddZddZejZdS)ra1 A simple class for representing a fixed offset from UTC. :param name: The timezone name, to be returned when ``tzname()`` is called. :param offset: The time zone offset in seconds, or (since version 2.6.0, represented as a :py:class:`datetime.timedelta` object. c Cs>||_y t|}Wnttfk r*YnXtj|d|_dS)N)seconds)_namer TypeErrorAttributeErrordatetime timedeltar)rnameoffsetrrr__init__cs  ztzoffset.__init__cCs|jS)N)r)rrrrrrmsztzoffset.utcoffsetcCstS)N)r )rrrrrrpsz tzoffset.dstcCs|jS)N)r))rrrrrrssztzoffset.tznamecCs ||jS)N)r)rrrrrrwsztzoffset.fromutccCsdS)a6 Whether or not the "wall time" of a given datetime is ambiguous in this zone. :param dt: A :py:class:`datetime.datetime`, naive or time zone aware. :return: Returns ``True`` if ambiguous, ``False`` otherwise. .. versionadded:: 2.6.0 Fr)rrrrrr{sztzoffset.is_ambiguouscCst|tstS|j|jkS)N)rrrr)rrrrrrs ztzoffset.__eq__NcCs ||k S)Nr)rrrrrrsztzoffset.__ne__cCs"d|jjt|jtt|jfS)Nz %s(%s, %s))rr reprr)intrr)rrrrr!sztzoffset.__repr__)r r"r#r$r0rrrrr rrrr%rr!r&r'rrrrrXs    rcsxeZdZdZfddZddZddZedd Zd d Z d d Z dddZ ddZ dZ ddZddZejZZS)tzlocalzR A :class:`tzinfo` subclass built around the ``time`` timezone functions. cs`tt|jtjtj d|_tjr:tjtj d|_ n|j|_ |j |j|_ t |j |_ dS)N)r()superr3r0r,r-timetimezone _std_offsetZdaylightZaltzone _dst_offset _dst_savedbool_hasdst)r)rrrr0sztzlocal.__init__cCs,|dkr|jrdS|j|r"|jS|jSdS)N)r;_isdstr8r7)rrrrrrs  ztzlocal.utcoffsetcCs0|dkr|jrdS|j|r(|j|jStSdS)N)r;r<r8r7r )rrrrrrs   z tzlocal.dstcCstj|j|S)N)r5rr<)rrrrrrsztzlocal.tznamecCs$|j|}| o"||j||jkS)a6 Whether or not the "wall time" of a given datetime is ambiguous in this zone. :param dt: A :py:class:`datetime.datetime`, naive or time zone aware. :return: Returns ``True`` if ambiguous, ``False`` otherwise. .. versionadded:: 2.6.0 ) _naive_is_dstr9)rrZ naive_dstrrrrs ztzlocal.is_ambiguouscCst|}tj|tjjS)N)_datetime_to_timestampr5 localtimer6Ztm_isdst)rr timestamprrrr=sztzlocal._naive_is_dstTcCsF|js dS|j|}t|dd}|j|rB|dk r>|j| SdS|S)NFfoldT)r;r=getattrr_fold)rrZ fold_naiveZdstvalrArrrr<s    ztzlocal._isdstcCs&t|tstS|j|jko$|j|jkS)N)rr3rr7r8)rrrrrrs  ztzlocal.__eq__NcCs ||k S)Nr)rrrrrr sztzlocal.__ne__cCs d|jjS)Nz%s())rr )rrrrr!sztzlocal.__repr__)T)r r"r#r$r0rrrrrr=r<rr%rr!r&r' __classcell__rr)rrr3s    (r3c@sReZdZdddddddgZdd Zd d Zd d ZdZddZddZ ddZ dS)_ttinfor/deltaisdstabbrisstdisgmt dstoffsetcCs x|jD]}t||dqWdS)N) __slots__setattr)rattrrrrr0s z_ttinfo.__init__cCsRg}x6|jD],}t||}|dk r |jd|t|fq Wd|jjdj|fS)Nz%s=%sz%s(%s)z, )rLrBappendr1rr join)rlrNvaluerrrr!s   z_ttinfo.__repr__cCsbt|tstS|j|jko`|j|jko`|j|jko`|j|jko`|j|jko`|j|jko`|j |j kS)N) rrErr/rFrGrHrIrJrK)rrrrrr$s       z_ttinfo.__eq__NcCs ||k S)Nr)rrrrrr2sz_ttinfo.__ne__cCs(i}x|jD]}t||d||<q W|S)N)rLrB)rstater.rrr __getstate__5s z_ttinfo.__getstate__cCs,x&|jD]}||krt||||qWdS)N)rLrM)rrSr.rrr __setstate__;s z_ttinfo.__setstate__) r r"r#rLr0r!rr%rrTrUrrrrrEs  rEc@s,eZdZdZdddddddd gZd d Zd S) _tzfilezw Lightweight class for holding the relevant transition and time zone information read from binary tzfiles. trans_listtrans_list_utc trans_idx ttinfo_list ttinfo_std ttinfo_dst ttinfo_before ttinfo_firstcKs(x"|jD]}t|||j|dqWdS)N)attrsrMget)rkwargsrNrrrr0Is z_tzfile.__init__N)r r"r#r$r_r0rrrrrVAs rVcseZdZdZd&fdd ZddZddZd'd d Zd d ZddZ ddZ d(ddZ ddZ ddZ ddZeddZddZdZddZd d!Zd"d#Zd$d%ZZS))tzfilea This is a ``tzinfo`` subclass thant allows one to use the ``tzfile(5)`` format timezone files to extract current and historical zone information. :param fileobj: This can be an opened file stream or a file name that the time zone information can be read from. :param filename: This is an optional parameter specifying the source of the time zone information in the event that ``fileobj`` is a file object. If omitted and ``fileobj`` is a file stream, this parameter will be set either to ``fileobj``'s ``name`` attribute or to ``repr(fileobj)``. See `Sources for Time Zone and Daylight Saving Time Data `_ for more information. Time zone files can be compiled from the `IANA Time Zone database files `_ with the `zic time zone compiler `_ Nc stt|jd}t|tr2||_t|d}d}n.|dk rB||_nt|drV|j|_n t ||_|dk r|stt |}|}|j |}WdQRX|j |dS)NFrbTr.) r4rbr0rr _filenameopenhasattrr.r1_ContextWrapper _read_tzfile _set_tzdata)rfileobjfilenameZfile_opened_hereZ file_streamtzobj)rrrr0ds"     ztzfile.__init__cCs*x$tjD]}t|d|t||qWdS)z= Set the time zone data of this object from a _tzfile object _N)rVr_rMrB)rrlrNrrrri|s ztzfile._set_tzdatacst|jdjdkr td|jdtjd|jd\}}}}}}|rnttjd||j|d_ng_|rtjd||j|_ng_g}x(t |D]} |j tjd |jd qW|j|j} |r|j |d t j |rtjd ||j|} |r"tjd ||j|} g_xt |D]} || \} }}d | dd } t}| |_tjd|_tj| d|_||_| || jd||_|| ko| | dk|_|| ko| | dk|_jj |q2WfddjD_d_d_d_jr؈js$jd__nxt |dddD]V} j| }j r`|j r`|_nj rx|jrx|_jr6jr6Pq6Wjrj rj_x,jD]}|js|_PqWjd_d}g_xltjD]^\} }|js |j}|}n*|dk r*|j||_|j| <|p2d}jj j| |qWd}x~t t t!jD]h} j| }|jr|jp|dks|j||_n|j}t"|jtjstj|jd|_|j| <qhWt#j_t#j_t#j_S)NZTZifzmagic not foundz>6lz>%dlz>%dBz>lbbz>%db<r)r(csg|]}j|qSr)rZ).0idx)outrr sz'tzfile._read_tzfile..rrz)$rVreaddecode ValueErrorstructunpacklistrXrYrangerOseekosSEEK_CURrZrEr/r,r-rKrFrGfindrHrIrJr[r\r]r^rW enumeratereversedlenrtuple)rrjZ ttisgmtcntZ ttisstdcntZleapcntZtimecntZtypecntZcharcntZttinfoirHrIrJZgmtoffrGZabbrindttiZ laststdoffsetr/r)rxrrhs                         ztzfile._read_tzfileFcCs6|js dSt|}|r|jn|j}tj||}|dS)Nr) _trans_listr>Z_trans_list_utcbisectZ bisect_right)rrin_utcr@rWrwrrr_find_last_transition^s  ztzfile._find_last_transitioncCs8|dks|dt|jkr |jS|dkr.|jS|j|S)Nrr)rr _ttinfo_stdZ_ttinfo_before _trans_idx)rrwrrr _get_ttinfoms ztzfile._get_ttinfocCs|j|}|j|S)N)_resolve_ambiguous_timer)rrrwrrr _find_ttinfoxs ztzfile._find_ttinfocCsnt|tjstd|j|k r&td|j|dd}|j|}|tj|jd}|j ||d}t |t |dS)a The ``tzfile`` implementation of :py:func:`datetime.tzinfo.fromutc`. :param dt: A :py:class:`datetime.datetime` object. :raises TypeError: Raised if ``dt`` is not a :py:class:`datetime.datetime` object. :raises ValueError: Raised if this is called with a ``dt`` which does not have this ``tzinfo`` attached. :return: Returns a :py:class:`datetime.datetime` object representing the wall time in ``self``'s time zone. z&fromutc() requires a datetime argumentzdt.tzinfo is not selfT)r)r()rw)rA) rr,r*tzinfor}rrr-r/rrr2)rrrwrZdt_outrArrrr}s   ztzfile.fromutccCsd|dkr|j|}t|}|j|}|dks4|dkr8dS|j|dj|j}|j|}|||kS)a6 Whether or not the "wall time" of a given datetime is ambiguous in this zone. :param dt: A :py:class:`datetime.datetime`, naive or time zone aware. :return: Returns ``True`` if ambiguous, ``False`` otherwise. .. versionadded:: 2.6.0 NrFr)rr>rr/r)rrrwr@rZodZttrrrrs   ztzfile.is_ambiguouscCsF|j|}|j|}|dks$|dkr(|St| o:|j||}||S)Nr)rrCr2r)rrrwrCZ idx_offsetrrrrs   ztzfile._resolve_ambiguous_timecCs"|dkr dS|jstS|j|jS)N)rr rrF)rrrrrrs ztzfile.utcoffsetcCs0|dkr dS|jstS|j|}|js*tS|jS)N)Z _ttinfo_dstr rrGrK)rrrrrrrs z tzfile.dstcCs |j s|dkrdS|j|jS)N)rrrH)rrrrrrsz tzfile.tznamecCs2t|tstS|j|jko0|j|jko0|j|jkS)N)rrbrrrZ _ttinfo_list)rrrrrrs    z tzfile.__eq__cCs ||k S)Nr)rrrrrrsz tzfile.__ne__cCsd|jjt|jfS)Nz%s(%s))rr r1rd)rrrrr!sztzfile.__repr__cCs |jdS)N) __reduce_ex__)rrrrr'sztzfile.__reduce__cCs|jd|jf|jfS)N)rrd__dict__)rZprotocolrrrrsztzfile.__reduce_ex__)N)F)N)r r"r#r$r0rirhrrrrrrrrrrrr%rr!r'rrDrr)rrrbNs(]  $    rbc@s6eZdZdZd ddZddZddZed d ZdS) tzrangeaQ The ``tzrange`` object is a time zone specified by a set of offsets and abbreviations, equivalent to the way the ``TZ`` variable can be specified in POSIX-like systems, but using Python delta objects to specify DST start, end and offsets. :param stdabbr: The abbreviation for standard time (e.g. ``'EST'``). :param stdoffset: An integer or :class:`datetime.timedelta` object or equivalent specifying the base offset from UTC. If unspecified, +00:00 is used. :param dstabbr: The abbreviation for DST / "Summer" time (e.g. ``'EDT'``). If specified, with no other DST information, DST is assumed to occur and the default behavior or ``dstoffset``, ``start`` and ``end`` is used. If unspecified and no other DST information is specified, it is assumed that this zone has no DST. If this is unspecified and other DST information is *is* specified, DST occurs in the zone but the time zone abbreviation is left unchanged. :param dstoffset: A an integer or :class:`datetime.timedelta` object or equivalent specifying the UTC offset during DST. If unspecified and any other DST information is specified, it is assumed to be the STD offset +1 hour. :param start: A :class:`relativedelta.relativedelta` object or equivalent specifying the time and time of year that daylight savings time starts. To specify, for example, that DST starts at 2AM on the 2nd Sunday in March, pass: ``relativedelta(hours=2, month=3, day=1, weekday=SU(+2))`` If unspecified and any other DST information is specified, the default value is 2 AM on the first Sunday in April. :param end: A :class:`relativedelta.relativedelta` object or equivalent representing the time and time of year that daylight savings time ends, with the same specification method as in ``start``. One note is that this should point to the first time in the *standard* zone, so if a transition occurs at 2AM in the DST zone and the clocks are set back 1 hour to 1AM, set the `hours` parameter to +1. **Examples:** .. testsetup:: tzrange from dateutil.tz import tzrange, tzstr .. doctest:: tzrange >>> tzstr('EST5EDT') == tzrange("EST", -18000, "EDT") True >>> from dateutil.relativedelta import * >>> range1 = tzrange("EST", -18000, "EDT") >>> range2 = tzrange("EST", -18000, "EDT", -14400, ... relativedelta(hours=+2, month=4, day=1, ... weekday=SU(+1)), ... relativedelta(hours=+1, month=10, day=31, ... weekday=SU(-1))) >>> tzstr('EST5EDT') == range1 == range2 True NcCs@ddlma||_||_y t|}Wnttfk r<YnXy t|}Wnttfk rbYnX|dk r|tj|d|_ nt |_ |dk rtj|d|_ n(|r|dk r|j tjd d|_ nt |_ |r|dkrtjd ddtj d d|_ n||_ |r|dkrtjdd d tj dd|_n||_|j |j |_t|j |_dS)Nr) relativedelta)r(r)hoursrn)rmonthdayweekday rrrrrz)dateutilr _std_abbr _dst_abbrrr*r+r,r-r7r r8SU _start_delta _end_delta_dst_base_offset_r:hasdst)rstdabbr stdoffsetdstabbrrKstartendrrrr0Js:     ztzrange.__init__cCs4|js dStj|dd}||j}||j}||fS)a For a given year, get the DST on and off transition times, expressed always on the standard time side. For zones with no transitions, this function returns ``None``. :param year: The year whose transitions you would like to query. :return: Returns a :class:`tuple` of :class:`datetime.datetime` objects, ``(dston, dstoff)`` for zones with an annual DST transition, or ``None`` for fixed offset zones. Nr)rr,rr)rZyearZ base_yearrrrrr transitionsys   ztzrange.transitionscCsVt|tstS|j|jkoT|j|jkoT|j|jkoT|j|jkoT|j|jkoT|j|jkS)N) rrrrrr7r8rr)rrrrrrs      ztzrange.__eq__cCs|jS)N)r)rrrr_dst_base_offsetsztzrange._dst_base_offset)NNNNN) r r"r#r$r0rrpropertyrrrrrrsI - rc@s,eZdZdZd ddZd ddZdd Zd S) tzstra ``tzstr`` objects are time zone objects specified by a time-zone string as it would be passed to a ``TZ`` variable on POSIX-style systems (see the `GNU C Library: TZ Variable`_ for more details). There is one notable exception, which is that POSIX-style time zones use an inverted offset format, so normally ``GMT+3`` would be parsed as an offset 3 hours *behind* GMT. The ``tzstr`` time zone object will parse this as an offset 3 hours *ahead* of GMT. If you would like to maintain the POSIX behavior, pass a ``True`` value to ``posix_offset``. The :class:`tzrange` object provides the same functionality, but is specified using :class:`relativedelta.relativedelta` objects. rather than strings. :param s: A time zone string in ``TZ`` variable format. This can be a :class:`bytes` (2.x: :class:`str`), :class:`str` (2.x: :class:`unicode`) or a stream emitting unicode characters (e.g. :class:`StringIO`). :param posix_offset: Optional. If set to ``True``, interpret strings such as ``GMT+3`` or ``UTC+3`` as being 3 hours *behind* UTC rather than ahead, per the POSIX standard. .. _`GNU C Library: TZ Variable`: https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html Fc Csddlma||_tj|}|dkr,td|jd krJ| rJ|jd 9_tj||j|j|j |j ddd|j s~d|_ d|_ n&|j |j|_ |j r|j |jdd |_ t|j |_dS) Nr)parserzunknown string formatGMTrrF)rr)isend)rrrz)rr_sZ_parsetzr}rrrr0rrKrr_deltarrr:r)rsZ posix_offsetresrrrr0s"   ztzstr.__init__rcCs<ddlm}i}|jdk rr|j|d<|jdk r`|j|j|j|d<|jdkrVd|d<qpd|d<q|jr|j|d<n*|jdk r|j|d<n|jdk r|j|d <|s|sd |d<d|d<|jd|d<nd |d<d|d<|jd|d<|j dk r|j |d <nd |d <|r0|j |j }|d |j |j d8<|jf|S)Nr)rrrrrrZyeardayZ nlyeardayrnrr(i iQrrz)rrrrZweekrZydayZjydayrr5r8r7r(Zdays)rxrrrarFrrrrs<               z tzstr._deltacCsd|jjt|jfS)Nz%s(%s))rr r1r)rrrrr!sztzstr.__repr__N)F)r)r r"r#r$r0rr!rrrrrs )rc@seZdZdddZdS)_tzicalvtzcompNcCs@tj|d|_tj|d|_|j|j|_||_||_||_dS)N)r()r,r- tzoffsetfrom tzoffsetto tzoffsetdiffrGrrrule)rrrrGrrrrrr0 s z_tzicalvtzcomp.__init__)NN)r r"r#r0rrrrr srcsZeZdZgffdd ZddZddZddZd d Zed d Z d dZ e j Z Z S) _tzicalvtzcs*tt|j||_||_g|_g|_dS)N)r4rr0_tzid_comps _cachedate _cachecomp)rtzidcomps)rrrr0s z_tzicalvtz.__init__c Cs t|jdkr|jdS|jdd}y|j|jj||j|fStk rTYnXd}d}x4|jD]*}|j||}|rf| s||krf|}|}qfW|sx"|jD]}|j s|}PqW|d}|jj d||j|f|jj d|t|jdkr|jj |jj |S)Nrr)rr) rrreplacerrindexrCr} _find_compdtrGinsertpop)rrZ lastcompdtZlastcompcompcompdtrrr _find_comps4       z_tzicalvtz._find_compcCs2|jtkr|j|r||j8}|jj|dd}|S)NT)Zinc)rr rCrZbefore)rrrrrrrrIs z_tzicalvtz._find_compdtcCs|dkr dS|j|jS)N)rr)rrrrrrQsz_tzicalvtz.utcoffsetcCs|j|}|jr|jStSdS)N)rrGrr )rrrrrrrWs z_tzicalvtz.dstcCs |j|jS)N)rr)rrrrrr^sz_tzicalvtz.tznamecCsdt|jS)Nz)r1r)rrrrr!bsz_tzicalvtz.__repr__)r r"r#r0rrrrrrr!r&r'rDrr)rrrs* rc@sBeZdZdZddZddZdddZd d Zd d Zd dZ dS)tzicala\ This object is designed to parse an iCalendar-style ``VTIMEZONE`` structure as set out in `RFC 2445`_ Section 4.6.5 into one or more `tzinfo` objects. :param `fileobj`: A file or stream in iCalendar format, which should be UTF-8 encoded with CRLF endings. .. _`RFC 2445`: https://www.ietf.org/rfc/rfc2445.txt c Csjddlmat|tr(||_t|d}nt|dt||_t|}i|_ |}|j |j WdQRXdS)Nr)rrr.) rrrrrrerBr1rg_vtz _parse_rfcr{)rrjZfobjrrrr0ss   ztzical.__init__cCst|jjS)z? Retrieves the available time zones as a list. )rrkeys)rrrrrsz tzical.keysNcCsP|dkrDt|jdkr tdnt|jdkr6tdtt|j}|jj|S)a Retrieve a :py:class:`datetime.tzinfo` object by its ``tzid``. :param tzid: If there is exactly one time zone available, omitting ``tzid`` or passing :py:const:`None` value returns it. Otherwise a valid key (which can be retrieved from :func:`keys`) is required. :raises ValueError: Raised if ``tzid`` is not specified but there are either more or fewer than 1 zone defined. :returns: Returns either a :py:class:`datetime.tzinfo` object representing the relevant time zone or :py:const:`None` if the ``tzid`` was not found. Nrzno timezones definedrz more than one timezone available)rrr}nextiterr`)rrrrrr`s z tzical.getcCs|j}|std|dd kr>d|ddk}|dd}nd}t|dkrzt|dddt|ddd |St|d krt|dddt|ddd t|dd|Std |dS)Nz empty offsetr+-rrnrirsrqzinvalid offset: )rrrzr)rzrr)stripr}rr2)rrsignalrrr _parse_offsets  , <ztzical._parse_offsetcCsH|j}|stdd}xh|t|kr||j}|s>||=q|dkrv|ddkrv||d|dd7<||=q|d7}qWd}g}d}d}x|D]}|sq|jdd\} } | jd} | std| dj} | dd} |r$| d kr(| d)krn td | | }d} d} d}g}d}q@| d kr| dkr|rNtd||s\td|sjtdt|||j|<d}n| |kr| std| dkrtd|dkrtdd}|rtj dj |dddd}t | ||d k||}|j |d}n td| q@|r| dkr2|j |d} n| d*krH|j |n| dkrx| rltd| | df|j | } nj| dkr| rtd | d|j | }n>| d!kr| rtd"| d| }n| d#krn td$| n>| d%kr | rtd&| d| }n| d+krn td$| q| d kr| dkrd}g}d}qWdS),Nz empty stringr rF:;zempty property nameZBEGINSTANDARDDAYLIGHTzunknown component: ZENDZ VTIMEZONEzcomponent not closed: zmandatory TZID not foundz at least one component is neededzmandatory DTSTART not foundz mandatory TZOFFSETFROM not found T)Z compatibleZignoretzcachezinvalid component end: ZDTSTARTRRULERDATEEXRULEEXDATEZ TZOFFSETFROMzunsupported %s parm: %s Z TZOFFSETTOzunsupported TZOFFSETTO parm: ZTZNAMEzunsupported TZNAME parm: COMMENTzunsupported property: ZTZIDzunsupported TZID parm: TZURL LAST-MODIFIED)rr)rrrr)rrr) splitlinesr}rrstripsplitupperrrrZrrulestrrPrrOr)rrlinesrlinerrZinvtzZcomptyper.rRZparmsZ founddtstartrrZ rrulelinesrZrrrrrrrs                            ztzical._parse_rfccCsd|jjt|jfS)Nz%s(%s))rr r1r)rrrrr!+sztzical.__repr__)N) r r"r#r$r0rr`rrr!rrrrrhs  vrZwin32z/etc/localtimer?z/usr/share/zoneinfoz/usr/lib/zoneinfoz/usr/share/lib/zoneinfoz /etc/zoneinfocCsDd}|s,ytjd}Wntk r*YnX|dks<|dkrxtD]v}tjj|s|}x*tD] }tjj||}tjj|r\Pq\WqBtjj|rByt |}PWqBt t t fk rYqBXqBWt }nz|jdr|dd }tjj|r tjj|rt |}nd}n6x2tD]l}tjj||}tjj|sP|jdd}tjj|sPqyt |}PWnt t t fk rzYnXqWd}tdk ry t|}Wntk rd}YnX|sddlm}|j|}|s@xb|D]6}|dkry t|}Wnt k rYnXPqW|d kr.t}n|tjkr@t }|S) NZTZrrrrmr)get_zonefile_instance 0123456789rrrz)rr)renvironKeyErrorTZFILESpathisabsTZPATHSrPisfilerbIOErrorOSErrorr}r3 startswithrr Z WindowsErrorZdateutil.zoneinforr`rr r5r)r.tzfilepathrkrrcrrrgettz:sz                       rcCsZ|dkr |jdkrtd|j}|jdd}|j|djtj|}|jdd}||kS)a Given a datetime and a time zone, determine whether or not a given datetime would fall in a gap. :param dt: A :class:`datetime.datetime` (whose time zone will be ignored if ``tz`` is provided.) :param tz: A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If ``None`` or not provided, the datetime's own time zone will be used. :return: Returns a boolean value whether or not the "wall time" exists in ``tz``. Nz,Datetime is naive and no time zone provided.)r)rr}rZ astimezoner )rrZdt_rtrrrdatetime_existss   rc Cs|dkr |jdkrtd|j}t|dd}|dk rLy |j|SYnX|j|d}t|dd}t|dd}|j|jk}|j|jk}|o| S)a\ Given a datetime and a time zone, determine whether or not a given datetime is ambiguous (i.e if there are two times differentiated only by their DST status). :param dt: A :class:`datetime.datetime` (whose time zone will be ignored if ``tz`` is provided.) :param tz: A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If ``None`` or not provided, the datetime's own time zone will be used. :return: Returns a boolean value whether or not the "wall time" is ambiguous in ``tz``. .. versionadded:: 2.6.0 Nz,Datetime is naive and no time zone provided.r)rr)rAr)rr}rBrrrrr)rrZis_ambiguous_fnZwall_0Zwall_1Z same_offsetZsame_dstrrrdatetime_ambiguouss       rcCst|jddtS)z Convert a :class:`datetime.datetime` object to an epoch timestamp in seconds since January 1, 1970, ignoring the time zone. N)r)rrEPOCH)rrrrr>sr>c@s(eZdZdZddZddZddZdS) rgz^ Class for wrapping contexts so that they are passed through in a with statement. cCs ||_dS)N)context)rrrrrr0sz_ContextWrapper.__init__cCs|jS)N)r)rrrr __enter__sz_ContextWrapper.__enter__cOsdS)Nr)argsrarrr__exit__sz_ContextWrapper.__exit__N)r r"r#r$r0rrrrrrrgsrg)N)N)N)/r$r,r~r5sysrrZsixrZ_commonrrrrrr winr r ImportErrorr-r ZutcfromtimestamprZ toordinalZ EPOCHORDINALrr rr3r&rErVrbrrrrrplatformrrrrrr>rgrrrr s\    8Fv- 5"j RH  J  .