summaryrefslogtreecommitdiff
path: root/src/zope/i18n/locales
diff options
context:
space:
mode:
Diffstat (limited to 'src/zope/i18n/locales')
-rw-r--r--src/zope/i18n/locales/__init__.py67
-rw-r--r--src/zope/i18n/locales/inheritance.py17
-rw-r--r--src/zope/i18n/locales/provider.py4
-rw-r--r--src/zope/i18n/locales/tests/test_docstrings.py2
-rw-r--r--src/zope/i18n/locales/tests/test_fallbackcollator.py2
-rw-r--r--src/zope/i18n/locales/tests/test_locales.py10
-rw-r--r--src/zope/i18n/locales/tests/test_xmlfactory.py5
-rw-r--r--src/zope/i18n/locales/xmlfactory.py48
8 files changed, 91 insertions, 64 deletions
diff --git a/src/zope/i18n/locales/__init__.py b/src/zope/i18n/locales/__init__.py
index 12009a6..8ecb911 100644
--- a/src/zope/i18n/locales/__init__.py
+++ b/src/zope/i18n/locales/__init__.py
@@ -19,24 +19,33 @@ import os
from datetime import date
from zope.interface import implementer
+
+# Setup the locale directory
+from zope import i18n
+from zope.i18n.format import DateTimeFormat
+from zope.i18n.format import NumberFormat
from zope.i18n.interfaces.locales import ILocale
-from zope.i18n.interfaces.locales import ILocaleDisplayNames, ILocaleDates
-from zope.i18n.interfaces.locales import ILocaleVersion, ILocaleIdentity
-from zope.i18n.interfaces.locales import ILocaleTimeZone, ILocaleCalendar
-from zope.i18n.interfaces.locales import ILocaleCurrency, ILocaleNumbers
-from zope.i18n.interfaces.locales import ILocaleFormat, ILocaleFormatLength
+from zope.i18n.interfaces.locales import ILocaleCalendar
+from zope.i18n.interfaces.locales import ILocaleCurrency
+from zope.i18n.interfaces.locales import ILocaleDates
+from zope.i18n.interfaces.locales import ILocaleDayContext
+from zope.i18n.interfaces.locales import ILocaleDisplayNames
+from zope.i18n.interfaces.locales import ILocaleFormat
+from zope.i18n.interfaces.locales import ILocaleFormatLength
+from zope.i18n.interfaces.locales import ILocaleIdentity
+from zope.i18n.interfaces.locales import ILocaleMonthContext
+from zope.i18n.interfaces.locales import ILocaleNumbers
from zope.i18n.interfaces.locales import ILocaleOrientation
-from zope.i18n.interfaces.locales import ILocaleDayContext, ILocaleMonthContext
-from zope.i18n.format import NumberFormat, DateTimeFormat
-from zope.i18n.locales.inheritance import \
- AttributeInheritance, InheritingDictionary, NoParentException
+from zope.i18n.interfaces.locales import ILocaleTimeZone
+from zope.i18n.interfaces.locales import ILocaleVersion
+from zope.i18n.locales.inheritance import AttributeInheritance
+from zope.i18n.locales.inheritance import InheritingDictionary
+from zope.i18n.locales.inheritance import NoParentException
# LoadLocaleError is not used, but might be imported from here by others.
from zope.i18n.locales.provider import LoadLocaleError # noqa
from zope.i18n.locales.provider import LocaleProvider
-# Setup the locale directory
-from zope import i18n
LOCALEDIR = os.path.join(os.path.dirname(i18n.__file__), "locales", "data")
# Global LocaleProvider. We really just need this single one.
@@ -77,7 +86,7 @@ calendarAliases = {'islamic': ('arabic',),
@implementer(ILocaleIdentity)
-class LocaleIdentity(object):
+class LocaleIdentity:
"""Represents a unique identification of the locale
This class does not have to deal with inheritance.
@@ -116,12 +125,12 @@ class LocaleIdentity(object):
def __repr__(self):
"""See zope.i18n.interfaces.ILocaleIdentity
"""
- return "<LocaleIdentity (%s, %s, %s, %s)>" % (
+ return "<LocaleIdentity ({}, {}, {}, {})>".format(
self.language, self.script, self.territory, self.variant)
@implementer(ILocaleVersion)
-class LocaleVersion(object):
+class LocaleVersion:
"""Represents a particular version of a locale
This class does not have to deal with inheritance.
@@ -190,7 +199,7 @@ class LocaleDisplayNames(AttributeInheritance):
@implementer(ILocaleTimeZone)
-class LocaleTimeZone(object):
+class LocaleTimeZone:
"""Specifies one of the timezones of a specific locale.
The attributes of this class are not inherited, since all timezone
@@ -217,7 +226,7 @@ class LocaleTimeZone(object):
@implementer(ILocaleFormat)
-class LocaleFormat(object):
+class LocaleFormat:
"""Specifies one of the format of a specific format length.
The attributes of this class are not inherited, since all format
@@ -229,8 +238,8 @@ class LocaleFormat(object):
def __init__(self, type=None):
"""Initialize the object."""
self.type = type
- self.displayName = u""
- self.pattern = u""
+ self.displayName = ""
+ self.pattern = ""
@implementer(ILocaleFormatLength)
@@ -250,7 +259,7 @@ class LocaleMonthContext(AttributeInheritance):
def __init__(self, type=None):
"""Initialize the object."""
self.type = type
- self.default = u"wide"
+ self.default = "wide"
@implementer(ILocaleDayContext)
@@ -259,7 +268,7 @@ class LocaleDayContext(AttributeInheritance):
def __init__(self, type=None):
"""Initialize the object."""
self.type = type
- self.default = u"wide"
+ self.default = "wide"
@implementer(ILocaleCalendar)
@@ -498,15 +507,15 @@ class LocaleDates(AttributeInheritance):
"""
def getFormatter(self, category, length=None, name=None,
- calendar=u"gregorian"):
+ calendar="gregorian"):
"""See zope.i18n.interfaces.locales.ILocaleDates"""
- if category not in (u"date", u"time", u"dateTime"):
+ if category not in ("date", "time", "dateTime"):
raise ValueError('Invalid category: %s' % category)
- if calendar not in (u"gregorian", u"arabic", u"chinese",
- u"civil-arabic", u"hebrew", u"japanese",
- u"thai-buddhist"):
+ if calendar not in ("gregorian", "arabic", "chinese",
+ "civil-arabic", "hebrew", "japanese",
+ "thai-buddhist"):
raise ValueError('Invalid calendar: %s' % calendar)
- if length not in (u"short", u"medium", u"long", u"full", None):
+ if length not in ("short", "medium", "long", "full", None):
raise ValueError('Invalid format length: %s' % length)
cal = self.calendars[calendar]
@@ -544,7 +553,7 @@ class LocaleDates(AttributeInheritance):
@implementer(ILocaleCurrency)
-class LocaleCurrency(object):
+class LocaleCurrency:
"""Simple implementation of ILocaleCurrency without inheritance support,
since it is not needed for a single currency."""
@@ -634,8 +643,8 @@ class LocaleNumbers(AttributeInheritance):
def getFormatter(self, category, length=None, name=None):
"""See zope.i18n.interfaces.locales.ILocaleNumbers"""
- assert category in (u"decimal", u"percent", u"scientific", u"currency")
- assert length in (u"short", u"medium", u"long", u"full", None)
+ assert category in ("decimal", "percent", "scientific", "currency")
+ assert length in ("short", "medium", "long", "full", None)
formats = getattr(self, category + 'Formats')
if length is None:
diff --git a/src/zope/i18n/locales/inheritance.py b/src/zope/i18n/locales/inheritance.py
index e597b78..809b6fe 100644
--- a/src/zope/i18n/locales/inheritance.py
+++ b/src/zope/i18n/locales/inheritance.py
@@ -21,10 +21,11 @@ locale inheritance is not inheritance in the programming sense.
__docformat__ = 'restructuredtext'
from zope.deprecation import deprecate
-
from zope.interface import implementer
-from zope.i18n.interfaces.locales import \
- ILocaleInheritance, IAttributeInheritance, IDictionaryInheritance
+
+from zope.i18n.interfaces.locales import IAttributeInheritance
+from zope.i18n.interfaces.locales import IDictionaryInheritance
+from zope.i18n.interfaces.locales import ILocaleInheritance
class NoParentException(AttributeError):
@@ -32,7 +33,7 @@ class NoParentException(AttributeError):
@implementer(ILocaleInheritance)
-class Inheritance(object):
+class Inheritance:
"""A simple base version of locale inheritance.
This object contains some shared code amongst the various
@@ -109,7 +110,7 @@ class AttributeInheritance(Inheritance):
not name.startswith('__')):
value.__parent__ = self
value.__name__ = name
- super(AttributeInheritance, self).__setattr__(name, value)
+ super().__setattr__(name, value)
def __getattr__(self, name):
"""See zope.i18n.interfaces.locales.ILocaleInheritance"""
@@ -129,7 +130,7 @@ class AttributeInheritance(Inheritance):
# Note that we cannot use the normal setattr function, since
# __setattr__ of this class tries to assign a parent and name,
# which we do not want to override.
- super(AttributeInheritance, self).__setattr__(name, value)
+ super().__setattr__(name, value)
return value
@@ -200,7 +201,7 @@ class InheritingDictionary(Inheritance, dict):
if ILocaleInheritance.providedBy(value):
value.__parent__ = self
value.__name__ = name
- super(InheritingDictionary, self).__setitem__(name, value)
+ super().__setitem__(name, value)
def __getitem__(self, name):
"""See zope.i18n.interfaces.locales.ILocaleInheritance"""
@@ -211,7 +212,7 @@ class InheritingDictionary(Inheritance, dict):
pass
else:
return selfUp.__getitem__(name)
- return super(InheritingDictionary, self).__getitem__(name)
+ return super().__getitem__(name)
def get(self, name, default=None):
"""See zope.i18n.interfaces.locales.ILocaleInheritance"""
diff --git a/src/zope/i18n/locales/provider.py b/src/zope/i18n/locales/provider.py
index 9e7f66b..6396898 100644
--- a/src/zope/i18n/locales/provider.py
+++ b/src/zope/i18n/locales/provider.py
@@ -17,7 +17,9 @@ The Locale Provider looks up locales and loads them from the XML data, if
necessary.
"""
import os
+
from zope.interface import implementer
+
from zope.i18n.interfaces.locales import ILocaleProvider
@@ -26,7 +28,7 @@ class LoadLocaleError(Exception):
@implementer(ILocaleProvider)
-class LocaleProvider(object):
+class LocaleProvider:
"""A locale provider that gets its data from the XML data."""
def __init__(self, locale_dir):
diff --git a/src/zope/i18n/locales/tests/test_docstrings.py b/src/zope/i18n/locales/tests/test_docstrings.py
index faa4e97..59a8f52 100644
--- a/src/zope/i18n/locales/tests/test_docstrings.py
+++ b/src/zope/i18n/locales/tests/test_docstrings.py
@@ -15,9 +15,9 @@
"""
import unittest
from doctest import DocTestSuite
+
from zope.i18n.locales.inheritance import AttributeInheritance
from zope.i18n.locales.inheritance import NoParentException
-
from zope.i18n.testing import unicode_checker
diff --git a/src/zope/i18n/locales/tests/test_fallbackcollator.py b/src/zope/i18n/locales/tests/test_fallbackcollator.py
index ad78b72..f3a2761 100644
--- a/src/zope/i18n/locales/tests/test_fallbackcollator.py
+++ b/src/zope/i18n/locales/tests/test_fallbackcollator.py
@@ -12,8 +12,8 @@
#
##############################################################################
-import unittest
import doctest
+import unittest
from zope.i18n.testing import unicode_checker
diff --git a/src/zope/i18n/locales/tests/test_locales.py b/src/zope/i18n/locales/tests/test_locales.py
index 523b1d2..42968cc 100644
--- a/src/zope/i18n/locales/tests/test_locales.py
+++ b/src/zope/i18n/locales/tests/test_locales.py
@@ -13,19 +13,21 @@
##############################################################################
"""This module tests the LocaleProvider and everything that goes with it.
"""
-import os
import datetime
+import os
from unittest import TestCase
+import zope.i18n
from zope.i18n.interfaces.locales import ILocaleProvider
from zope.i18n.locales import locales
-from zope.i18n.locales.provider import LocaleProvider, LoadLocaleError
+from zope.i18n.locales.provider import LoadLocaleError
+from zope.i18n.locales.provider import LocaleProvider
+
-import zope.i18n
datadir = os.path.join(os.path.dirname(zope.i18n.__file__), 'locales', 'data')
-class AbstractTestILocaleProviderMixin(object):
+class AbstractTestILocaleProviderMixin:
"""Test the functionality of an implmentation of the ILocaleProvider
interface."""
diff --git a/src/zope/i18n/locales/tests/test_xmlfactory.py b/src/zope/i18n/locales/tests/test_xmlfactory.py
index e11097c..e3e82f9 100644
--- a/src/zope/i18n/locales/tests/test_xmlfactory.py
+++ b/src/zope/i18n/locales/tests/test_xmlfactory.py
@@ -14,10 +14,11 @@
"""Testing all XML Locale functionality.
"""
import os
-from unittest import TestCase, TestSuite
+from unittest import TestCase
+from unittest import TestSuite
-from zope.i18n.locales.xmlfactory import LocaleFactory
import zope.i18n
+from zope.i18n.locales.xmlfactory import LocaleFactory
class LocaleXMLFileTestCase(TestCase):
diff --git a/src/zope/i18n/locales/xmlfactory.py b/src/zope/i18n/locales/xmlfactory.py
index f1ed219..c6ac415 100644
--- a/src/zope/i18n/locales/xmlfactory.py
+++ b/src/zope/i18n/locales/xmlfactory.py
@@ -13,18 +13,30 @@
##############################################################################
"""XML Locale-related objects and functions
"""
-from datetime import date, time
+from datetime import date
+from datetime import time
from xml.dom.minidom import parse as parseXML
-from zope.i18n.locales import Locale, LocaleDisplayNames, LocaleDates
-from zope.i18n.locales import LocaleVersion, LocaleIdentity, LocaleTimeZone
-from zope.i18n.locales import LocaleCalendar, LocaleCurrency, LocaleNumbers
-from zope.i18n.locales import LocaleFormat, LocaleFormatLength, dayMapping
-from zope.i18n.locales import LocaleOrientation, LocaleDayContext
-from zope.i18n.locales import LocaleMonthContext, calendarAliases
+
+from zope.i18n.locales import Locale
+from zope.i18n.locales import LocaleCalendar
+from zope.i18n.locales import LocaleCurrency
+from zope.i18n.locales import LocaleDates
+from zope.i18n.locales import LocaleDayContext
+from zope.i18n.locales import LocaleDisplayNames
+from zope.i18n.locales import LocaleFormat
+from zope.i18n.locales import LocaleFormatLength
+from zope.i18n.locales import LocaleIdentity
+from zope.i18n.locales import LocaleMonthContext
+from zope.i18n.locales import LocaleNumbers
+from zope.i18n.locales import LocaleOrientation
+from zope.i18n.locales import LocaleTimeZone
+from zope.i18n.locales import LocaleVersion
+from zope.i18n.locales import calendarAliases
+from zope.i18n.locales import dayMapping
from zope.i18n.locales.inheritance import InheritingDictionary
-class LocaleFactory(object):
+class LocaleFactory:
"""This class creates a Locale object from an ICU XML file."""
def __init__(self, path):
@@ -35,7 +47,7 @@ class LocaleFactory(object):
self._data = parseXML(path).documentElement
def _getText(self, nodelist):
- rc = u''
+ rc = ''
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
@@ -983,7 +995,7 @@ class LocaleFactory(object):
# get the short and long name node
long = node.getElementsByTagName('long')
short = node.getElementsByTagName('short')
- for type in (u"generic", u"standard", u"daylight"):
+ for type in ("generic", "standard", "daylight"):
# get long name
long_desc = None
if long:
@@ -1066,10 +1078,10 @@ 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 ("decimal", "group", "list", "percentSign",
+ "nativeZeroDigit", "patternDigit", "plusSign",
+ "minusSign", "exponential", "perMille",
+ "infinity", "nan"):
nodes = symbols_nodes[0].getElementsByTagName(name)
if nodes:
symbols[name] = self._getText(nodes[0].childNodes)
@@ -1225,7 +1237,7 @@ class LocaleFactory(object):
if nodes:
currency.symbol = self._getText(nodes[0].childNodes)
currency.symbolChoice = \
- nodes[0].getAttribute('choice') == u"true"
+ nodes[0].getAttribute('choice') == "true"
nodes = curr_node.getElementsByTagName('displayName')
if nodes:
@@ -1298,8 +1310,8 @@ class LocaleFactory(object):
return
delimiters = InheritingDictionary()
- for name in (u'quotationStart', u"quotationEnd",
- u"alternateQuotationStart", u"alternateQuotationEnd"):
+ for name in ('quotationStart', "quotationEnd",
+ "alternateQuotationStart", "alternateQuotationEnd"):
nodes = delimiters_nodes[0].getElementsByTagName(name)
if nodes:
delimiters[name] = self._getText(nodes[0].childNodes)
@@ -1330,7 +1342,7 @@ class LocaleFactory(object):
if not orientation_nodes:
return
orientation = LocaleOrientation()
- for name in (u"characters", u"lines"):
+ for name in ("characters", "lines"):
value = orientation_nodes[0].getAttribute(name)
if value:
setattr(orientation, name, value)