Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid KeyError trying to get data on WindowsXP #604

Merged
merged 1 commit into from
Dec 18, 2018
Merged

Avoid KeyError trying to get data on WindowsXP #604

merged 1 commit into from
Dec 18, 2018

Conversation

mondeja
Copy link
Contributor

@mondeja mondeja commented Oct 13, 2018

I've found this issue trying to compile documentation with Sphinx on WindowsXP with make html command. Some data dictionaries are void on my machine, so using lazy 'get' on those can prevent next KeyError:

C:\Path\to\my\project\doc>make html
{'MapID': '8,9', 'Index': 165, 'Std': 'Hora estándar árabe', 'Display': '(GMT+04
:00) Abu Dhabi, Muscat', 'TZI': b'\x10\xff\xff\xff\x00\x00\x00\x00\xc4\xff\xff\x
ff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano árab
e'}
{'MapID': '-1,71', 'Index': 158, 'Std': 'Hora estándar árabe D', 'Display': '(GM
T+03:00) Baghdad', 'TZI': b'L\xff\xff\xff\x00\x00\x00\x00\xc4\xff\xff\xff\x00\x0
0\n\x00\x00\x00\x01\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\
x01\x00\x03\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano árabe'}
{'MapID': '12,13', 'Index': 195, 'Std': 'Hora estándar de Asia C.', 'Display': '
(GMT+06:00) Astana, Dhaka', 'TZI': b'\x98\xfe\xff\xff\x00\x00\x00\x00\xc4\xff\xf
f\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano d
e Asia C.'}
{}
Traceback (most recent call last):
  File "c:\python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\sphinx-build.exe\__main__.py", line 5, in <module>
  File "c:\python34\lib\site-packages\sphinx\cmd\build.py", line 25, in <module>

    from sphinx.application import Sphinx
  File "c:\python34\lib\site-packages\sphinx\application.py", line 29, in <modul
e>
    from sphinx.config import Config, check_unicode
  File "c:\python34\lib\site-packages\sphinx\config.py", line 28, in <module>
    from sphinx.util.i18n import format_date
  File "c:\python34\lib\site-packages\sphinx\util\i18n.py", line 20, in <module>

    import babel.dates
  File "c:\python34\lib\site-packages\babel\dates.py", line 29, in <module>
    from babel.util import UTC, LOCALTZ
  File "c:\python34\lib\site-packages\babel\util.py", line 19, in <module>
    from babel import localtime
  File "c:\python34\lib\site-packages\babel\localtime\__init__.py", line 74, in
<module>
    LOCALTZ = get_localzone()
  File "c:\python34\lib\site-packages\babel\localtime\__init__.py", line 70, in
get_localzone
    return _get_localzone()
  File "c:\python34\lib\site-packages\babel\localtime\_win32.py", line 97, in _g
et_localzone
    return pytz.timezone(get_localzone_name())
  File "c:\python34\lib\site-packages\babel\localtime\_win32.py", line 70, in ge
t_localzone_name
    if data['Std'] == tzwin:
KeyError: 'Std'

I've found this issue trying to compile documentation with Sphinx on WindowsXP with `make html` command. Some data dictionaries are void on my machine, so using lazy 'get' on those can prevent next `KeyError`:

```
C:\Path\to\my\project\doc>make html
{'MapID': '8,9', 'Index': 165, 'Std': 'Hora estándar árabe', 'Display': '(GMT+04
:00) Abu Dhabi, Muscat', 'TZI': b'\x10\xff\xff\xff\x00\x00\x00\x00\xc4\xff\xff\x
ff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano árab
e'}
{'MapID': '-1,71', 'Index': 158, 'Std': 'Hora estándar árabe D', 'Display': '(GM
T+03:00) Baghdad', 'TZI': b'L\xff\xff\xff\x00\x00\x00\x00\xc4\xff\xff\xff\x00\x0
0\n\x00\x00\x00\x01\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\
x01\x00\x03\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano árabe'}
{'MapID': '12,13', 'Index': 195, 'Std': 'Hora estándar de Asia C.', 'Display': '
(GMT+06:00) Astana, Dhaka', 'TZI': b'\x98\xfe\xff\xff\x00\x00\x00\x00\xc4\xff\xf
f\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano d
e Asia C.'}
{}
Traceback (most recent call last):
  File "c:\python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\sphinx-build.exe\__main__.py", line 5, in <module>
  File "c:\python34\lib\site-packages\sphinx\cmd\build.py", line 25, in <module>

    from sphinx.application import Sphinx
  File "c:\python34\lib\site-packages\sphinx\application.py", line 29, in <modul
e>
    from sphinx.config import Config, check_unicode
  File "c:\python34\lib\site-packages\sphinx\config.py", line 28, in <module>
    from sphinx.util.i18n import format_date
  File "c:\python34\lib\site-packages\sphinx\util\i18n.py", line 20, in <module>

    import babel.dates
  File "c:\python34\lib\site-packages\babel\dates.py", line 29, in <module>
    from babel.util import UTC, LOCALTZ
  File "c:\python34\lib\site-packages\babel\util.py", line 19, in <module>
    from babel import localtime
  File "c:\python34\lib\site-packages\babel\localtime\__init__.py", line 74, in
<module>
    LOCALTZ = get_localzone()
  File "c:\python34\lib\site-packages\babel\localtime\__init__.py", line 70, in
get_localzone
    return _get_localzone()
  File "c:\python34\lib\site-packages\babel\localtime\_win32.py", line 97, in _g
et_localzone
    return pytz.timezone(get_localzone_name())
  File "c:\python34\lib\site-packages\babel\localtime\_win32.py", line 70, in ge
t_localzone_name
    if data['Std'] == tzwin:
KeyError: 'Std'
```
@codecov-io
Copy link

codecov-io commented Oct 13, 2018

Codecov Report

Merging #604 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #604   +/-   ##
=======================================
  Coverage   90.31%   90.31%           
=======================================
  Files          24       24           
  Lines        4128     4128           
=======================================
  Hits         3728     3728           
  Misses        400      400
Impacted Files Coverage Δ
babel/localtime/_win32.py 62.96% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2cf189...bb6eb0c. Read the comment docs.

Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good patch (though Windows XP has been EOL for a while now).

@mondeja
Copy link
Contributor Author

mondeja commented Oct 13, 2018

I know, I don't use it to work usually, only was a small fix to make it work on my parents' PC.

@akx akx merged commit b7dda2a into python-babel:master Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants