B \@sdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl Z ddl m Z ddl m Z ddlmZmZddlmZmZdd lmZdd lmZmZdd lmZydd lmZmZWnek rdZZYnXdd lmZedZej dZ!e!"Z#e $eGdddej%Z&e $eGdddej%Z'GdddeZ(Gddde)Z*Gddde)Z+GdddeZ,GdddeZ-e $eGddde-Z.Gddde)Z/Gd d!d!eZ0Gd"d#d#e)Z1ej2d$krd%d&gZ3d'd(d)d*gZ4ngZ3gZ4d+d,Z5e5Z6[5dZ?Wn&ek rGd:d;d;e)Z?YnXdS)>a This module offers timezone implementations subclassing the abstract :py:class:`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) OrderedDict) string_types)_thread)tzname_in_python2_tzinfo) tzrangebaseenfold)_validate_fromutc_inputs) _TzSingleton_TzOffsetFactory) _TzStrFactory)tzwin tzwinlocal)warnc@sbeZdZdZddZddZeddZdd Ze d d Z d d Z dZ ddZ ddZejZdS)tzutca This is a tzinfo object that represents the UTC time zone. **Examples:** .. doctest:: >>> from datetime import * >>> from dateutil.tz import * >>> datetime.now() datetime.datetime(2003, 9, 27, 9, 40, 1, 521290) >>> datetime.now(tzutc()) datetime.datetime(2003, 9, 27, 12, 40, 12, 156379, tzinfo=tzutc()) >>> datetime.now(tzutc()).tzname() 'UTC' .. versionchanged:: 2.7.0 ``tzutc()`` is now a singleton, so the result of ``tzutc()`` will always return the same object. .. doctest:: >>> from dateutil.tz import tzutc, UTC >>> tzutc() is tzutc() True >>> tzutc() is UTC True cCstS)N)ZERO)selfdtr9/tmp/pip-build-uw_ogi45/python-dateutil/dateutil/tz/tz.py utcoffsetJsztzutc.utcoffsetcCstS)N)r)rrrrrdstMsz tzutc.dstcCsdS)NUTCr)rrrrrtznamePsz 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_ambiguousTsztzutc.is_ambiguouscCs|S)z Fast track version of fromutc() returns the original ``dt`` object for any valid :py:class:`datetime.datetime` object. r)rrrrrfromutcdsz tzutc.fromutccCs0t|ttfstSt|tp.t|to.|jtkS)N) isinstancertzoffsetNotImplemented_offsetr)rotherrrr__eq__ls z tzutc.__eq__NcCs ||k S)Nr)rr!rrr__ne__usz tzutc.__ne__cCs d|jjS)Nz%s()) __class____name__)rrrr__repr__xsztzutc.__repr__)r% __module__ __qualname____doc__rrrrrr rr"__hash__r#r&object __reduce__rrrrr)s   rc@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 CsB||_y |}Wnttfk r*YnXtjt|d|_dS)N)seconds)_name total_seconds TypeErrorAttributeErrordatetime timedelta_get_supported_offsetr )rnameoffsetrrr__init__s  ztzoffset.__init__cCs|jS)N)r )rrrrrrsztzoffset.utcoffsetcCstS)N)r)rrrrrrsz tzoffset.dstcCs|jS)N)r.)rrrrrrsztzoffset.tznamecCs ||jS)N)r )rrrrrrsztzoffset.fromutccCsdS)a4 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)rrrrrrs ztzoffset.is_ambiguouscCst|tstS|j|jkS)N)rrrr )rr!rrrr"s ztzoffset.__eq__NcCs ||k S)Nr)rr!rrrr#sztzoffset.__ne__cCs"d|jjt|jt|jfS)Nz %s(%s, %s))r$r%reprr.intr r/)rrrrr&sztzoffset.__repr__)r%r'r(r)r7rrrrr rrr"r*r#r&r+r,rrrrr~s    rcsxeZdZdZfddZddZddZedd Zd d Z d d Z dddZ ddZ dZ ddZddZejZZS)tzlocalzR A :class:`tzinfo` subclass built around the ``time`` timezone functions. csltt|tjtj d|_tjr:tjtj d|_ n|j|_ |j |j|_ t |j |_ ttj|_dS)N)r-)superr:r7r2r3timetimezone _std_offsetdaylightaltzone _dst_offset _dst_savedbool_hasdsttupler_tznames)r)r$rrr7s ztzlocal.__init__cCs,|dkr|jrdS||r"|jS|jSdS)N)rD_isdstrAr>)rrrrrrs  ztzlocal.utcoffsetcCs0|dkr|jrdS||r(|j|jStSdS)N)rDrGrAr>r)rrrrrrs   z tzlocal.dstcCs|j||S)N)rFrG)rrrrrrsztzlocal.tznamecCs$||}| o"||||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_dstrB)rrZ naive_dstrrrrs ztzlocal.is_ambiguouscCst|}t|tjjS)N)_datetime_to_timestampr< localtimer=tm_isdst)rr timestamprrrrHsztzlocal._naive_is_dstTcCsF|js dS||}t|dd}||rB|dk r>|| SdS|S)NFfoldT)rDrHgetattrr_fold)rrZ fold_naiveZdstvalrMrrrrGs    ztzlocal._isdstcCst|tr"|j|jko |j|jkSt|trL|j oJ|jddkoJ|jtkSt|trz|j ox|jd|j kox|j|j kSt SdS)Nr>GMTr) rr:r>rArrDrFrrr.r r)rr!rrrr"(s       ztzlocal.__eq__NcCs ||k S)Nr)rr!rrrr#9sztzlocal.__ne__cCs d|jjS)Nz%s())r$r%)rrrrr&<sztzlocal.__repr__)T)r%r'r(r)r7rrrrrrHrGr"r*r#r&r+r, __classcell__rr)r$rr:s    (r:c@sReZdZdddddddgZdd Zd d Zd d ZdZddZddZ ddZ dS)_ttinfor6deltaisdstabbrisstdisgmt dstoffsetcCs x|jD]}t||dqWdS)N) __slots__setattr)rattrrrrr7Fs z_ttinfo.__init__cCsRg}x6|jD],}t||}|dk r |d|t|fq Wd|jjd|fS)Nz%s=%sz%s(%s)z, )rYrNappendr8r$r%join)rlr[valuerrrr&Js   z_ttinfo.__repr__cCsbt|tstS|j|jko`|j|jko`|j|jko`|j|jko`|j|jko`|j|jko`|j |j kS)N) rrRrr6rSrTrUrVrWrX)rr!rrrr"Rs       z_ttinfo.__eq__NcCs ||k S)Nr)rr!rrrr#`sz_ttinfo.__ne__cCs(i}x|jD]}t||d||<q W|S)N)rYrN)rstater5rrr __getstate__cs z_ttinfo.__getstate__cCs,x&|jD]}||krt||||qWdS)N)rYrZ)rr`r5rrr __setstate__is z_ttinfo.__setstate__) r%r'r(rYr7r&r"r*r#rarbrrrrrRBs  rRc@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||||dqWdS)N)attrsrZget)rkwargsr[rrrr7ws z_tzfile.__init__N)r%r'r(r)rlr7rrrrrcos rccseZdZdZd&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 `_ .. note:: Only construct a ``tzfile`` directly if you have a specific timezone file on disk that you want to read into a Python ``tzinfo`` object. If you want to get a ``tzfile`` representing a specific IANA zone, (e.g. ``'America/New_York'``), you should call :func:`dateutil.tz.gettz` with the zone identifier. **Examples:** Using the US Eastern time zone as an example, we can see that a ``tzfile`` provides time zone information for the standard Daylight Saving offsets: .. testsetup:: tzfile from dateutil.tz import gettz from datetime import datetime .. doctest:: tzfile >>> NYC = gettz('America/New_York') >>> NYC tzfile('/usr/share/zoneinfo/America/New_York') >>> print(datetime(2016, 1, 3, tzinfo=NYC)) # EST 2016-01-03 00:00:00-05:00 >>> print(datetime(2016, 7, 7, tzinfo=NYC)) # EDT 2016-07-07 00:00:00-04:00 The ``tzfile`` structure contains a fully history of the time zone, so historical dates will also have the right offsets. For example, before the adoption of the UTC standards, New York used local solar mean time: .. doctest:: tzfile >>> print(datetime(1901, 4, 12, tzinfo=NYC)) # LMT 1901-04-12 00:00:00-04:56 And during World War II, New York was on "Eastern War Time", which was a state of permanent daylight saving time: .. doctest:: tzfile >>> print(datetime(1944, 2, 7, tzinfo=NYC)) # EWT 1944-02-07 00:00:00-04:00 Nc stt|d}t|tr2||_t|d}d}n.|dk rB||_nt|drV|j|_n t ||_|dk r|stt |}|}| |}WdQRX| |dS)NFrbTr5) r;ror7rr _filenameopenhasattrr5r8 _nullcontext _read_tzfile _set_tzdata)rfileobjfilenameZfile_opened_hereZ file_streamtzobj)r$rrr7s"     ztzfile.__init__cCs*x$tjD]}t|d|t||qWdS)z= Set the time zone data of this object from a _tzfile object _N)rcrlrZrN)rryr[rrrrvs ztzfile._set_tzdatac st|ddkr td|dtd|d\}}}}}}|rnttd|||d_ng_|rtd|||_ng_g}x(t |D]} | td |d qW||} |r| |d t j |rtd |||} |r"td |||} g_xt |D]} || \} }}t| } t}| |_td |_tj| d|_||_| || d||_|| ko| | d k|_|| ko| | d k|_j |q2WfddjD_d_d_d_jrȈjsjd __nx|t |dddD]P} j| }jsT|jsT|_njsj|jrj|_jr.jr.Pq.Wjrjsj_x,jD]}|js|_PqWjd _d}d}d}d}g_xt jD]\} }|j}d }|dk r>|jr>|s||}|s,|r,|}tj|d|_|}||}|}|dk rn||krn|j|krn|}|j}|}|}j j| |qWt!j_t!j_t!j_S)NZTZifzmagic not foundz>6lz>%dlz>%dBz>lbbz>%dbr)r-csg|]}j|qSr)rg).0idx)outrr msz'tzfile._read_tzfile..r)"rcreaddecode ValueErrorstructunpacklistrerfranger\seekosSEEK_CURrgr4rRr6r2r3rXrSrTfindrUrVrWrhrirjrkrd enumeraterE)rrwZ ttisgmtcntZ ttisstdcntZleapcntZtimecntZtypecntZcharcntZttinfoirUrVrWgmtoffrTZabbrindttiZlastdstZ lastoffsetZ lastdstoffsetZlastbaseoffsetr6rXZ baseoffsetZ adjustmentr)rrrus                       ztzfile._read_tzfileFcCs6|js dSt|}|r|jn|j}t||}|dS)Nr) _trans_listrIZ_trans_list_utcbisect bisect_right)rrin_utcrLrdrrrr_find_last_transitions  ztzfile._find_last_transitioncCs8|dks|dt|jkr |jS|dkr.|jS|j|S)Nrr)lenr _ttinfo_stdZ_ttinfo_before _trans_idx)rrrrr _get_ttinfos ztzfile._get_ttinfocCs||}||S)N)_resolve_ambiguous_timer)rrrrrr _find_ttinfos ztzfile._find_ttinfocCsnt|tjstd|j|k r&td|j|dd}||}|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-)r)rM) rr2r0tzinforrrr3r6rr r9)rrrrZdt_outrMrrrrs   ztzfile.fromutccCsd|dkr||}t|}||}|dks4|dkr8dS||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)rrIrr6r)rrrrLrZodttrrrrs   ztzfile.is_ambiguouscCsF||}||}|dks$|dkr(|St| o:|||}||S)Nr)rrOr9r)rrrrOZ idx_offsetrrrr"s   ztzfile._resolve_ambiguous_timecCs"|dkr dS|jstS||jS)N)rrrrS)rrrrrr/s ztzfile.utcoffsetcCs0|dkr dS|jstS||}|js*tS|jS)N)Z _ttinfo_dstrrrTrX)rrrrrrr8s z tzfile.dstcCs|jr|dkrdS||jS)N)rrrU)rrrrrrHsz tzfile.tznamecCs2t|tstS|j|jko0|j|jko0|j|jkS)N)rrorrrZ _ttinfo_list)rr!rrrr"Ns    z tzfile.__eq__cCs ||k S)Nr)rr!rrrr#Wsz tzfile.__ne__cCsd|jjt|jfS)Nz%s(%s))r$r%r8rq)rrrrr&Zsztzfile.__repr__cCs |dS)N) __reduce_ex__)rrrrr,]sztzfile.__reduce__cCs|jd|jf|jfS)N)r$rq__dict__)rprotocolrrrr`sztzfile.__reduce_ex__)N)F)N)r%r'r(r)r7rvrurrrrrrrrrrr"r*r#r&r,rrQrr)r$rro|s(Fa  $    roc@s6eZdZdZd ddZddZddZed d ZdS) tzrangea[ 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 Nc Cs@ddlma||_||_y |}Wnttfk r<YnXy |}Wnttfk rbYnX|dk r|tj|d|_ nt |_ |dk rtj|d|_ n(|r|dk r|j tjdd|_ nt |_ |r|dkrtjdddt dd|_ n||_ |r|dkrtjdd d t d d|_n||_|j |j |_t|j |_dS) Nr) relativedelta)r-r)hoursr{)rmonthdayweekday r)dateutilr _std_abbr _dst_abbrr/r0r1r2r3r>rrASU _start_delta _end_delta_dst_base_offset_rChasdst)rstdabbr stdoffsetdstabbrrXstartendrrrr7s:     ztzrange.__init__cCs4|js dSt|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)rr2rr)ryearZ base_yearrrrrr transitionss   ztzrange.transitionscCsVt|tstS|j|jkoT|j|jkoT|j|jkoT|j|jkoT|j|jkoT|j|jkS)N) rrrrrr>rArr)rr!rrrr"s      ztzrange.__eq__cCs|jS)N)r)rrrr_dst_base_offsetsztzrange._dst_base_offset)NNNNN) r%r'r(r)r7rr"propertyrrrrrrdsJ - 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. .. caution:: Prior to version 2.7.0, this function also supported time zones in the format: * ``EST5EDT,4,0,6,7200,10,0,26,7200,3600`` * ``EST5EDT,4,1,0,7200,10,-1,0,7200,3600`` This format is non-standard and has been deprecated; this function will raise a :class:`DeprecatedTZFormatWarning` until support is removed in a future version. .. _`GNU C Library: TZ Variable`: https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html Fc Csddlma||_t|}|dks*|jr2td|jdkrN|sN|jd9_t j ||j|j|j |j ddd|j sd|_ d|_n&||j|_ |j r|j|jdd |_t|j |_dS) Nr)_parserzunknown string format)rPrrF)rrr)isend)Zdateutil.parserrparser_sZ_parsetzZany_unused_tokensrrrrr7rrXrr_deltarrrCr)rsZ posix_offsetresrrrr71s"   ztzstr.__init__rcCs:ddlm}i}|jdk rr|j|d<|jdk r`||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<|d|d<nd |d<d|d<|d |d<|j dk r|j |d <nd|d <|r.|j |j }|d |j |j d8<|jf|S)Nr)rrrrrrZyeardayZ nlyeardayr{rrr-i iQ)rrrrweekrZydayZjydayrr<rAr>r-days)rxrrrnrSrrrrQs<               z tzstr._deltacCsd|jjt|jfS)Nz%s(%s))r$r%r8r)rrrrr&zsztzstr.__repr__N)F)r)r%r'r(r)r7rr&rrrrrs* )rc@seZdZdddZdS)_tzicalvtzcompNcCs@tj|d|_tj|d|_|j|j|_||_||_||_dS)N)r-)r2r3 tzoffsetfrom tzoffsetto tzoffsetdiffrTrrrule)rrrrTrrrrrr7s z_tzicalvtzcomp.__init__)NN)r%r'r(r7rrrrr~srcsZeZdZgffdd ZddZddZddZd d Zed d Z d dZ e j Z Z S) _tzicalvtzcs4tt|||_||_g|_g|_t|_ dS)N) r;rr7_tzid_comps _cachedate _cachecompr allocate_lock _cache_lock)rtzidcomps)r$rrr7s z_tzicalvtz.__init__c Cs,t|jdkr|jdS|jdd}y.|j|j|j|||fSQRXWntk rfYnXd}d}x2|jD](}| ||}|rx|r||krx|}|}qxW|sx"|jD]}|j s|}PqW|d}|jP|j d|||f|j d|t|jdkr|j |j WdQRX|S)Nrr)rr) rrreplacerrrindexrOr _find_compdtrTinsertpop)rrZ lastcompdtZlastcompcompcompdtrrr _find_comps:       z_tzicalvtz._find_compcCs2|jtkr||r||j8}|jj|dd}|S)NT)inc)rrrOrbefore)rrrrrrrrs z_tzicalvtz._find_compdtcCs|dkr dS||jS)N)rr)rrrrrrsz_tzicalvtz.utcoffsetcCs||}|jr|jStSdS)N)rrTrr)rrrrrrrs z_tzicalvtz.dstcCs ||jS)N)rr)rrrrrrsz_tzicalvtz.tznamecCsdt|jS)Nz)r8r)rrrrr&sz_tzicalvtz.__repr__)r%r'r(r7rrrrrrr&r+r,rQrr)r$rrs - 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 5545`_ 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 5545`: https://tools.ietf.org/html/rfc5545 c Csjddlmat|tr(||_t|d}nt|dt||_t|}i|_ |}| | WdQRXdS)Nr)rrr5) rrrrrrrrNr8rt_vtz _parse_rfcr)rrwZfobjrrrr7s   ztzical.__init__cCst|jS)z? Retrieves the available time zones as a list. )rrkeys)rrrrrsz tzical.keysNcCsP|dkrDt|jdkr tdnt|jdkr6tdtt|j}|j|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)rrrnextiterrm)rrrrrrms z tzical.getcCs|}|std|ddkr>d|ddk}|dd}nd}t|dkrzt|ddd t|ddd |St|d krt|ddd t|ddd t|dd|Std |dS) Nz empty offsetr)+-)rrrrr{ri<r~zinvalid offset: )striprrr9)rrsignalrrr _parse_offsets  , <ztzical._parse_offsetcCsp|}|stdd}xh|t|kr||}|s>||=q|dkrv|ddkrv||d|dd7<||=q|d7}qWd}g}d}d}x|D]}|sq|dd\} } | d} | std| d} | dd} |rL| d kr&| d krn td | | }d} d} d}g}d}qh| d kr| d kr~|rLtd||sZtd|shtdt|||j|<d}n| |kr| std| dkrtd|dkrtdd}|rtj d |dddd}t | ||dk||}| |d}n td| qh|r | dkrZx(| D] }|dkr&d|}t|q&W| |d} n| dkrp| |n| dkr| rtd| | df| | } nj| dkr| rtd| d| | }n>| d kr| rtd!| d| }n| d"krn td#| n>| d$kr2| r,td%| d| }n| d&kr>n td#| q| d kr| d krd}g}d}qWdS)'Nz empty stringr rF:;zempty property nameZBEGIN)ZSTANDARDDAYLIGHTzunknown component: ZENDZ VTIMEZONEzcomponent not closed: zmandatory TZID not foundz at least one component is neededzmandatory DTSTART not foundz mandatory TZOFFSETFROM not found T) compatibleZignoretzcacherzinvalid component end: ZDTSTARTzVALUE=DATE-TIMEz(Unsupported DTSTART param in VTIMEZONE: )ZRRULEZRDATEZEXRULEZEXDATEZ TZOFFSETFROMzunsupported %s parm: %s Z TZOFFSETTOzunsupported TZOFFSETTO parm: ZTZNAMEzunsupported TZNAME parm: COMMENTzunsupported property: ZTZIDzunsupported TZID parm: )ZTZURLz LAST-MODIFIEDr) splitlinesrrrstripsplitupperrrrZrrulestrr]rr\r)rrlinesrlinerrZinvtzcomptyper5r_ZparmsZ founddtstartrrZ rrulelinesrZrrrZparmmsgrrrr,s                             ztzical._parse_rfccCsd|jjt|jfS)Nz%s(%s))r$r%r8r)rrrrr&sztzical.__repr__)N) r%r'r(r)r7rrmrrr&rrrrrs  }rwin32z/etc/localtimerJz/usr/share/zoneinfoz/usr/lib/zoneinfoz/usr/share/lib/zoneinfoz /etc/zoneinfocs2tftdk rtf7Gfdddt}|S)NcsDeZdZdZddZd fdd ZddZd d Zedd d Z dS)z__get_gettz..GettzFunca Retrieve a time zone object from a string representation This function is intended to retrieve the :py:class:`tzinfo` subclass that best represents the time zone that would be used if a POSIX `TZ variable`_ were set to the same value. If no argument or an empty string is passed to ``gettz``, local time is returned: .. code-block:: python3 >>> gettz() tzfile('/etc/localtime') This function is also the preferred way to map IANA tz database keys to :class:`tzfile` objects: .. code-block:: python3 >>> gettz('Pacific/Kiritimati') tzfile('/usr/share/zoneinfo/Pacific/Kiritimati') On Windows, the standard is extended to include the Windows-specific zone names provided by the operating system: .. code-block:: python3 >>> gettz('Egypt Standard Time') tzwin('Egypt Standard Time') Passing a GNU ``TZ`` style string time zone specification returns a :class:`tzstr` object: .. code-block:: python3 >>> gettz('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3') tzstr('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3') :param name: A time zone name (IANA, or, on Windows, Windows keys), location of a ``tzfile(5)`` zoneinfo file or ``TZ`` variable style time zone specifier. An empty string, no argument or ``None`` is interpreted as local time. :return: Returns an instance of one of ``dateutil``'s :py:class:`tzinfo` subclasses. .. versionchanged:: 2.7.0 After version 2.7.0, any two calls to ``gettz`` using the same input strings will return the same object: .. code-block:: python3 >>> tz.gettz('America/Chicago') is tz.gettz('America/Chicago') True In addition to improving performance, this ensures that `"same zone" semantics`_ are used for datetimes in the same zone. .. _`TZ variable`: https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html .. _`"same zone" semantics`: https://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html cSs&t|_d|_t|_t|_dS)Nr) weakrefWeakValueDictionary_GettzFunc__instances_GettzFunc__strong_cache_sizer_GettzFunc__strong_cacherrr)rrrrr7s z'__get_gettz..GettzFunc.__init__Nc s|j|j|d}|dkrT|j|d}|dksPt|sP|dksP||j|<n|S|j|||j|<t|j|jkr|jj ddWdQRX|S)N)r5F)last) rrrmnocacherrrrrpopitem)rr5rv)tzlocal_classesrr__call__ s   z'__get_gettz..GettzFunc.__call__c Ss>|j.||_x t|j|kr.|jjddqWWdQRXdS)NF)r)rrrrr)rsizerrrset_cache_size%sz-__get_gettz..GettzFunc.set_cache_sizec Ss*|jt|_|jWdQRXdS)N)rrrrrclear)rrrr cache_clear+s z*__get_gettz..GettzFunc.cache_clearc SsHd}|s,ytjd}Wntk r*YnX|dks<|dkrxtD]v}tj|s|}x*tD] }tj||}tj|r\Pq\WqBtj|rByt |}PWqBt t t fk rYqBXqBWt }n~|dr|dd}tj|r tj|rt |}nd}n:x6tD]l}tj||}tj|sP|dd}tj|sPqyt |}PWnt t t fk rzYnXqWd}tdk ry t|}Wnttfk rd}YnX|sddlm}||}|sDxb|D]6}|d kry t|}Wnt k rYnXPqW|d kr2t}n|tjkrDt }|S) zA non-cached version of gettzNZTZrrrrzr)get_zonefile_instance 0123456789)rPr)renvironKeyErrorTZFILESpathisabsTZPATHSr]isfileroIOErrorOSErrorrr: startswithrrZ WindowsErrorUnicodeEncodeErrorZdateutil.zoneinforrmrrr<r)r5tzfilepathrxrrcrrrr0sz                       z&__get_gettz..GettzFunc.nocache)N)N) r%r'r(r)r7r r r staticmethodrr)r rr GettzFuncsEr )r:rr+)r r)r r __get_gettzs  Cr!cCsZ|dkr |jdkrtd|j}|jdd}|j|dt|}|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``. .. versionadded:: 2.7.0 Nz,Datetime is naive and no time zone provided.)r)rrr astimezoner)rrZdt_rtrrrdatetime_existss   r#cCs|dkr |jdkrtd|j}t|dd}|dk rTy ||Stk rRYnX|j|d}t|dd}t|dd}||k}||k}|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)rMr) rrrNr Exceptionrr rr)rrZis_ambiguous_fnZwall_0Zwall_1Z same_offsetZsame_dstrrrdatetime_ambiguouss       r%cCsJ|jdk rFt|sF|tjdd}|tjdd}|||7}|S)aZ Given a datetime that may be imaginary, return an existing datetime. This function assumes that an imaginary datetime represents what the wall time would be in a zone had the offset transition not occurred, so it will always fall forward by the transition's change in offset. .. doctest:: >>> from dateutil import tz >>> from datetime import datetime >>> NYC = tz.gettz('America/New_York') >>> print(tz.resolve_imaginary(datetime(2017, 3, 12, 2, 30, tzinfo=NYC))) 2017-03-12 03:30:00-04:00 >>> KIR = tz.gettz('Pacific/Kiritimati') >>> print(tz.resolve_imaginary(datetime(1995, 1, 1, 12, 30, tzinfo=KIR))) 1995-01-02 12:30:00+14:00 As a note, :func:`datetime.astimezone` is guaranteed to produce a valid, existing datetime, so a round-trip to and from UTC is sufficient to get an extant datetime, however, this generally "falls back" to an earlier time rather than falling forward to the STD side (though no guarantees are made about this behavior). :param dt: A :class:`datetime.datetime` which may or may not exist. :return: Returns an existing :class:`datetime.datetime`. If ``dt`` was not imaginary, the datetime returned is guaranteed to be the same object passed to the function. .. versionadded:: 2.7.0 Nr})r)rr#r2r3r)rZ curr_offset old_offsetrrrresolve_imaginarys $ r'cCs|jddtS)z Convert a :class:`datetime.datetime` object to an epoch timestamp in seconds since January 1, 1970, ignoring the time zone. N)r)rEPOCHr/)rrrrrIsrI)r~cCs|S)Nr) second_offsetrrrr4 sr4cCs|}d|dd}|S)Nrr)r*r&Zcalculated_offsetrrrr4s) nullcontextc@s(eZdZdZddZddZddZdS) rtzj Class for wrapping contexts so that they are passed through in a with statement. cCs ||_dS)N)context)rr-rrrr7#sz_nullcontext.__init__cCs|jS)N)r-)rrrr __enter__&sz_nullcontext.__enter__cOsdS)Nr)argsrnrrr__exit__)sz_nullcontext.__exit__N)r%r'r(r)r7r.r0rrrrrtsrt)N)N)@r)r2rr<sysrrr collectionsrsixrZ six.movesrZ_commonrrrr r Z _factoriesr r r winrr ImportErrorwarningsrr3rutcfromtimestampr( toordinalZ EPOCHORDINAL add_metaclassrrrr:r+rRrcrorrrrrplatformrrr!Zgettzr#r%r'rI version_infor4contextmanagerr,rtrrrr s         T D- k#w VO K " ..