# HG changeset patch # User cmlenz # Date 1187181700 0 # Node ID 04936a6812af7e06d99eb31d16b30292fe607e4e # Parent ba30864779ccc93ec7556d64d29ab647c2f5c197 Fail more gracefully when formatting the timezone for an unknown/invalid territory. diff --git a/babel/dates.py b/babel/dates.py --- a/babel/dates.py +++ b/babel/dates.py @@ -276,8 +276,10 @@ # 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