summaryrefslogtreecommitdiff
path: root/babel/localtime
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2013-07-06 13:45:57 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2013-07-06 13:45:57 +0200
commitebdcccff93df0d8d413d7a1f58736f15206ac2e4 (patch)
tree4fb7c8ffbbfd2cf9ce987e72d4c341086c8c20b8 /babel/localtime
parentd42286129c30420ad60558214773e270d2907b6c (diff)
downloadbabel-ebdcccff93df0d8d413d7a1f58736f15206ac2e4.tar.gz
Added fallback support for local timezones
Diffstat (limited to 'babel/localtime')
-rw-r--r--babel/localtime/__init__.py6
-rw-r--r--babel/localtime/_win32.py6
2 files changed, 10 insertions, 2 deletions
diff --git a/babel/localtime/__init__.py b/babel/localtime/__init__.py
index e2a45d5..842a03e 100644
--- a/babel/localtime/__init__.py
+++ b/babel/localtime/__init__.py
@@ -49,6 +49,7 @@ class _FallbackLocalTimezone(tzinfo):
tt = time.localtime(stamp)
return tt.tm_isdst > 0
+
def get_localzone():
"""Returns the current underlying local timezone object.
Generally this function does not need to be used, it's a
@@ -57,4 +58,7 @@ def get_localzone():
return _get_localzone()
-LOCALTZ = get_localzone()
+try:
+ LOCALTZ = get_localzone()
+except pytz.UnknownTimeZoneError:
+ LOCALTZ = _FallbackLocalTimezone()
diff --git a/babel/localtime/_win32.py b/babel/localtime/_win32.py
index 1636240..1f6ecc7 100644
--- a/babel/localtime/_win32.py
+++ b/babel/localtime/_win32.py
@@ -10,7 +10,7 @@ from babel.core import get_global
import pytz
-tznames = get_global('windows_zone_mapping')
+tz_names = get_global('windows_zone_mapping')
def valuestodict(key):
@@ -22,6 +22,7 @@ def valuestodict(key):
dict[data[0]] = data[1]
return dict
+
def get_localzone_name():
# Windows is special. It has unique time zone names (in several
# meanings of the word) available, but unfortunately, they can be
@@ -82,4 +83,7 @@ def get_localzone_name():
def _get_localzone():
+ if winreg is None:
+ raise pytz.UnknownTimeZoneError(
+ 'Runtime support not available')
return pytz.timezone(get_localzone_name())