zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
U
¥ý°dHKã@sêdZddlmZmZmZddlmZzeWn ek
rLddlm    ZYnXddl
Z
ddl m Z m Z gZiZdd„Ze d¡ZdeiZd    d
„ZiZd d „ZedƒZd d„ZGdd„deƒZGdd„deƒZGdd„deƒZddd„ZdS)zBBase classes and helpers for building zone specific tzinfo classesé)ÚdatetimeÚ    timedeltaÚtzinfo)Ú bisect_right)ÚSetN)ÚAmbiguousTimeErrorÚNonExistentTimeErrorcCs:z
t|WStk
r4t|d}|t|<|YSXdS)z3Create only one instance of each distinct timedelta©ÚsecondsN)Ú_timedelta_cacheÚKeyErrorr)r
Údelta©rúBd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pytz/tzinfo.pyÚmemorized_timedeltas 
 
rcCs>z
t|WStk
r8tt|d}|t|<|YSXdS)z2Create only one instance of each distinct datetimer    N)Ú_datetime_cacher Ú_epochr)r
ÚdtrrrÚmemorized_datetimes 
rcGsNz
t|WStk
rHt|dƒt|dƒ|df}|t|<|YSXdS)z/Create only one instance of each distinct tuplerééN)Ú _ttinfo_cacher r)ÚargsZttinforrrÚmemorized_ttinfo-s
 
 
ýrcCs|j|jdddS)zConvert a timedelta to secondséé<)r
Údays)ÚtdrrrÚ _to_seconds=src@s eZdZdZdZdZdd„ZdS)Ú
BaseTzInfoNcCs|jS©N©Úzone©ÚselfrrrÚ__str__HszBaseTzInfo.__str__)Ú__name__Ú
__module__Ú __qualname__Ú
_utcoffsetÚ_tznamer"r%rrrrrBsrc@sZeZdZdZdd„Zddd„Zddd„Zdd    d
„Zdd d „Zddd„Z    dd„Z
dd„Z dS)Ú StaticTzInfoz¡A timezone that has a constant offset from UTC
 
    These timezones are rare, as most locations have changed their
    offset at some point in their history
    cCs.|jdk    r|j|k    rtdƒ‚||jj|dS)úSee datetime.tzinfo.fromutcNúfromutc: dt.tzinfo is not self©r)rÚ
