/etc/timezone parsing doesn't deal with comments properly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-tzlocal (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
On my system, /etc/timezone is 2 lines, one comment, then a timezone definition:
# Ansible managed: /nfs/users/
Europe/London
pytz's _get_localzone code doesn't parse this correctly, resulting in pytz.exceptions
this is because the code first splits on the first space, and then splits the result on the # character (resulting in an empty string); I demonstrate it here by copying the logic from unix.py ll56 et seq:
>>> with open("/
... data = tzfile.read()
... etctz = data.strip(
... print("'%s'" % etctz)
... if ' ' in etctz:
... a = etctz.split(' ', 1)
... print(a)
... if '#' in a[0]:
... b=a[0].split('#', 1)
... print(b)
...
'# Ansible managed: /nfs/users/
Europe/London'
['#', 'Ansible managed: /nfs/users/
['', '']
I think it would be better to do a line-by-line read of the file, and discard comment lines (i.e. where first character is #)?
affects: | pytz → python-tzlocal (Ubuntu) |
Changed in python-tzlocal (Ubuntu): | |
status: | New → Fix Committed |
status: | Fix Committed → Fix Released |
Sorry, this is actually a bug in python3-tzlocal.