dbfdg 3 +e58@sdZdZdZeZeZddddddd d d d d dg ZddlZddlZddlZ ddl Z ddl m Z ddl m Z ddl mZddl mZddlmZmZmZddlmZddlmZmZyeWn ek reZddZYn XddZe jdpdZeje j r eddIZddZ!d d!Z"iZ#d"dZ$d#d$Z%ej&dZ'ej&dd%Z(Gd&d'd'ej)Z*e*Z*Z+d(d)Z,d*e,_-d+d,Z.d*e._-Gd-d.d.eZ/e/Z0Gd/d0d0eZ1e1Z2Gd1d2d2ej)Z3ifd3d4Z4d*e4_-d5d6Z5e6d7kre5gZ7xTe j8eD]F\Z9Z:Z;x$dJD]Zd:d;e;DqWede@e jAjBed?DZCeCj>d@dAdBdCdDdEdFdGd'g edHd;eCDZCeeCZDdS)Kz 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. Z2017bz2017.2timezoneutccountry_timezones country_namesAmbiguousTimeErrorInvalidTimeErrorNonExistentTimeErrorUnknownTimeZoneError all_timezonesall_timezones_setcommon_timezonescommon_timezones_setN)r)r)r)r)LazyDictLazyListLazySet) unpickler) build_tzinfo _byte_stringcCs|jd|S)z >>> ascii('Hello') 'Hello' >>> ascii('\N{TRADE MARK SIGN}') #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnicodeEncodeError: ... ASCII)encode)sr/usr/lib/python3.6/__init__.pyascii.s rcCs |jdS)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)rrrrr<s ZTZDIRz/usr/share/zoneinfocCs^|jdjd}x0|D](}|tjjks2tjj|krtd|qWtjjtf|}t |dS)zOpen a resource from the zoneinfo subdir for reading. Uses the pkg_resources module if available and no standard file found at the calculated location. /zBad path segment: %rrb) lstripsplitospathpardirsep ValueErrorjoin _tzinfo_diropen)nameZ name_partspartfilenamerrr open_resourceMs  r*c Cs*yt|jdStk r$dSXdS)z(Return true if the given resource existsTFN)r*closeIOError)r'rrrresource_exists[s  r-cCs|jdkrtSy t|}Wntk r8t|YnXt|}|tkr|tkrzt|}zt ||t|<Wd|j Xnt|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 UTCN) upperrrUnicodeEncodeErrorr _unmunge_zone _tzinfo_cacher r*rr+)zonefprrrrus%   cCs|jddjddS)z?Undo the time zone name munging done by older versions of pytz.Z_plus_+Z_minus_-)replace)r3rrrr1sr1)ZhourscsteZdZdZdZeZeZeZfddZ ddZ ddZ dd Z d d Z dd dZdddZddZddZZS)r.zUTC Optimized UTC implementation. It unpickles using the single module global instance defined beneath this class declaration. cs&|jdkr|j|Sttj|j|S)N)tzinfolocalizesuperr __class__fromutc)selfdt)r;rrr<s  z UTC.fromutccCstS)N)ZERO)r=r>rrr utcoffsetsz UTC.utcoffsetcCsdS)Nr.r)r=r>rrrtznamesz UTC.tznamecCstS)N)r?)r=r>rrrdstszUTC.dstcCstffS)N)_UTC)r=rrr __reduce__szUTC.__reduce__FcCs|jdk rtd|j|dS)z Convert naive time to local timeNz*Not naive datetime (tzinfo is already set))r8)r8r#r7)r=r>is_dstrrrr9s z UTC.localizecCs*|j|kr|S|jdkr td|j|S)z6Correct the timezone information on the given datetimeNzNaive time - no tzinfo set)r8r# astimezone)r=r>rErrr normalizes   z UTC.normalizecCsdS)Nzr)r=rrr__repr__sz UTC.__repr__cCsdS)Nr.r)r=rrr__str__sz UTC.__str__)F)F)__name__ __module__ __qualname____doc__r3r?Z _utcoffsetZ_dstZ_tznamer<r@rArBrDr9rGrHrI __classcell__rr)r;rr.s   r.cCstS)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.txt, but we are not depending on Python 2.4 so integrating the README.txt 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 )rrrrrrCsrCTcGst|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_psrPc@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)r=Z iso3166_coderrr__call__;sz_CountryTimezoneDict.__call__cCsi}td}zxx|D]p}|jd}|jdr.q|jdddd\}}}|tkrRqy||j|Wqtk r|g||<YqXqW||_Wd|jXdS)Nzzone.tabzUTF-8#) r*decode startswithrr appendKeyErrordatar+)r=rZzone_tablinecodeZ coordinatesr3rrr_fill?s     z_CountryTimezoneDict._fillN)rJrKrLrMrRr^rrrrrQsrQc@seZdZdZddZdS)_CountryNameDictzgDictionary proving ISO3166 code -> English name. >>> print(country_names['au']) Australia c Csji}td}zNxB|jD]6}|jd}|jdr2q|jdd\}}|j||<qW||_Wd|jXdS)Nz iso3166.tabzUTF-8rSr)r* readlinesrVrWrstriprZr+)r=rZr[r\r]r'rrrr^[s   z_CountryNameDict._fillN)rJrKrLrMr^rrrrr_Usr_c@sTeZdZdZddZddZddZdd Zd d Zd d Z dddZ dddZ dS) _FixedOffsetNcCs.t|dkrtd|||_tj|d|_dS)Nizabsolute offset is too large)minutes)absr#_minutesdatetime timedelta_offset)r=rcrrr__init__rs  z_FixedOffset.__init__cCs|jS)N)rh)r=r>rrrr@xsz_FixedOffset.utcoffsetcCs t|jffS)N) FixedOffsetre)r=rrrrD{sz_FixedOffset.__reduce__cCstS)N)r?)r=r>rrrrB~sz_FixedOffset.dstcCsdS)Nr)r=r>rrrrAsz_FixedOffset.tznamecCs d|jS)Nzpytz.FixedOffset(%d))re)r=rrrrHsz_FixedOffset.__repr__FcCs|jdk rtd|j|dS)z Convert naive time to local timeNz*Not naive datetime (tzinfo is already set))r8)r8r#r7)r=r>rErrrr9s z_FixedOffset.localizecCs*|j|kr|S|jdkr td|j|S)z6Correct the timezone information on the given datetimeNzNaive time - no tzinfo set)r8r#rF)r=r>rErrrrGs   z_FixedOffset.normalize)F)F) rJrKrLr3rir@rDrBrArHr9rGrrrrrbns rbcCs2|dkr tS|j|}|dkr.|j|t|}|S)areturn a fixed-offset timezone based off a number of minutes. >>> one = FixedOffset(-330) >>> one pytz.FixedOffset(-330) >>> one.utcoffset(datetime.datetime.now()) datetime.timedelta(-1, 66600) >>> one.dst(datetime.datetime.now()) datetime.timedelta(0) >>> two = FixedOffset(1380) >>> two pytz.FixedOffset(1380) >>> two.utcoffset(datetime.datetime.now()) datetime.timedelta(0, 82800) >>> two.dst(datetime.datetime.now()) datetime.timedelta(0) 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 r N)r.get setdefaultrb)offsetZ_tzinfosinforrrrjs 5 rjcCs:ddl}ddl}ddl}|jjd|jddl}|j|S)Nr )doctestrsysr insertr!pytzZtestmod)rorrprrrrr_testsrs__main__posixrightccsD|]<}|dkr|dkrd|krtjjt|ttddVqdS)ZREADMEZTheory.rN)rr r$rootlenr%).0Ztz_filerrr sr{ccs|]}t|r|VqdS)N)r-)rztzrrrr{scCs,g|]$}|dkr|ddkr|jdqS)r rS)r)rzlrrr srzzone.tabZGMTz US/Alaskaz US/Arizonaz US/Centralz US/Easternz US/Hawaiiz US/Mountainz US/Pacificccs|]}|tkr|VqdS)N)r )rzr|rrrr{s)rurv)ErMZ OLSON_VERSIONVERSION __version__Z OLSEN_VERSION__all__rprfZos.pathrgettextZpytz.exceptionsrrrrZ pytz.lazyrrrZ pytz.tzinforZ pytz.tzfilerrZunicode NameErrorstrrgetenvr%endswithr"r*r-r2rr1rgr?ZHOURr8r.rrCZ__safe_for_unpickling__rPrQrr_rrbrjrsrJr walkrxdirsfilesexcludeindexextendr r&r r$r r rrrr s        <  2 7( B