ValueErrorr)Úreplace)r$rrrrÚfromutcRszStaticTzInfo.fromutcNcCs|jS)z“See datetime.tzinfo.utcoffset
 
        is_dst is ignored for StaticTzInfo, and exists only to
        retain compatibility with DstTzInfo.
        )r)©r$rÚis_dstrrrÚ    utcoffsetXszStaticTzInfo.utcoffsetcCstS)zSee datetime.tzinfo.dst
 
        is_dst is ignored for StaticTzInfo, and exists only to
        retain compatibility with DstTzInfo.
        )Ú_notimer2rrrÚdst`szStaticTzInfo.dstcCs|jS)zSee datetime.tzinfo.tzname
 
        is_dst is ignored for StaticTzInfo, and exists only to
        retain compatibility with DstTzInfo.
        )r*r2rrrÚtznamehszStaticTzInfo.tznameFcCs|jdk    rtdƒ‚|j|dS)z Convert naive time to local timeNú*Not naive datetime (tzinfo is already set)r.)rr/r0r2rrrÚlocalizeps
zStaticTzInfo.localizecCs*|j|kr|S|jdkr tdƒ‚| |¡S)aCorrect the timezone information on the given datetime.
 
        This is normally a no-op, as StaticTzInfo timezones never have
        ambiguous cases to correct:
 
        >>> from pytz import timezone
        >>> gmt = timezone('GMT')
        >>> isinstance(gmt, StaticTzInfo)
        True
        >>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
        >>> gmt.normalize(dt) is dt
        True
 
        The supported method of converting between timezones is to use
        datetime.astimezone(). Currently normalize() also works:
 
        >>> la = timezone('America/Los_Angeles')
        >>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
        >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
        >>> gmt.normalize(dt).strftime(fmt)
        '2011-05-07 08:02:03 GMT (+0000)'
        NúNaive time - no tzinfo set)rr/Ú
astimezoner2rrrÚ    normalizevs
 
 
zStaticTzInfo.normalizecCs d|jfS)Nz<StaticTzInfo %r>r!r#rrrÚ__repr__“szStaticTzInfo.__repr__cCstj|jffSr )ÚpytzÚ_pr"r#rrrÚ
__reduce__–szStaticTzInfo.__reduce__)N)N)N)F)F) r&r'r(Ú__doc__r1r4r6r7r9r<r=r@rrrrr+Ls
 
 
 
 
r+c@sveZdZdZdZdZdZdZdZddd„Z    dd„Z
dd„Z dd
d „Z dd d „Z ddd„Zddd„Zdd„Zdd„ZdS)Ú    DstTzInfozÙA timezone that has a variable offset from UTC
 
    The offset might change if daylight saving time comes into effect,
    or at a point in history when the region decides to change their
    timezone definition.
    NcCsz|r||_|\|_|_|_nZi}||_|jd\|_|_|_|||jd<|jdd…D]}||krX| ||¡||<qXdS)Nrr)Ú_tzinfosr)Ú_dstr*Ú_transition_infoÚ    __class__)r$Ú_infrCÚinfrrrÚ__init__³sÿzDstTzInfo.__init__cCsl|jdk    r&t|jddƒ|jk    r&tdƒ‚|jdd}tdt|j|ƒdƒ}|j|}||dj|j|dS)r,NrCr-r.rr)    rÚgetattrrCr/r0ÚmaxrÚ_utc_transition_timesrE)r$rÚidxrHrrrr1Ás
ÿ 
zDstTzInfo.fromutccCs8|jdkrtdƒ‚|jj}|jdd}||}| |¡S)aICorrect the timezone information on the given datetime
 
        If date arithmetic crosses DST boundaries, the tzinfo
        is not magically adjusted. This method normalizes the
        tzinfo to the correct one.
 
        To test, first we need to do some setup
 
        >>> from pytz import timezone
        >>> utc = timezone('UTC')
        >>> eastern = timezone('US/Eastern')
        >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
 
        We next create a datetime right on an end-of-DST transition point,
        the instant when the wallclocks are wound back one hour.
 
        >>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
        >>> loc_dt = utc_dt.astimezone(eastern)
        >>> loc_dt.strftime(fmt)
        '2002-10-27 01:00:00 EST (-0500)'
 
        Now, if we subtract a few minutes from it, note that the timezone
        information has not changed.
 
        >>> before = loc_dt - timedelta(minutes=10)
        >>> before.strftime(fmt)
        '2002-10-27 00:50:00 EST (-0500)'
 
        But we can fix that by calling the normalize method
 
        >>> before = eastern.normalize(before)
        >>> before.strftime(fmt)
        '2002-10-27 01:50:00 EDT (-0400)'
 
        The supported method of converting between timezones is to use
        datetime.astimezone(). Currently, normalize() also works:
 
        >>> th = timezone('Asia/Bangkok')
        >>> am = timezone('Europe/Amsterdam')
        >>> dt = th.localize(datetime(2011, 5, 7, 1, 2, 3))
        >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
        >>> am.normalize(dt).strftime(fmt)
        '2011-05-06 20:02:03 CEST (+0200)'
        Nr:r.)rr/r)r0r1)r$rÚoffsetrrrr<Ës -
 zDstTzInfo.normalizeFc s¬|jdk    rtdƒ‚tƒ}tddtddfD]b}||}tdt|j|ƒdƒ}|j|}|j|}|     |j
|d¡}|j
dd|kr,|  |¡q,t |ƒdkr¤|  ¡St |ƒdkr ˆdkrÄt|ƒ‚nHˆrê|j|tdd    d
d tdd    S|j|tdd    d d tdd    Sˆdkrt|ƒ‚‡fd d„|Dƒ}    t |    ƒdkrF|    dSt |    ƒdkr\t|ƒ}    i}
|    D]0} | j
dd| jj} | |
ksŠt‚| |
| <qd|
ttgˆ |
ƒS)aèConvert naive time to local time.
 
        This method should be used to construct localtimes, rather
        than passing a tzinfo argument to a datetime constructor.
 
        is_dst is used to determine the correct timezone in the ambigous
        period at the end of daylight saving time.
 
        >>> from pytz import timezone
        >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
        >>> amdam = timezone('Europe/Amsterdam')
        >>> dt  = datetime(2004, 10, 31, 2, 0, 0)
        >>> loc_dt1 = amdam.localize(dt, is_dst=True)
        >>> loc_dt2 = amdam.localize(dt, is_dst=False)
        >>> loc_dt1.strftime(fmt)
        '2004-10-31 02:00:00 CEST (+0200)'
        >>> loc_dt2.strftime(fmt)
        '2004-10-31 02:00:00 CET (+0100)'
        >>> str(loc_dt2 - loc_dt1)
        '1:00:00'
 
        Use is_dst=None to raise an AmbiguousTimeError for ambiguous
        times at the end of daylight saving time
 
        >>> try:
        ...     loc_dt1 = amdam.localize(dt, is_dst=None)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous
 
        is_dst defaults to False
 
        >>> amdam.localize(dt) == amdam.localize(dt, False)
        True
 
        is_dst is also used to determine the correct timezone in the
        wallclock times jumped over at the start of daylight saving time.
 
        >>> pacific = timezone('US/Pacific')
        >>> dt = datetime(2008, 3, 9, 2, 0, 0)
        >>> ploc_dt1 = pacific.localize(dt, is_dst=True)
        >>> ploc_dt2 = pacific.localize(dt, is_dst=False)
        >>> ploc_dt1.strftime(fmt)
        '2008-03-09 02:00:00 PDT (-0700)'
        >>> ploc_dt2.strftime(fmt)
        '2008-03-09 02:00:00 PST (-0800)'
        >>> str(ploc_dt2 - ploc_dt1)
        '1:00:00'
 
        Use is_dst=None to raise a NonExistentTimeError for these skipped
        times.
 
        >>> try:
        ...     loc_dt1 = pacific.localize(dt, is_dst=None)
        ... except NonExistentTimeError:
        ...     print('Non-existent')
        Non-existent
        Nr8éÿÿÿÿ)rrrr.é)ÚhoursT©r3Fcs g|]}t|jjƒˆkr|‘qSr)ÚboolrrD)Ú.0ÚprRrrÚ
<listcomp>osz&DstTzInfo.localize.<locals>.<listcomp>)rr/ÚsetrrKrrLrErCr<r0ÚaddÚlenÚpoprr9rÚlistr)ÚAssertionErrorÚmin) r$rr3Zpossible_loc_dtr Zloc_dtrMrHrZfiltered_possible_loc_dtÚdatesZlocal_dtZutc_timerrRrr9sd;
ÿÿ
 
 
 ÿÿ þþ    
 
ÿ ÿ zDstTzInfo.localizecCs4|dkr dS|j|k    r*| ||¡}|jjS|jSdS)aLSee datetime.tzinfo.utcoffset
 
        The is_dst parameter may be used to remove ambiguity during DST
        transitions.
 
        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')
        >>> ambiguous = datetime(2009, 10, 31, 23, 30)
 
        >>> str(tz.utcoffset(ambiguous, is_dst=False))
        '-1 day, 20:30:00'
 
        >>> str(tz.utcoffset(ambiguous, is_dst=True))
        '-1 day, 21:30:00'
 
        >>> try:
        ...     tz.utcoffset(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous
 
        N)rr9r)r2rrrr4Œs 
 zDstTzInfo.utcoffsetcCs4|dkr dS|j|k    r*| ||¡}|jjS|jSdS)aþSee datetime.tzinfo.dst
 
        The is_dst parameter may be used to remove ambiguity during DST
        transitions.
 
        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')
 
        >>> normal = datetime(2009, 9, 1)
 
        >>> str(tz.dst(normal))
        '1:00:00'
        >>> str(tz.dst(normal, is_dst=False))
        '1:00:00'
        >>> str(tz.dst(normal, is_dst=True))
        '1:00:00'
 
        >>> ambiguous = datetime(2009, 10, 31, 23, 30)
 
        >>> str(tz.dst(ambiguous, is_dst=False))
        '0:00:00'
        >>> str(tz.dst(ambiguous, is_dst=True))
        '1:00:00'
        >>> try:
        ...     tz.dst(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous
 
        N)rr9rDr2rrrr6«s 
 z DstTzInfo.dstcCs6|dkr|jS|j|k    r,| ||¡}|jjS|jSdS)aåSee datetime.tzinfo.tzname
 
        The is_dst parameter may be used to remove ambiguity during DST
        transitions.
 
        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')
 
        >>> normal = datetime(2009, 9, 1)
 
        >>> tz.tzname(normal)
        'NDT'
        >>> tz.tzname(normal, is_dst=False)
        'NDT'
        >>> tz.tzname(normal, is_dst=True)
        'NDT'
 
        >>> ambiguous = datetime(2009, 10, 31, 23, 30)
 
        >>> tz.tzname(ambiguous, is_dst=False)
        'NST'
        >>> tz.tzname(ambiguous, is_dst=True)
        'NDT'
        >>> try:
        ...     tz.tzname(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous
        N)r"rr9r*r2rrrr7Òs 
 zDstTzInfo.tznamecCsJ|jr d}nd}|jtkr0d|j|j|j|fSd|j|j|j|fSdS)NZDSTZSTDz<DstTzInfo %r %s+%s %s>z<DstTzInfo %r %s%s %s>)rDr)r5r"r*)r$r6rrrr=øs 
ÿÿzDstTzInfo.__repr__cCs"tj|jt|jƒt|jƒ|jffSr )r>r?r"rr)rDr*r#rrrr@s üzDstTzInfo.__reduce__)NN)F)N)N)N)r&r'r(rArLrEr"rCrDrIr1r<r9r4r6r7r=r@rrrrrBœs     
 
7

 
'
&rBcCs¢t |¡}|dkr|St|ƒ}t|ƒ}z|j|||fWStk
rLYnX|j ¡D] }|j|krX|j|krX|SqX|||f}| ||j¡|j|<|j|S)a%Factory function for unpickling pytz tzinfo instances.
 
    This is shared for both StaticTzInfo and DstTzInfo instances, because
    database changes could cause a zones implementation to switch between
    these two base classes and we can't break pickles on a pytz version
    upgrade.
    N)    r>ÚtimezonerrCr Úvaluesr)rDrF)r"r4Z    dstoffsetr7ÚtzZ localized_tzrHrrrÚ    unpicklers"
 
 
ÿ
 
rb)NNN)rArrrÚbisectrrWÚ    NameErrorZsetsrr>Zpytz.exceptionsrrÚ__all__r rÚutcfromtimestamprrrrrr5rrr+rBrbrrrrÚ<module>s0     
 
Pw