diff options
author | Paul Ganssle <paul@ganssle.io> | 2019-02-03 10:17:23 -0500 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2019-02-03 12:26:40 -0500 |
commit | 82fc863aa62b624318fbc6e2945bc5d8e3b030d2 (patch) | |
tree | f638fea03cf284c4af31a5b1bceb0963b0124770 /dateutil | |
parent | ee819bf84929cb24a549398a7b753f07f1ce4904 (diff) | |
download | dateutil-82fc863aa62b624318fbc6e2945bc5d8e3b030d2.tar.gz |
Catch UnicodeEncodeError for Windows in tz.gettz
On Windows and Python 2.7, calling `tzwin` with a non-ascii name will
raise a UnicodeEncodeError instead of WindowsError, as it does on other
platforms and versions.
Fixes GH #802.
Diffstat (limited to 'dateutil')
-rw-r--r-- | dateutil/test/test_tz.py | 2 | ||||
-rw-r--r-- | dateutil/tz/tz.py | 3 |
2 files changed, 2 insertions, 3 deletions
diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py index 386b909..bb0f4b7 100644 --- a/dateutil/test/test_tz.py +++ b/dateutil/test/test_tz.py @@ -1095,8 +1095,6 @@ def test_gettz_badzone(badzone): @pytest.mark.gettz -@pytest.mark.xfail(IS_WIN and PY2, - reason='tzwin fails with non-unicode characters on 2.7') def test_gettz_badzone_unicode(): # Make sure a unicode string can be passed to TZ (GH #802) # When fixed, combine this with test_gettz_badzone diff --git a/dateutil/tz/tz.py b/dateutil/tz/tz.py index 161f4d8..d05414e 100644 --- a/dateutil/tz/tz.py +++ b/dateutil/tz/tz.py @@ -1633,7 +1633,8 @@ def __get_gettz(): if tzwin is not None: try: tz = tzwin(name) - except WindowsError: + except (WindowsError, UnicodeEncodeError): + # UnicodeEncodeError is for Python 2.7 compat tz = None if not tz: |