r4idZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl Z ddl m Z ddl m Z ddlmZmZddlmZmZdd lmZdd lmZmZdd lmZ dd lmZmZdd lmZej<dZejdddddZ e jCZ"e jFeGddejHZ%e%Z&e jFeGddejHZ'GddeZ(Gdde)Z*Gdde)Z+GddeZ,GddeZ-e jFeGdde-Z.Gdd e)Z/Gd!d"eZ0Gd#d$e)Z1ejdd%k7r d&d'gZ3gd(Z4ngZ3gZ4d)Z5e5Z6[5d4d*Z7d4d+Z8d,Z9d-Z:ejvd.k\rd/ZZ?y#e$rdxZZYpwxYw#e$rGd2d3e)Z?YywxYw)5a 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)warnicpeZdZdZdZdZedZdZe dZ dZ dZ d Z d Zej Zy) 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 ctSNZEROselfdts Z/mnt/ssd/data/python-lab/DaemonControl/venv/lib/python3.12/site-packages/dateutil/tz/tz.py utcoffsetztzutc.utcoffsetJ ctSrrrs rdstz tzutc.dstMrrcy)NUTCrs rtznamez tzutc.tznamePsrcy)6 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#rs r is_ambiguousztzutc.is_ambiguousTsrc|S)z Fast track version of fromutc() returns the original ``dt`` object for any valid :py:class:`datetime.datetime` object. r#rs rfromutcz tzutc.fromutcds  rct|ttfstSt|txs%t|txr|jt k(Sr) isinstancertzoffsetNotImplemented_offsetrrothers r__eq__z tzutc.__eq__lsE%%!23! !5%(HE8,F$1F IrNc||k( Srr#r/s r__ne__z tzutc.__ne__uEM""rc4d|jjzSNz%s() __class____name__rs r__repr__ztzutc.__repr__x////r)r9 __module__ __qualname____doc__rr rr$r'r r)r1__hash__r3r;object __reduce__r#rrrr)sb> IH#0""JrrcveZdZdZdZdZdZedZe dZ dZ dZ d Z d Zd Zej"Zy ) r,a1 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||_ |j}t j t ||_y#ttf$rY6wxYwNseconds)_name total_seconds TypeErrorAttributeErrordatetime timedelta_get_supported_offsetr.)rnameoffsets r__init__ztzoffset.__init__sO  ))+F ))2G2OP >*   s>AAc|jSrr.rs rrztzoffset.utcoffsets ||rctSrrrs rr z tzoffset.dstrrc|jSr)rHrs rr$ztzoffset.tznames zzrc ||jzSrrSrs rr)ztzoffset.fromutcsDLL  rcy)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#rs rr'ztzoffset.is_ambiguoussrc`t|tstS|j|jk(Sr)r+r,r-r.r/s rr1ztzoffset.__eq__s%%*! !||u}},,rNc||k( Srr#r/s rr3ztzoffset.__ne__r4rc|jjdt|jdt |j j dS)N(, ))r8r9reprrHintr.rIr:s rr;ztzoffset.__repr__s<#~~66#DJJ/"4<<#=#=#?@B Br)r9r=r>r?rQrr rr$r r)r'r1r@r3r;rArBr#rrr,r,sh Q!! - H#B ""Jrr,ceZdZdZfdZdZdZedZdZ dZ d dZ d Z d Z d Zd Zej"ZxZS)tzlocalzR A :class:`tzinfo` subclass built around the ``time`` timezone functions. ctt| tjt j |_t jr+tjt j |_ n|j|_ |j|jz |_ t|j|_ tt j|_yrE)superrarQrLrMtimetimezone _std_offsetdaylightaltzone _dst_offset _dst_savedbool_hasdsttupler$_tznames)rr8s rrQztzlocal.__init__s gt%'#--t}}nE =='114<<-HD #//D **T-=-==DOO, dkk* rcr| |jry|j|r |jS|jSr)rl_isdstrirfrs rrztzlocal.utcoffsets3 :$,, ;;r?## ### #rc| |jry|j|r|j|jz StSr)rlrprirfrrs rr z tzlocal.dsts7 :$,, ;;r?##d&6&66 6Krc>|j|j|Sr)rnrprs rr$ztzlocal.tznames}}T[[_--rcp|j|}| xr!||j||jz k7S)r&) _naive_is_dstrj)rr naive_dsts rr'ztzlocal.is_ambiguoussA&&r*  Hd00doo1EFF Ircxt|}tj|tjzjSr)_datetime_to_timestamprd localtimeretm_isdst)rr timestamps rrtztzlocal._naive_is_dsts**2. ~~i$--78AAArc|jsy|j|}t|dd}|j|r||j | Sy|S)NFfoldT)rlrtgetattrr'_fold)rr fold_naivedstvalr|s rrpztzlocal._isdsts[2||##B'r64(   R ::b>)) rct|tr4|j|jk(xr|j|jk(St|tr5|j xr&|j ddvxr|jtk(St|trF|j xr7|j d|jk(xr|j|jk(StS)Nr>GMTr") r+rarfrirrlrnrr,rHr.r-r/s rr1ztzlocal.__eq__.s eW %$$(9(99:$$(9(99 ; u % $-MM!$6-$$, .x ( $6MM!$ 36$$ 5 7" !rNc||k( Srr#r/s rr3ztzlocal.__ne__?r4rc4d|jjzSr6r7r:s rr;ztzlocal.__repr__Br<r)T)r9r=r>r?rQrr rr$r'rtrpr1r@r3r;rArB __classcell__r8s@rraras` +$..I$B&P "H#0""Jrrac<eZdZgdZdZdZdZdZdZdZ dZ y) _ttinfo)rPdeltaisdstabbrisstdisgmt dstoffsetc@|jD]}t||dyr __slots__setattr)rattrs rrQz_ttinfo.__init__Ls!NN &D D$ % &rcg}|jD]0}t||}||j|dt|2|jj ddj |dS)N=r[r\r])rr}appendr^r8r9join)rlrvalues rr;z_ttinfo.__repr__Ps` NN 8DD$'E D$u+67 8 >>22DIIaLAArct|tstS|j|jk(xr|j|jk(xr|j |j k(xrj|j |j k(xrO|j|jk(xr4|j|jk(xr|j|jk(Sr) r+rr-rPrrrrrrr/s rr1z_ttinfo.__eq__Xs%)! ! u||+2 ekk)2 ekk)2 UZZ'2 ekk) 2  ekk) 2 %//1  3rNc||k( Srr#r/s rr3z_ttinfo.__ne__fr4rcLi}|jD]}t||d||<|Sr)rr}rstaterOs r __getstate__z_ttinfo.__getstate__is1NN 4D!$d3E$K 4 rcP|jD]}||vst||||yrrrs r __setstate__z_ttinfo.__setstate__os,NN 1Du}dE$K0 1r) r9r=r>rrQr;r1r@r3rrr#rrrrHs/0I&B 3H# 1rrceZdZdZgdZdZy)_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_firstc `|jD]}t|||j|d!yr)attrsrget)rkwargsrs rrQz_tzfile.__init__}s,JJ 8D D$ 4 6 7 8rN)r9r=r>r?rrQr#rrrrus JE8rrceZdZdZdfd ZdZdZddZdZdZ d Z dd Z d Z d Z d ZedZdZdZdZdZdZdZxZS)tzfilea This is a ``tzinfo`` subclass that 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|tt| d}t|tr||_t |d}d}n8|||_n.t|dr|j|_nt||_|;|s t|}|5}|j|}ddd|jyy#1swYxYw)NFrbTrO) rcrrQr+r _filenameopenhasattrrOr^ _nullcontext _read_tzfile _set_tzdata)rfileobjfilenamefile_opened_here file_streamtzobjr8s rrQztzfile.__init__s fd$&  g| ,$DN7D)G#   !%DN Wf %$\\DN!']DN  #&w/ 7K))+6 7   U #  7 7s B22B;c btjD]}t|d|zt||y)z= Set the time zone data of this object from a _tzfile object _N)rrrr})rrrs rrztzfile._set_tzdatas.MM j|j| |ztC|j|_tC|j>|_tC|j|_|Scc}w)NTZifzmagic not foundz>6lz>%dlz>%dBz>lbbz>%dbrrFr)"rreaddecode ValueErrorstructunpacklistrrrangerseekosSEEK_CURrrNrrPrLrMrrrfindrrrrrrrr enumeraterm)rrout ttisgmtcnt ttisstdcntleapcnttimecnttypecntcharcntttinfoirrrgmtoffrabbrindttiidxlastdst lastoffset lastdstoffsetlastbaseoffsetrPr baseoffset adjustments rrztzfile._read_tzfilesi <<? ! ! #v -./ / R2 MM%b!1 2/       !%fmmFW4D4;LL4K'M"NC "$C  "MM&7*:*1,,w*?ACMCMw BA MM&-- Q@ A B||G$++-  LL1bkk 2 MM&:"5"),,z":?CH#a9E!HMCI#a9E!HMCI OO " "3 ' (:=G#-G   ??%%47OOA4FF!1wqy"b1 8A--*C>>#))), ^^ ),~~#.. 8~~cnn),??;C99,/); ),(:C%   . FFAsZZFI"99"$*Z$7 $$1 $,$6$6y$ICM$-M )+J#J*z^/K W,+ iiGJ'N NN ! !#"4"4Q"7*"D E? FBcmm, s~~."3#5#56 gHs0Tc|jsyt|}|r |jn |j}tj||}|dz S)Nr) _trans_listrw_trans_list_utcbisect bisect_right)rrin_utcrzrrs r_find_last_transitionztzfile._find_last_transitionsL*2. .4T))9I9I !!*i8Qwrc||dzt|jk\r |jS|dkr |jS|j|S)Nrr)lenr _ttinfo_std_ttinfo_before _trans_idx)rrs r _get_ttinfoztzfile._get_ttinfosM ;37s4+;+;'<<## # 7&& &s##rcF|j|}|j|Sr)_resolve_ambiguous_timer)rrrs r _find_ttinfoztzfile._find_ttinfos#**2.$$rc^t|tjs td|j|ur t d|j |d}|j |}|tj|jz}|j||}t|t|S)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)rrF)rr|) r+rLrJtzinforrrrMrPr'r r_)rrrrdt_outr|s rr)ztzfile.fromutcs("h//0DE E 99D 45 5((D(9s#h((<<  S 1f3t9--rc||j|}t|}|j|}||dkry|j|dz j|jz }|j|}|||zkS)r&rFr)rrwrrPr)rrrrzrodtts rr'ztzfile.is_ambiguous s ;,,R0C+2. s# ;#(   cAg & - - :   c "27""rc|j|}|j|}||dk(r|St| xr|j||}||z S)Nr)rr~r_r')rrrr~ idx_offsets rrztzfile._resolve_ambiguous_time(s\((, 2 ;#(JUAt'8'8S'AB Zrcb|y|jstS|j|jSr)rrrrrs rrztzfile.utcoffset5s/ :K  $***rc|y|jstS|j|}|jstS|jSr) _ttinfo_dstrrrr)rrrs rr z tzfile.dst>s@ :K#yyK}}rcV|jr|y|j|jSr)rrrrs rr$z tzfile.tznameNs)2:  $)))rct|tstS|j|jk(xr4|j|jk(xr|j |j k(Sr)r+rr-rr _ttinfo_listr/s rr1z tzfile.__eq__Ts[%(! !  E$5$5585#3#338!!U%7%77 9rc||k( Srr#r/s rr3z tzfile.__ne__]r4rc`|jjdt|jdSNr[r])r8r9r^rr:s rr;ztzfile.__repr__`s >>22D4HIIrc$|jdSr) __reduce_ex__r:s rrBztzfile.__reduce__cs!!$''rcL|jd|jf|jfSr)r8r__dict__)rprotocols rr ztzfile.__reduce_ex__fs t~~ 6 FFrrF)r9r=r>r?rQrrrrrr)r'rrr rr$r1r@r3r;rBr rrs@rrrszEN$0< ^@  $% ".H#:  + ** 9H#J(Grrc:eZdZdZ ddZdZdZedZy)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*ddlma||_||_ |j } |j }|tj||_ n t|_ |tj||_ n8|r+|)|jtjdz|_ n t|_ |r4|2tjdddtjd|_ n||_ |r4|2tjdd d tjd |_n||_|j|jz |_t!|j|_y#t t f$rYUwxYw#t t f$rYZwxYw) Nr relativedeltarFrhoursr)rmonthdayweekday r)dateutilr _std_abbr _dst_abbrrIrJrKrLrMrfrriSU _start_delta _end_delta_dst_base_offset_rkhasdst)rstdabbr stdoffsetdstabbrrstartends rrQztzrange.__init__s| +   !//1I !//1I  '11)DD #D   '11)DD  .#//(2D2D22NND #D  u} - ; ;q-2B2B22F!<!HD !&D  s{+99M4D4DR4H:JDO"DO!%!1!1D4D4D!D4,,- C>*    >*   s"E)E?)E<;E<?FFc|jsytj|dd}||jz}||jz}||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)r%rLr"r#)ryear base_yearr)r*s r transitionsztzrange.transitionssJ{{%%dAq1 D---$//)s|rcnt|tstS|j|jk(xr|j|jk(xrj|j |j k(xrO|j |j k(xr4|j|jk(xr|j|jk(Sr) r+rr-rr rfrir"r#r/s rr1ztzrange.__eq__s%)! !%//14%//14  E$5$554  E$5$554!!U%7%77 4 5#3#33  5rc|jSr)r$r:s r_dst_base_offsetztzrange._dst_base_offsets%%%r)NNNNN) r9r=r>r?rQr.r1propertyr1r#rrrrjs8IT+/)-!%-.^0 5&&rrc&eZdZdZddZddZdZy)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 c Rddlma||_tj |}| |j r t d|jdvr|s|xjdzc_tj||j|j|j|jdd|jsd|_ d|_nN|j|j |_ |jr"|j|j"d |_t%|j|_y) Nr)_parserzunknown string formatrr"rF)r)r*r)isend)dateutil.parserr6parser_s_parsetzany_unused_tokensrr&r'rrQr(rr"r#_deltar)r*rkr%)rs posix_offsetress rrQztzstr.__init__7s5ooa  ;#//45 5 ;;. ( MMR M s{{CMMcmm$%  1{{ $D "DO $ CII 6D   "&++cggQ+"?4,,- rcddlm}i}|j{|j|d<|jD|j|j|j|d<|jdkDrd|d<nYd|d<nS|j rG|j |d<n7|j |j |d<n|j|j|d <|s?|sd |d<d|d<|jd|d<nd |d<d|d<|jd |d<|j|j|d <nd|d <|r@|j|jz }|d xx|j|jdzzzcc<|jdi|S)Nrrrrrrryearday nlyeardayrrrrGi iQr#)rrrrweekrydayjydayr!rdrirfrGdays)rxr8rrrs rr>z tzstr._deltaWsx* 77 ggF7Oyy$$1$9$9!))QVV$Ly!66A:$%F5M$&F5M !u VV  !F9  WW "#''F; "#w !u $1$4$4R$8y!"$w "u $1$4$4R$8y! 66  !F9 !%F9  $$t'7'77E 9 e1C!C C *}**4V44rc`|jjdt|jdSr r8r9r^r;r:s rr;ztzstr.__repr__>>22DMBBrNr)r)r9r=r>r?rQr>r;r#rrr4r4 s(R.@'5RCrr4ceZdZ ddZy)_tzicalvtzcompNctj||_tj||_|j|jz |_||_||_||_yrE)rLrM tzoffsetfrom tzoffsetto tzoffsetdiffrr$rrule)rrPrQrr$rSs rrQz_tzicalvtzcomp.__init__sS$..|D",,Z@ OOd.?.??   r)NN)r9r=r>rQr#rrrNrNs $(rrNcheZdZgffd ZdZdZdZdZedZ dZ e jZ xZ S) _tzicalvtzctt| ||_||_g|_g|_tj|_ yr) rcrUrQ_tzid_comps _cachedate _cachecompr allocate_lock _cache_lock)rtzidcompsr8s rrQz_tzicalvtz.__init__s= j$(*  "002rczt|jdk(r|jdS|jd} |j5|j|j j ||j|fcdddS#1swYnxYwn#t$rYnwxYwd}d}|jD]#}|j||}|s|r||ks |}|}%|s&|jD]}|jr|}nd}|j5|j jd||j|f|jjd|t|j dkDr4|j j|jjddd|S#1swY|SxYw)Nrrrr) rrXreplacer\rZrYindexr~r _find_compdtrinsertpop)rr lastcompdtlastcompcompcompdts r _find_compz_tzicalvtz._find_comps t{{ q ;;q> ! ZZtZ $ !! +t'<'<B((*+ + + + +    KK D&&tR0FzZ&-@#      #zz#H #  7    & OO " "1r4::b>&: ; OO " "1h /4??#b(##%##%  & &s6 B9B  B BB B#"B#BF00F:c|jtkr |j|r||jz}|jj |d}|S)NT)inc)rRrr~rSbefore)rrhrris rrcz_tzicalvtz._find_compdtsH   t # 2 $## #B""24"0 rc>|y|j|jSr)rjrQrs rrz_tzicalvtz.utcoffsets :r"---rc`|j|}|jr |jStSr)rjrrRr)rrrhs rr z_tzicalvtz.dsts(r" ::$$ $Krc8|j|jSr)rjr$rs rr$z_tzicalvtz.tznamesr")))rc2dt|jzS)Nz)r^rWr:s rr;z_tzicalvtz.__repr__s$tzz"222r)r9r=r>rQrjrcrr rr$r;rArBrrs@rrUrUsF#%3+Z. **3""JrrUc6eZdZdZdZdZd dZdZdZdZ y) 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 cddlmat|tr||_t |d}n&t |dt||_t|}i|_ |5}|j|jdddy#1swYyxYw)Nr)rSrrO) rrSr+rr;rr}r^r_vtz _parse_rfcr)rrfobjs rrQztzical.__init__ss" g| ,DG7C(GgvtG}=DG"7+G  ) OODIIK ( ) ) )s  BB cHt|jjS)z? Retrieves the available time zones as a list. )rrvkeysr:s rrzz tzical.keyssDIINN$%%rNc|dt|jdk(r tdt|jdkDr tdtt |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. rzno timezones definedrz more than one timezone available)rrvrnextiterr)rr]s rrz tzical.getsf$ <499~" !788TYY!# !CDDTYY(Dyy}}T""rcz|j}|s td|ddvrd|ddk(}|dd}nd}t|dk(r&t|ddd zt|ddd zz|zSt|d k(r5t|ddd zt|ddd zzt|ddz|zStd |z) Nz empty offsetr)+-)rrrrrri<rzinvalid offset: )striprrr_)rr?signals r _parse_offsetztzical._parse_offset"s GGI^, , Q4: adck*F!"AF q6Q;"1J%AabE R76A A Vq["1J%AaF b(883qu:EO O/!34 4rc|j}|s tdd}|t|krQ||j}|s||=n)|dkDr|ddk(r||dz xx|ddz cc<||=n|dz }|t|krQd}g}d}d}|D]t}|s|j dd\} } | j d} | s td| dj } | dd} |r | d k(r | d vrntd | z| }d} d} d}g}d}z| d k(r| d k(rF|rtd|z|s td|s tdt |||j|<d}| |k(rz s td td tdd}r(tjdj|ddd}t| ||dk(|}|j|d}Itd| z|r| dk(r1| D]}|dk7s d|z}t|j|d} | dvrj|| dk(r*| rtd| d| dd|j| } | dk(r&| rtd | dz|j| }| d!k(r| rtd"| dz| }| d#k(r#td$| z| d%k(r| rtd&| dz| }M| d'vrStd$| z| d k(sh| d k(sod}g}d}wy)(Nz empty stringr rF:;zempty property nameBEGIN)STANDARDDAYLIGHTzunknown component: END VTIMEZONEzcomponent not closed: zmandatory TZID not foundz at least one component is neededzmandatory DTSTART not foundz mandatory TZOFFSETFROM not found T) compatibleignoretzcacherzinvalid component end: DTSTARTzVALUE=DATE-TIMEz(Unsupported DTSTART param in VTIMEZONE: )RRULERDATEEXRULEEXDATE TZOFFSETFROMz unsupported z parm: TZOFFSETTOzunsupported TZOFFSETTO parm: TZNAMEzunsupported TZNAME parm: COMMENTzunsupported property: TZIDzunsupported TZID parm: )TZURLz LAST-MODIFIEDr) splitlinesrrrstripsplitupperrUrvrSrrulestrrrNrr)rr?linesrliner]r^invtzcomptyperOrparms founddtstartrPrQ rrulelinesr$rrrhparmmsgs rrwztzical._parse_rfc2s ^, , #e*n8??$D!HQ47c>ac d12h& !HQ#e*nf D**S!,KD%JJsOE !6778>>#D!"IE7? 88()>u)DEE$H#(L#'L!%J!#J!FU] +#",-Eh-N"OO#",-G"HH$", B#DD+5T5*A $ %(*+",-J"KK'/", B#DD%-", B#DD"%!& *0E;?9=6:"0"BE!H M#OO'+'9'9%'@ - ", ?a H#JJ%)%7%7%> ) ", ;E!H D#FF!&*()A$)FGGv~ ", 9%( B#DD$!FF()A$)FGGUk%9Mf rc`|jjdt|jdSr rKr:s rr;ztzical.__repr__rLrr) r9r=r>r?rQrzrrrwr;r#rrrsrss( )"& #65 {zCrrswin32z/etc/localtimerx)z/usr/share/zoneinfoz/usr/lib/zoneinfoz/usr/share/lib/zoneinfoz /etc/zoneinfocbtft tfz Gfddt}|S)NcBeZdZdZdZdfd ZdZdZeddZ y) __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 ctj|_d|_t |_t j|_y)Nr) weakrefWeakValueDictionary_GettzFunc__instances_GettzFunc__strong_cache_sizer_GettzFunc__strong_cacherr[r\r:s rrQz'__get_gettz..GettzFunc.__init__ s6&::.GettzFunc.__call__s!! <%%))$5:40B L)"o>!z24((. "# < <&-1,?,?,C,CD",M##D)t**+d.F.FF''//U/;- <0I1 <0IsAC*A'CC%c|j5||_t|j|kDr5|jj dt|j|kDr5dddy#1swYyxYw)NFr)r\rrrr)rsizes rset_cache_sizez-__get_gettz..GettzFunc.set_cache_size+sg!! <+/($--.5''//U/;$--.5 < < .GettzFunc.cache_clear1sC!! ,#*#>#>#@ ##))+ , , ,s 4A  Acd}|s tjd}||dvrtD]}tjj |sO|}t D]C}tjj||}tjj|sCnqtjj|s t|}|St}|S |jdr|dd}tjj |r0tjj|r t|}|Sd}|St D]}tjj||}tjj|s2|j)dd}tjj|st t|}|Sd}t* t+|}|sd d lm}|j5|}|sB|D]}|d vs t7|}|S|d vrt8}|S|t:j<vr t}|S#t$rY-wxYw#tttf$rY}t!|t"r"d}t%j&t||nYd}~d}~wwxYw#tttf$rYwxYw#t,t.f$rd}YwxYw#t$rY|SwxYw) zA non-cached version of gettzNTZ)rrrz'gettz argument should be str, not bytesrrr)get_zonefile_instance 0123456789r7)renvironKeyErrorTZFILESpathisabsTZPATHSrisfilerIOErrorOSErrorrra startswithrJr+bytessix raise_fromrar WindowsErrorUnicodeEncodeErrordateutil.zoneinforrr4r"rdr$) rOtzfilepathrrenew_msgrcs rrz&__get_gettz..GettzFunc.nocache6sB::d+D|ty0 '#H77==2#+$+%D')ww||D('CH!ww~~h7 %% %ww~~h/!!'!1B!|IU# !BtIqs+#ABx77==&ww~~d+#D\ZIW"VIS!((3#%77<<d#;!ww~~h7'/'7'7S'AH#%77>>(#; (!!'!1B!BIS(3" ,*%*4[ "O!6!8!#9),BI&*T[[%8)0BI[  !(*=! !!!$."Ky'91=>*!(*=! !%12D#E*%)*",6%-(,$) I%-sqH:7 I I%3 J/ K  K": II I"!I"% J,.3J''J,/KK KK" K0/K0r) r9r=r>r?rQrrr staticmethodr)rsr GettzFuncrs4D J 7 6 <  , S  S rr)rarrA)rrs @r __get_gettzrs5jOJ=(GFGR ;rc|#|j td|j}|jd}|j|jtj|}|jd}||k(S)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 N,Datetime is naive and no time zone provided.r`)rrra astimezoner")rrdt_rts rdatetime_existsrsz& z 99 KL L YY 4 B JJbJ ! , ,S 1 < >> 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 rr)rrrLrMr)r curr_offset old_offsets rresolve_imaginaryrsfH yy_R%8H..R88CCE 8--B77BBD  kJ&& IrcP|jdtz jS)z Convert a :class:`datetime.datetime` object to an epoch timestamp in seconds since January 1, 1970, ignoring the time zone. Nr`)raEPOCHrI)rs rrwrws# JJdJ #e + : : <r?rQrrr#rrrr+s  #  rrr)@r?rLrrdsysrrr collectionsrrr six.movesr_commonrrr r r _factoriesr r rwinrr ImportErrorwarningsrrMrr toordinal EPOCHORDINAL add_metaclassrrr"r,rarArrrrr4rNrUrsplatformrrrgettzrrrrw version_inforN contextlibrrr#rrrs> # /(-6%& x!$1a+ < Q#HOOQ#!Q#n g#$A#xA#%A#H|#g|#~*1f*1Z 8f 8eGWeGP_&k_&D=!tCGtC"tCnVS#S#lKCVKC\<<7-G G GGNb  D+*\+\=v!6W8EJX8  v  s$G?G GGG)(G)