summaryrefslogtreecommitdiff
path: root/src/zope/i18n/locales/xmlfactory.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/zope/i18n/locales/xmlfactory.py')
-rw-r--r--src/zope/i18n/locales/xmlfactory.py159
1 files changed, 89 insertions, 70 deletions
diff --git a/src/zope/i18n/locales/xmlfactory.py b/src/zope/i18n/locales/xmlfactory.py
index 5b2dbf5..244d17e 100644
--- a/src/zope/i18n/locales/xmlfactory.py
+++ b/src/zope/i18n/locales/xmlfactory.py
@@ -41,7 +41,6 @@ class LocaleFactory(object):
rc = rc + node.data
return rc
-
def _extractVersion(self, identity_node):
"""Extract the Locale's version info based on data from the DOM
tree.
@@ -81,7 +80,6 @@ class LocaleFactory(object):
return LocaleVersion(number, generationDate, notes)
-
def _extractIdentity(self):
"""Extract the Locale's identity object based on info from the DOM
tree.
@@ -119,7 +117,7 @@ class LocaleFactory(object):
# Retrieve the language of the locale
nodes = identity.getElementsByTagName('language')
if nodes != []:
- id.language = nodes[0].getAttribute('type') or None
+ id.language = nodes[0].getAttribute('type') or None
# Retrieve the territory of the locale
nodes = identity.getElementsByTagName('territory')
if nodes != []:
@@ -132,7 +130,6 @@ class LocaleFactory(object):
id.version = self._extractVersion(identity)
return id
-
def _extractTypes(self, names_node):
"""Extract all types from the names_node.
@@ -179,7 +176,6 @@ class LocaleFactory(object):
types[(type, key)] = self._getText(type_node.childNodes)
return types
-
def _extractDisplayNames(self):
"""Extract all display names from the DOM tree.
@@ -265,11 +261,13 @@ class LocaleFactory(object):
if names_nodes == []:
return displayNames
- for group_tag, single_tag in (('languages', 'language'),
- ('scripts', 'script'),
- ('territories', 'territory'),
- ('variants', 'variant'),
- ('keys', 'key')):
+ for group_tag, single_tag in (
+ ('languages', 'language'),
+ ('scripts', 'script'),
+ ('territories', 'territory'),
+ ('variants', 'variant'),
+ ('keys', 'key'),
+ ):
group_nodes = names_nodes[0].getElementsByTagName(group_tag)
if group_nodes == []:
continue
@@ -285,7 +283,6 @@ class LocaleFactory(object):
displayNames.types = types
return displayNames
-
def _extractMonths(self, months_node, calendar):
"""Extract all month entries from cal_node and store them in calendar.
@@ -385,14 +382,16 @@ class LocaleFactory(object):
defaultMonthContext_node = months_node.getElementsByTagName('default')
if defaultMonthContext_node:
- calendar.defaultMonthContext = defaultMonthContext_node[0].getAttribute('type')
+ calendar.defaultMonthContext = defaultMonthContext_node[
+ 0
+ ].getAttribute('type')
monthContext_nodes = months_node.getElementsByTagName('monthContext')
if not monthContext_nodes:
return
calendar.monthContexts = InheritingDictionary()
- names_node = abbrs_node = None # BBB
+ names_node = abbrs_node = None # BBB
for node in monthContext_nodes:
context_type = node.getAttribute('type')
@@ -438,9 +437,10 @@ class LocaleFactory(object):
# Put the info together
calendar.months = InheritingDictionary()
for type in range(1, 13):
- calendar.months[type] = (names.get(type, None),
- abbrs.get(type, None))
-
+ calendar.months[type] = (
+ names.get(type, None),
+ abbrs.get(type, None),
+ )
def _extractDays(self, days_node, calendar):
"""Extract all day entries from cal_node and store them in
@@ -529,14 +529,16 @@ class LocaleFactory(object):
defaultDayContext_node = days_node.getElementsByTagName('default')
if defaultDayContext_node:
- calendar.defaultDayContext = defaultDayContext_node[0].getAttribute('type')
+ calendar.defaultDayContext = defaultDayContext_node[
+ 0
+ ].getAttribute('type')
dayContext_nodes = days_node.getElementsByTagName('dayContext')
if not dayContext_nodes:
return
calendar.dayContexts = InheritingDictionary()
- names_node = abbrs_node = None # BBB
+ names_node = abbrs_node = None # BBB
for node in dayContext_nodes:
context_type = node.getAttribute('type')
@@ -581,9 +583,10 @@ class LocaleFactory(object):
# Put the info together
calendar.days = InheritingDictionary()
for type in range(1, 13):
- calendar.days[type] = (names.get(type, None),
- abbrs.get(type, None))
-
+ calendar.days[type] = (
+ names.get(type, None),
+ abbrs.get(type, None),
+ )
def _extractWeek(self, cal_node, calendar):
"""Extract all week entries from cal_node and store them in
@@ -644,7 +647,6 @@ class LocaleFactory(object):
time_args = map(int, node.getAttribute('time').split(':'))
calendar.week['weekendEnd'] = (day, time(*time_args))
-
def _extractEras(self, cal_node, calendar):
"""Extract all era entries from cal_node and store them in
calendar.
@@ -703,8 +705,10 @@ class LocaleFactory(object):
calendar.eras = InheritingDictionary()
for type in abbrs.keys():
- calendar.eras[type] = (names.get(type, None), abbrs.get(type, None))
-
+ calendar.eras[type] = (
+ names.get(type, None),
+ abbrs.get(type, None),
+ )
def _extractFormats(self, formats_node, lengthNodeName, formatNodeName):
"""Extract all format entries from formats_node and return a
@@ -765,14 +769,18 @@ class LocaleFactory(object):
if length_node.getElementsByTagName(formatNodeName):
length.formats = InheritingDictionary()
- for format_node in length_node.getElementsByTagName(formatNodeName):
+ for format_node in length_node.getElementsByTagName(
+ formatNodeName
+ ):
format = LocaleFormat()
format.type = format_node.getAttribute('type') or None
pattern_node = format_node.getElementsByTagName('pattern')[0]
format.pattern = self._getText(pattern_node.childNodes)
name_nodes = format_node.getElementsByTagName('displayName')
if name_nodes:
- format.displayName = self._getText(name_nodes[0].childNodes)
+ format.displayName = self._getText(
+ name_nodes[0].childNodes
+ )
length.formats[format.type] = format
lengths[length.type] = length
@@ -905,17 +913,21 @@ class LocaleFactory(object):
self._extractEras(cal_node, calendar)
for formatsName, lengthName, formatName in (
- ('dateFormats', 'dateFormatLength', 'dateFormat'),
- ('timeFormats', 'timeFormatLength', 'timeFormat'),
- ('dateTimeFormats', 'dateTimeFormatLength', 'dateTimeFormat')):
+ ('dateFormats', 'dateFormatLength', 'dateFormat'),
+ ('timeFormats', 'timeFormatLength', 'timeFormat'),
+ ('dateTimeFormats', 'dateTimeFormatLength', 'dateTimeFormat'),
+ ):
formats_nodes = cal_node.getElementsByTagName(formatsName)
if formats_nodes:
default, formats = self._extractFormats(
- formats_nodes[0], lengthName, formatName)
- setattr(calendar,
- 'default'+formatName[0].upper()+formatName[1:],
- default)
+ formats_nodes[0], lengthName, formatName
+ )
+ setattr(
+ calendar,
+ 'default' + formatName[0].upper() + formatName[1:],
+ default,
+ )
setattr(calendar, formatsName, formats)
calendars[calendar.type] = calendar
@@ -925,7 +937,6 @@ class LocaleFactory(object):
return calendars
-
def _extractTimeZones(self, dates_node):
"""Extract all timezone information for the locale from the DOM
tree.
@@ -1009,7 +1020,6 @@ class LocaleFactory(object):
return zones
-
def _extractDates(self):
"""Extract all date information from the DOM tree"""
dates_nodes = self._data.getElementsByTagName('dates')
@@ -1025,7 +1035,6 @@ class LocaleFactory(object):
dates.timezones = timezones
return dates
-
def _extractSymbols(self, numbers_node):
"""Extract all week entries from cal_node and store them in
calendar.
@@ -1071,17 +1080,26 @@ class LocaleFactory(object):
return
symbols = InheritingDictionary()
- for name in (u"decimal", u"group", u"list", u"percentSign",
- u"nativeZeroDigit", u"patternDigit", u"plusSign",
- u"minusSign", u"exponential", u"perMille",
- u"infinity", u"nan"):
+ for name in (
+ u"decimal",
+ u"group",
+ u"list",
+ u"percentSign",
+ u"nativeZeroDigit",
+ u"patternDigit",
+ u"plusSign",
+ u"minusSign",
+ u"exponential",
+ u"perMille",
+ u"infinity",
+ u"nan",
+ ):
nodes = symbols_nodes[0].getElementsByTagName(name)
if nodes:
symbols[name] = self._getText(nodes[0].childNodes)
return symbols
-
def _extractNumberFormats(self, numbers_node, numbers):
"""Extract all number formats from the numbers_node and save the data
in numbers.
@@ -1162,19 +1180,19 @@ class LocaleFactory(object):
"""
for category in ('decimal', 'scientific', 'percent', 'currency'):
- formatsName = category+'Formats'
- lengthName = category+'FormatLength'
- formatName = category+'Format'
- defaultName = 'default'+formatName[0].upper()+formatName[1:]
+ formatsName = category + 'Formats'
+ lengthName = category + 'FormatLength'
+ formatName = category + 'Format'
+ defaultName = 'default' + formatName[0].upper() + formatName[1:]
formats_nodes = numbers_node.getElementsByTagName(formatsName)
if formats_nodes:
default, formats = self._extractFormats(
- formats_nodes[0], lengthName, formatName)
+ formats_nodes[0], lengthName, formatName
+ )
setattr(numbers, defaultName, default)
setattr(numbers, formatsName, formats)
-
def _extractCurrencies(self, numbers_node):
"""Extract all currency definitions and their information from the
Locale's DOM tree.
@@ -1231,8 +1249,9 @@ class LocaleFactory(object):
nodes = curr_node.getElementsByTagName('symbol')
if nodes:
currency.symbol = self._getText(nodes[0].childNodes)
- currency.symbolChoice = \
- nodes[0].getAttribute('choice') == u"true"
+ currency.symbolChoice = (
+ nodes[0].getAttribute('choice') == u"true"
+ )
nodes = curr_node.getElementsByTagName('displayName')
if nodes:
@@ -1242,7 +1261,6 @@ class LocaleFactory(object):
return currencies
-
def _extractNumbers(self):
"""Extract all number information from the DOM tree"""
numbers_nodes = self._data.getElementsByTagName('numbers')
@@ -1259,7 +1277,6 @@ class LocaleFactory(object):
numbers.currencies = currencies
return numbers
-
def _extractDelimiters(self):
"""Extract all delimiter entries from the DOM tree.
@@ -1307,33 +1324,36 @@ class LocaleFactory(object):
return
delimiters = InheritingDictionary()
- for name in (u'quotationStart', u"quotationEnd",
- u"alternateQuotationStart", u"alternateQuotationEnd"):
+ for name in (
+ u'quotationStart',
+ u"quotationEnd",
+ u"alternateQuotationStart",
+ u"alternateQuotationEnd",
+ ):
nodes = delimiters_nodes[0].getElementsByTagName(name)
if nodes:
delimiters[name] = self._getText(nodes[0].childNodes)
return delimiters
-
def _extractOrientation(self):
"""Extract orientation information.
- >>> factory = LocaleFactory(None)
- >>> from xml.dom.minidom import parseString
- >>> xml = u'''
- ... <ldml>
- ... <layout>
- ... <orientation lines="bottom-to-top" characters="right-to-left" />
- ... </layout>
- ... </ldml>'''
- >>> dom = parseString(xml)
- >>> factory._data = parseString(xml).documentElement
- >>> orientation = factory._extractOrientation()
- >>> orientation.lines
- u'bottom-to-top'
- >>> orientation.characters
- u'right-to-left'
+ >>> factory = LocaleFactory(None)
+ >>> from xml.dom.minidom import parseString
+ >>> xml = u'''
+ ... <ldml>
+ ... <layout>
+ ... <orientation lines="bottom-to-top" characters="right-to-left" />
+ ... </layout>
+ ... </ldml>'''
+ >>> dom = parseString(xml)
+ >>> factory._data = parseString(xml).documentElement
+ >>> orientation = factory._extractOrientation()
+ >>> orientation.lines
+ u'bottom-to-top'
+ >>> orientation.characters
+ u'right-to-left'
"""
orientation_nodes = self._data.getElementsByTagName('orientation')
if not orientation_nodes:
@@ -1345,7 +1365,6 @@ class LocaleFactory(object):
setattr(orientation, name, value)
return orientation
-
def __call__(self):
"""Create the Locale."""
locale = Locale(self._extractIdentity())