mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-16 18:00:04 +00:00
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
|
"""
|
||
|
Common utilities that have been ported to Python 3.
|
||
|
|
||
|
Ported to Python 3.
|
||
|
"""
|
||
|
|
||
|
from __future__ import unicode_literals
|
||
|
from __future__ import absolute_import
|
||
|
from __future__ import division
|
||
|
from __future__ import print_function
|
||
|
|
||
|
from future.utils import PY2
|
||
|
if PY2:
|
||
|
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401
|
||
|
|
||
|
import os
|
||
|
import time
|
||
|
|
||
|
|
||
|
class TimezoneMixin(object):
|
||
|
|
||
|
def setTimezone(self, timezone):
|
||
|
def tzset_if_possible():
|
||
|
# Windows doesn't have time.tzset().
|
||
|
if hasattr(time, 'tzset'):
|
||
|
time.tzset()
|
||
|
|
||
|
unset = object()
|
||
|
originalTimezone = os.environ.get('TZ', unset)
|
||
|
def restoreTimezone():
|
||
|
if originalTimezone is unset:
|
||
|
del os.environ['TZ']
|
||
|
else:
|
||
|
os.environ['TZ'] = originalTimezone
|
||
|
tzset_if_possible()
|
||
|
|
||
|
os.environ['TZ'] = timezone
|
||
|
self.addCleanup(restoreTimezone)
|
||
|
tzset_if_possible()
|
||
|
|
||
|
def have_working_tzset(self):
|
||
|
return hasattr(time, 'tzset')
|