From: Christopher Lenz Date: Wed, 15 Aug 2007 12:41:40 +0000 (+0000) Subject: Fail more gracefully when formatting the timezone for an unknown/invalid territory. X-Git-Tag: 1.0~395 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=385a6fdd7facce9ccbca037c4319460c5a6c3c72;p=thirdparty%2Fbabel.git Fail more gracefully when formatting the timezone for an unknown/invalid territory. --- diff --git a/babel/dates.py b/babel/dates.py index df722635..daea4999 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -276,8 +276,10 @@ def get_timezone_location(dt_or_tzinfo=None, locale=LC_TIME): # localized country name region_format = locale.zone_formats['region'] territory = get_global('zone_territories').get(zone) + if territory not in locale.territories: + territory = 'ZZ' # invalid/unknown territory_name = locale.territories[territory] - if territory and len(get_global('territory_zones')[territory]) == 1: + if territory and len(get_global('territory_zones').get(territory, [])) == 1: return region_format % (territory_name) # Otherwise, include the city in the output