MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / _UTC

Function _UTC

tests/test_code/py/pytz/__init__.py:266–295  ·  view source on GitHub ↗

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 exa

()

Source from the content-addressed store, hash-verified

264
265
266def _UTC():
267 """Factory function for utc unpickling.
268
269 Makes sure that unpickling a utc instance always returns the same
270 module global.
271
272 These examples belong in the UTC class above, but it is obscured; or in
273 the README.rst, but we are not depending on Python 2.4 so integrating
274 the README.rst examples with the unit tests is not trivial.
275
276 >>> import datetime, pickle
277 >>> dt = datetime.datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc)
278 >>> naive = dt.replace(tzinfo=None)
279 >>> p = pickle.dumps(dt, 1)
280 >>> naive_p = pickle.dumps(naive, 1)
281 >>> len(p) - len(naive_p)
282 17
283 >>> new = pickle.loads(p)
284 >>> new == dt
285 True
286 >>> new is dt
287 False
288 >>> new.tzinfo is dt.tzinfo
289 True
290 >>> utc is UTC is timezone('UTC')
291 True
292 >>> utc is timezone('GMT')
293 False
294 """
295 return utc
296
297
298_UTC.__safe_for_unpickling__ = True

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected