o dE@sdZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z ddl mZmZmZddlmZmZdd lmZd efd d ZeZd ZeZeZgdZejddkrleZddZnddZddZ ddZ!iZ"ddZ#ddZ$da%ddZ&e'dZ(ej'ddZ)Gdd d eZ*e*Z*Z+d!d"Z,d#e,_-d$d%Z.d#e._-Gd&d'd'eZ/e/Z0Gd(d)d)eZ1e1Z2Gd*d+d+ej3Z4ifd,d-Z5d#e5_-d.d/Z6d e7efd0d1Z8e9d2kre6hd3Z:e;d4d5hZe<Z?e>e=Z@dS)6z datetime.tzinfo timezone definitions generated from the Olson timezone database: ftp://elsie.nci.nih.gov/pub/tz*.tar.gz See the datetime section of the Python Library Reference for information on how to use these modules. N)AmbiguousTimeError)InvalidTimeError)NonExistentTimeError)UnknownTimeZoneError)LazyDictLazyListLazySet) unpickler BaseTzInfo) build_tzinforeturncCs\td}|jdd }|}Wdn1swYtd|}|r,|dSdS)Nz/usr/share/zoneinfo/tzdata.ziutf-8encodingz^#\s*version\s*([0-9a-z]*)\s*$unknown)pathlibPathopenreadlinerematchgroup) tzdata_zitzdata_zi_filelinerr//usr/lib/python3/dist-packages/pytz/__init__.py_read_olson_versions    rz2022.1)timezoneutccountry_timezones country_namesrrrr all_timezonesall_timezones_setcommon_timezonescommon_timezones_setr FixedOffsetcCs(t|tkr |d}|S|d|S)z >>> ascii('Hello') 'Hello' >>> ascii('\N{TRADE MARK SIGN}') #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnicodeEncodeError: ... ASCII)typebytesdecodeencodesrrrascii<s  r0cCs |dS)a >>> ascii('Hello') 'Hello' >>> ascii(u'Hello') 'Hello' >>> ascii(u'\N{TRADE MARK SIGN}') #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnicodeEncodeError: ... r))r-r.rrrr0Ms cCs|dd}|D]}|tjjkstjj|vrtd|q tjdd}|dur5tjj |g|R}n1tjj dddg|R}tj |sfzdd l m }Wn t yZd}Ynw|durf|td |St|d S) a!Open a resource from the zoneinfo subdir for reading. Uses the pkg_resources module if available and no standard file found at the calculated location. It is possible to specify different location for zoneinfo subdir by using the PYTZ_TZDATADIR environment variable. /zBad path segment: %rPYTZ_TZDATADIRNz/usrsharezoneinfor)resource_streamz zoneinfo/rb)lstripsplitospathpardirsep ValueErrorenvirongetjoinexists pkg_resourcesr5 ImportError__name__r)name name_partspart zoneinfo_dirfilenamer5rrr open_resource[s,      rJcCs<ztjddr WdSt|WdStyYdSw)z(Return true if the given resource existsPYTZ_SKIPEXISTSCHECKTF)r9r>r?rJcloseIOError)rErrrresource_exists|s  rOcCs|durtd|dkrtSzt|}Wn ty!t|wtt|}|tvrN|tvrJt |}zt ||t|<W| t|S| wt|t|S)ao Return a datetime.tzinfo implementation for the given timezone >>> from datetime import datetime, timedelta >>> utc = timezone('UTC') >>> eastern = timezone('US/Eastern') >>> eastern.zone 'US/Eastern' >>> timezone(unicode('US/Eastern')) is eastern True >>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc) >>> loc_dt = utc_dt.astimezone(eastern) >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)' >>> loc_dt.strftime(fmt) '2002-10-27 01:00:00 EST (-0500)' >>> (loc_dt - timedelta(minutes=10)).strftime(fmt) '2002-10-27 00:50:00 EST (-0500)' >>> eastern.normalize(loc_dt - timedelta(minutes=10)).strftime(fmt) '2002-10-27 01:50:00 EDT (-0400)' >>> (loc_dt + timedelta(minutes=10)).strftime(fmt) '2002-10-27 01:10:00 EST (-0500)' Raises UnknownTimeZoneError if passed an unknown zone. >>> try: ... timezone('Asia/Shangri-La') ... except UnknownTimeZoneError: ... print('Unknown') Unknown >>> try: ... timezone(unicode('\N{TRADE MARK SIGN}')) ... except UnknownTimeZoneError: ... print('Unknown') Unknown NUTC) rupperr r0UnicodeEncodeError_case_insensitive_zone_lookup _unmunge_zone _tzinfo_cacher$rJr rM)zonefprrrrs(%     rcCs|ddddS)z?Undo the time zone name munging done by older versions of pytz._plus_+_minus_-)replacerVrrrrTsrTcCs,tdur tddtDat|p|S)z@case-insensitively matching timezone, else return zone unchangedNcss|] }||fVqdSN)lower).0tzrrr sz0_case_insensitive_zone_lookup..) _all_timezones_lower_to_standarddictr#r?r_r]rrrrSsrSr)hourscsteZdZdZdZeZeZeZfddZ ddZ ddZ dd Z d d Z dd dZdddZddZddZZS)rPzUTC Optimized UTC implementation. It unpickles using the single module global instance defined beneath this class declaration. cs&|jdur ||Sttj||Sr^)tzinfolocalizesuperr __class__fromutcselfdtrirrrjs  z UTC.fromutccCtSr^ZEROrkrrr utcoffsetz UTC.utcoffsetcCdSNrPrrkrrrtznamersz UTC.tznamecCror^rprkrrrdstrszUTC.dstcCstdfS)Nr)_UTCrlrrr __reduce__szUTC.__reduce__FcC|jdur td|j|dSz Convert naive time to local timeNz*Not naive datetime (tzinfo is already set))rfrfr=r\rlrmis_dstrrrrg  z UTC.localizecC*|j|ur|S|jdurtd||Sz6Correct the timezone information on the given datetimeNzNaive time - no tzinfo setrfr= astimezoner~rrr normalize   z UTC.normalizecCrt)Nzrryrrr__repr__ rsz UTC.__repr__cCrtrurryrrr__str__rsz UTC.__str__F)rD __module__ __qualname____doc__rVrq _utcoffset_dst_tznamerjrrrvrwrzrgrrr __classcell__rrrnrrPs   rPcCro)a*Factory function for utc unpickling. Makes sure that unpickling a utc instance always returns the same module global. These examples belong in the UTC class above, but it is obscured; or in the README.rst, but we are not depending on Python 2.4 so integrating the README.rst examples with the unit tests is not trivial. >>> import datetime, pickle >>> dt = datetime.datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc) >>> naive = dt.replace(tzinfo=None) >>> p = pickle.dumps(dt, 1) >>> naive_p = pickle.dumps(naive, 1) >>> len(p) - len(naive_p) 17 >>> new = pickle.loads(p) >>> new == dt True >>> new is dt False >>> new.tzinfo is dt.tzinfo True >>> utc is UTC is timezone('UTC') True >>> utc is timezone('GMT') False )r rrrrrxsrxTcGst|S)zFactory function for unpickling pytz tzinfo instances. Just a wrapper around tzinfo.unpickler to save a few bytes in each pickle by shortening the path. )r )argsrrr_p:src@s eZdZdZddZddZdS)_CountryTimezoneDictaMap ISO 3166 country code to a list of timezone names commonly used in that country. iso3166_code is the two letter code used to identify the country. >>> def print_list(list_of_strings): ... 'We use a helper so doctests work under Python 2.3 -> 3.x' ... for s in list_of_strings: ... print(s) >>> print_list(country_timezones['nz']) Pacific/Auckland Pacific/Chatham >>> print_list(country_timezones['ch']) Europe/Zurich >>> print_list(country_timezones['CH']) Europe/Zurich >>> print_list(country_timezones[unicode('ch')]) Europe/Zurich >>> print_list(country_timezones['XXX']) Traceback (most recent call last): ... KeyError: 'XXX' Previously, this information was exposed as a function rather than a dictionary. This is still supported:: >>> print_list(country_timezones('nz')) Pacific/Auckland Pacific/Chatham cCs||S)zBackwards compatibility.r)rl iso3166_coderrr__call__fsz_CountryTimezoneDict.__call__c Csi}td}zC|D]6}|d}|drq |dddd\}}}|tvr(q z |||Wq ty?|g||<Yq w||_W|dS|w)Nzzone.tabUTF-8#) rJr, startswithr8r$appendKeyErrordatarM)rlrzone_tabrcode coordinatesrVrrr_filljs"   z_CountryTimezoneDict._fillN)rDrrrrrrrrrrFs rc@seZdZdZddZdS)_CountryNameDictzgDictionary proving ISO3166 code -> English name. >>> print(country_names['au']) Australia cCsli}td}z*|D]}|d}|drq |dd\}}|||<q ||_W|dS|w)Nz iso3166.tabrrr)rJ readlinesr,rr8striprrM)rlrrrrrErrrrs   z_CountryNameDict._fillN)rDrrrrrrrrrs rc@sTeZdZdZddZddZddZdd Zd d Zd d Z dddZ dddZ dS) _FixedOffsetNcCs.t|dkr td|||_tj|d|_dS)Nizabsolute offset is too large)minutes)absr=_minutesdatetime timedelta_offset)rlrrrr__init__s  z_FixedOffset.__init__cCs|jSr^)rrkrrrrrsz_FixedOffset.utcoffsetcCs t|jffSr^)r'rryrrrrzs z_FixedOffset.__reduce__cCror^rprkrrrrwrsz_FixedOffset.dstcCsdSr^rrkrrrrvrsz_FixedOffset.tznamecCs d|jS)Nzpytz.FixedOffset(%d))rryrrrrs z_FixedOffset.__repr__FcCr{r|r}r~rrrrgrz_FixedOffset.localizecCrrrr~rrrrrz_FixedOffset.normalizer) rDrrrVrrrrzrwrvrrgrrrrrrs rcCs2|dkrtS||}|dur||t|}|S)areturn a fixed-offset timezone based off a number of minutes. >>> one = FixedOffset(-330) >>> one pytz.FixedOffset(-330) >>> str(one.utcoffset(datetime.datetime.now())) '-1 day, 18:30:00' >>> str(one.dst(datetime.datetime.now())) '0:00:00' >>> two = FixedOffset(1380) >>> two pytz.FixedOffset(1380) >>> str(two.utcoffset(datetime.datetime.now())) '23:00:00' >>> str(two.dst(datetime.datetime.now())) '0:00:00' The datetime.timedelta must be between the range of -1 and 1 day, non-inclusive. >>> FixedOffset(1440) Traceback (most recent call last): ... ValueError: ('absolute offset is too large', 1440) >>> FixedOffset(-1440) Traceback (most recent call last): ... ValueError: ('absolute offset is too large', -1440) An offset of 0 is special-cased to return UTC. >>> FixedOffset(0) is UTC True There should always be only one instance of a FixedOffset per timedelta. This should be true for multiple creation calls. >>> FixedOffset(-330) is one True >>> FixedOffset(1380) is two True It should also be true for pickling. >>> import pickle >>> pickle.loads(pickle.dumps(one)) is one True >>> pickle.loads(pickle.dumps(two)) is two True rN)rPr? setdefaultr)offset_tzinfosinforrrr's 5 r'cCs*ddl}tjdtjddl}||S)Nr)doctestsysr:insertr9r;pytztestmod)rrrrr_test s rcCsJt}td}|jddD]}|drq||ddq|S)Nz /usr/share/zoneinfo/zone1970.tabr rr r()setrr read_text splitlinesraddr8) timezonesrrrrr_read_timezones_from_zone_tabs  r__main__>z Asia/Aden US/Alaska US/Hawaii US/Arizona US/Central US/Eastern US/Pacific Africa/Lome Asia/Brunei Asia/Kuwait Asia/Muscat Europe/Oslo Indian/Mahe US/Mountain Africa/Accra Africa/Dakar Asia/Bahrain Europe/Vaduz Indian/Cocos Pacific/Wake Africa/Asmara Africa/Bamako Africa/Bangui Africa/Banjul Africa/Douala Africa/Harare Africa/Kigali Africa/Luanda Africa/Lusaka Africa/Malabo Africa/Maseru Africa/Niamey America/Aruba Europe/Jersey Europe/Monaco Europe/Skopje Europe/Zagreb Indian/Comoro Pacific/ChuukAfrica/ConakryAfrica/KampalaAfrica/MbabaneAmerica/CaymanAmerica/NassauAsia/VientianeCanada/CentralCanada/EasternCanada/PacificEurope/VaticanIndian/MayotteIndian/ReunionPacific/MajuroPacific/MidwayPacific/SaipanPacific/WallisAfrica/BlantyreAfrica/DjiboutiAfrica/FreetownAfrica/GaboroneAfrica/KinshasaAmerica/AntiguaAmerica/CrestonAmerica/CuracaoAmerica/GrenadaAmerica/MarigotAmerica/TortolaAsia/Phnom_PenhCanada/AtlanticCanada/MountainEurope/BusingenEurope/GuernseyEurope/SarajevoPacific/PohnpeiAfrica/BujumburaAfrica/MogadishuAmerica/AnguillaAmerica/AtikokanAmerica/DominicaAmerica/St_KittsAmerica/St_LuciaAntarctica/SyowaEurope/AmsterdamEurope/LjubljanaEurope/MariehamnEurope/PodgoricaEurope/StockholmIndian/ChristmasIndian/KerguelenPacific/FunafutiAfrica/LibrevilleAfrica/LubumbashiAfrica/NouakchottAfrica/Porto-NovoAmerica/St_ThomasAntarctica/VostokAsia/Kuala_LumpurEurope/BratislavaEurope/CopenhagenEurope/LuxembourgEurope/San_MarinoAfrica/Addis_AbabaAfrica/BrazzavilleAfrica/OuagadougouAmerica/GuadeloupeAmerica/KralendijkAmerica/MontserratAmerica/St_VincentAntarctica/McMurdoAtlantic/ReykjavikAtlantic/St_HelenaEurope/Isle_of_ManArctic/LongyearbyenCanada/NewfoundlandIndian/AntananarivoAfrica/Dar_es_SalaamAmerica/Blanc-SablonAmerica/Lower_PrincesAmerica/Port_of_SpainAmerica/St_BarthelemyAntarctica/DumontDUrvilleGMTrPFactory localtime)Arrros.pathr9rrr4pytz.exceptionsrrrr pytz.lazyrrr pytz.tzinfor r pytz.tzfiler strr OLSON_VERSIONVERSION __version__ OLSEN_VERSION__all__ version_infounicoder0rJrOrUrrTrcrSrrqHOURrPr rx__safe_for_unpickling__rrr!rr"rfrr'rrrrD_extra_common_timezones_setavailable_timezonesr$r&sortedr#r%rrrrsn         !?   2  8 (C |