From 4e15ebd90d5b31e6fe5161c5aac14e5d038adc85 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 3 Sep 2021 10:07:09 +0200 Subject: autopep8 --- docs/conf.py | 6 +-- setup.py | 7 +++- src/zope/i18n/compile.py | 5 ++- src/zope/i18n/config.py | 3 +- src/zope/i18n/format.py | 43 +++++++++++----------- src/zope/i18n/interfaces/__init__.py | 3 -- src/zope/i18n/interfaces/locales.py | 16 +++++--- src/zope/i18n/locales/__init__.py | 10 +++-- src/zope/i18n/locales/fallbackcollator.py | 1 + src/zope/i18n/locales/inheritance.py | 9 ++--- src/zope/i18n/locales/provider.py | 2 +- src/zope/i18n/locales/tests/test_docstrings.py | 4 +- .../i18n/locales/tests/test_fallbackcollator.py | 8 ++-- src/zope/i18n/locales/tests/test_locales.py | 2 + src/zope/i18n/locales/tests/test_xmlfactory.py | 10 ++--- src/zope/i18n/locales/xmlfactory.py | 38 ++++++------------- src/zope/i18n/testmessagecatalog.py | 5 ++- src/zope/i18n/tests/test.py | 1 + src/zope/i18n/tests/test_formats.py | 12 +++--- src/zope/i18n/tests/test_gettextmessagecatalog.py | 1 - src/zope/i18n/tests/test_imessagecatalog.py | 4 +- src/zope/i18n/tests/test_itranslationdomain.py | 5 ++- src/zope/i18n/tests/test_negotiator.py | 16 ++++---- src/zope/i18n/tests/test_plurals.py | 6 +-- src/zope/i18n/tests/test_testmessagecatalog.py | 2 + src/zope/i18n/tests/test_translationdomain.py | 2 +- src/zope/i18n/tests/test_zcml.py | 1 + src/zope/i18n/tests/testi18nawareobject.py | 4 +- src/zope/i18n/zcml.py | 4 +- 29 files changed, 120 insertions(+), 110 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0ed66d4..f6fff3f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,7 @@ import pkg_resources # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.append(os.path.abspath('.')) +# sys.path.append(os.path.abspath('.')) sys.path.append(os.path.abspath('../src')) rqmt = pkg_resources.require('zope.i18n')[0] @@ -183,8 +183,8 @@ htmlhelp_basename = 'zopei18ndoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'zopei18n.tex', u'zope.i18n Documentation', - u'Zope Foundation and Contributors', 'manual'), + ('index', 'zopei18n.tex', u'zope.i18n Documentation', + u'Zope Foundation and Contributors', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/setup.py b/setup.py index dc3b83c..297b18d 100644 --- a/setup.py +++ b/setup.py @@ -21,10 +21,12 @@ import os from setuptools import setup, find_packages + def read(*rnames): with open(os.path.join(os.path.dirname(__file__), *rnames)) as f: return f.read() + def alltests(): import sys import unittest @@ -39,6 +41,7 @@ def alltests(): suites = list(zope.testrunner.find.find_suites(options)) return unittest.TestSuite(suites) + COMPILE_REQUIRES = [ # python-gettext used to be here, but it's now # a fixed requirement. Keep the extra to avoid @@ -93,7 +96,7 @@ setup( url='https://github.com/zopefoundation/zope.i18n', packages=find_packages('src'), package_dir={'': 'src'}, - namespace_packages=['zope',], + namespace_packages=['zope', ], install_requires=[ 'setuptools', 'python-gettext', @@ -116,4 +119,4 @@ setup( test_suite='__main__.alltests', include_package_data=True, zip_safe=False, - ) +) diff --git a/src/zope/i18n/compile.py b/src/zope/i18n/compile.py index 834bf24..441523d 100644 --- a/src/zope/i18n/compile.py +++ b/src/zope/i18n/compile.py @@ -11,12 +11,14 @@ logger = logging.getLogger('zope.i18n') HAS_PYTHON_GETTEXT = True + def _safe_mtime(path): try: return os.path.getmtime(path) except (IOError, OSError): return None + def compile_mo_file(domain, lc_messages_path): """Creates or updates a mo file in the locales folder.""" @@ -44,6 +46,7 @@ def compile_mo_file(domain, lc_messages_path): with open(mofile, 'wb') as fd: fd.write(mo.read()) except PoSyntaxError as err: - logger.warning('Syntax error while compiling %s (%s).', pofile, err.msg) + logger.warning( + 'Syntax error while compiling %s (%s).', pofile, err.msg) except (IOError, OSError) as err: logger.warning('Error while compiling %s (%s).', pofile, err) diff --git a/src/zope/i18n/config.py b/src/zope/i18n/config.py index 1636083..b0068c5 100644 --- a/src/zope/i18n/config.py +++ b/src/zope/i18n/config.py @@ -45,4 +45,5 @@ def _parse_languages(value): #: A set of languages that `zope.i18n.negotiate` will pass to the #: `zope.i18n.interfaces.INegotiator` utility. If this is None, #: no utility will be used. -ALLOWED_LANGUAGES = _parse_languages(os.environ.get(ALLOWED_LANGUAGES_KEY, None)) +ALLOWED_LANGUAGES = _parse_languages( + os.environ.get(ALLOWED_LANGUAGES_KEY, None)) diff --git a/src/zope/i18n/format.py b/src/zope/i18n/format.py index abc3e50..7b9ba4a 100644 --- a/src/zope/i18n/format.py +++ b/src/zope/i18n/format.py @@ -31,7 +31,7 @@ NATIVE_NUMBER_TYPES = (int, float) try: NATIVE_NUMBER_TYPES += (long,) except NameError: - pass # Py3 + pass # Py3 def roundHalfUp(n): @@ -139,10 +139,11 @@ class DateTimeFormat(object): if not ampm_entry: raise DateTimeParseError( 'Cannot handle 12-hour format without am/pm marker.') - ampm = self.calendar.pm == results[bin_pattern.index(ampm_entry[0])] + ampm = self.calendar.pm == results[bin_pattern.index( + ampm_entry[0])] if hour == 12: ampm = not ampm - ordered[3] = (hour + 12*ampm)%24 + ordered[3] = (hour + 12*ampm) % 24 # Shortcut for the simple int functions dt_fields_map = {'d': 2, 'H': 3, 'm': 4, 's': 5, 'S': 6} @@ -155,7 +156,7 @@ class DateTimeFormat(object): # Handle timezones tzinfo = None - pytz_tzinfo = False # If True, we should use pytz specific syntax + pytz_tzinfo = False # If True, we should use pytz specific syntax tz_entry = _findFormattingCharacterInPattern('z', bin_pattern) if ordered[3:] != [None, None, None, None] and tz_entry: length = tz_entry[0][1] @@ -189,7 +190,7 @@ class DateTimeFormat(object): datetime.date.today(), datetime.time(*[e or 0 for e in ordered[3:]]))).timetz() return datetime.time( - *[e or 0 for e in ordered[3:]], **{'tzinfo' :tzinfo} + *[e or 0 for e in ordered[3:]], **{'tzinfo': tzinfo} ) if pytz_tzinfo: @@ -198,7 +199,7 @@ class DateTimeFormat(object): )) return datetime.datetime( - *[e or 0 for e in ordered], **{'tzinfo' :tzinfo} + *[e or 0 for e in ordered], **{'tzinfo': tzinfo} ) def format(self, obj, pattern=None): @@ -282,19 +283,19 @@ class NumberFormat(object): if bin_pattern[sign][GROUPING]: regex += self.symbols['group'] min_size += min_size/3 - regex += ']{%i,100}' %(min_size) + regex += ']{%i,100}' % (min_size) if bin_pattern[sign][FRACTION]: max_precision = len(bin_pattern[sign][FRACTION]) min_precision = bin_pattern[sign][FRACTION].count('0') regex += '['+self.symbols['decimal']+']?' - regex += '[0-9]{%i,%i}' %(min_precision, max_precision) + regex += '[0-9]{%i,%i}' % (min_precision, max_precision) if bin_pattern[sign][EXPONENTIAL] != '': regex += self.symbols['exponential'] min_exp_size = bin_pattern[sign][EXPONENTIAL].count('0') pre_symbols = self.symbols['minusSign'] if bin_pattern[sign][EXPONENTIAL][0] == '+': pre_symbols += self.symbols['plusSign'] - regex += '[%s]?[0-9]{%i,100}' %(pre_symbols, min_exp_size) + regex += '[%s]?[0-9]{%i,100}' % (pre_symbols, min_exp_size) regex += ')' if bin_pattern[sign][PADDING3] is not None: regex += '[' + bin_pattern[sign][PADDING3] + ']+' @@ -353,7 +354,7 @@ class NumberFormat(object): fractionLen = len(fraction) rounded = int(fraction) + 1 fraction = ('%0' + str(fractionLen) + 'i') % rounded - if len(fraction) > fractionLen: # rounded fraction >= 1 + if len(fraction) > fractionLen: # rounded fraction >= 1 roundInt = True fraction = fraction[1:] else: @@ -494,7 +495,7 @@ class NumberFormat(object): if bin_pattern[PADDING2] is not None and pre_padding > 0: if bin_pattern[PADDING1] is not None: text += bin_pattern[PADDING2] - else: # pragma: no cover + else: # pragma: no cover text += bin_pattern[PADDING2] * pre_padding text += number if bin_pattern[PADDING3] is not None and post_padding > 0: @@ -578,7 +579,7 @@ def parseDateTimePattern(pattern, DATETIMECHARS="aGyMdEDFwWhHmsSkKz"): # Some cleaning up if state == IN_QUOTE: - if quote_start == -1: # pragma: no cover + if quote_start == -1: # pragma: no cover # It should not be possible to get into this state. # The only time we set quote_start to -1 we also set the state # to DEFAULT. @@ -605,7 +606,7 @@ def buildDateTimeParseInfo(calendar, pattern): for entry in _findFormattingCharacterInPattern(field, pattern): # The maximum amount of digits should be infinity, but 1000 is # close enough here. - info[entry] = r'([0-9]{%i,1000})' %entry[1] + info[entry] = r'([0-9]{%i,1000})' % entry[1] # year (Number) for entry in _findFormattingCharacterInPattern('y', pattern): @@ -618,12 +619,12 @@ def buildDateTimeParseInfo(calendar, pattern): # am/pm marker (Text) for entry in _findFormattingCharacterInPattern('a', pattern): - info[entry] = r'(%s|%s)' %(calendar.am, calendar.pm) + info[entry] = r'(%s|%s)' % (calendar.am, calendar.pm) # era designator (Text) # TODO: works for gregorian only right now for entry in _findFormattingCharacterInPattern('G', pattern): - info[entry] = r'(%s|%s)' %(calendar.eras[1][1], calendar.eras[2][1]) + info[entry] = r'(%s|%s)' % (calendar.eras[1][1], calendar.eras[2][1]) # time zone (Text) for entry in _findFormattingCharacterInPattern('z', pattern): @@ -676,7 +677,7 @@ def buildDateTimeInfo(dt, calendar, pattern): else: ampm = calendar.am - h = dt.hour%12 + h = dt.hour % 12 if h == 0: h = 12 @@ -693,7 +694,7 @@ def buildDateTimeInfo(dt, calendar, pattern): tz_mins = int(math.fabs(tz_secs % 3600 / 60)) tz_hours = int(math.fabs(tz_secs / 3600)) tz_sign = '-' if tz_secs < 0 else '+' - tz_defaultname = "%s%i%.2i" %(tz_sign, tz_hours, tz_mins) + tz_defaultname = "%s%i%.2i" % (tz_sign, tz_hours, tz_mins) tz_name = tzinfo.tzname(dt) or tz_defaultname tz_fullname = getattr(tzinfo, 'zone', None) or tz_name @@ -705,12 +706,12 @@ def buildDateTimeInfo(dt, calendar, pattern): # Generic Numbers for field, value in (('d', dt.day), ('D', int(dt.strftime('%j'))), ('F', day_of_week_in_month), ('k', dt.hour or 24), - ('K', dt.hour%12), ('h', h), ('H', dt.hour), + ('K', dt.hour % 12), ('h', h), ('H', dt.hour), ('m', dt.minute), ('s', dt.second), ('S', dt.microsecond), ('w', int(dt.strftime('%W'))), ('W', week_in_month)): for entry in _findFormattingCharacterInPattern(field, pattern): - info[entry] = (u"%%.%ii" %entry[1]) %value + info[entry] = (u"%%.%ii" % entry[1]) % value # am/pm marker (Text) for entry in _findFormattingCharacterInPattern('a', pattern): @@ -724,9 +725,9 @@ def buildDateTimeInfo(dt, calendar, pattern): # time zone (Text) for entry in _findFormattingCharacterInPattern('z', pattern): if entry[1] == 1: - info[entry] = u"%s%i%.2i" %(tz_sign, tz_hours, tz_mins) + info[entry] = u"%s%i%.2i" % (tz_sign, tz_hours, tz_mins) elif entry[1] == 2: - info[entry] = u"%s%.2i:%.2i" %(tz_sign, tz_hours, tz_mins) + info[entry] = u"%s%.2i:%.2i" % (tz_sign, tz_hours, tz_mins) elif entry[1] == 3: info[entry] = tz_name else: diff --git a/src/zope/i18n/interfaces/__init__.py b/src/zope/i18n/interfaces/__init__.py index c5a3328..e717108 100644 --- a/src/zope/i18n/interfaces/__init__.py +++ b/src/zope/i18n/interfaces/__init__.py @@ -203,7 +203,6 @@ class IMessageImportFilter(Interface): Classes implementing this interface should usually be Adaptors, as they adapt the IEditableTranslationService interface.""" - def importMessages(domains, languages, file): """Import all messages that are defined in the specified domains and languages. @@ -254,7 +253,6 @@ class IMessageExportFilter(Interface): Classes implementing this interface should usually be Adaptors, as they adapt the IEditableTranslationService interface.""" - def exportMessages(domains, languages): """Export all messages that are defined in the specified domains and languages. @@ -326,7 +324,6 @@ class IFormat(Interface): """Format an object to a string using the pattern as a rule.""" - class INumberFormat(IFormat): r"""Specific number formatting interface. Here are the formatting rules (I modified the rules from ICU a bit, since I think they did not diff --git a/src/zope/i18n/interfaces/locales.py b/src/zope/i18n/interfaces/locales.py index f6017ad..01c9cbe 100644 --- a/src/zope/i18n/interfaces/locales.py +++ b/src/zope/i18n/interfaces/locales.py @@ -17,7 +17,7 @@ import datetime import re from zope.interface import Interface, Attribute from zope.schema import \ - Field, Text, TextLine, Int, Bool, Tuple, List, Dict, Date + Field, Text, TextLine, Int, Bool, Tuple, List, Dict, Date from zope.schema import Choice @@ -188,7 +188,6 @@ class ILocaleTimeZone(Interface): required=True, readonly=True) - names = Dict( title=u"Time Zone Names", description=u"Various names of the timezone.", @@ -230,7 +229,7 @@ class ILocaleFormatLength(Interface): title=u"Format Length Type", description=u"Name of the format length", values=(u"full", u"long", u"medium", u"short") - ) + ) default = TextLine( title=u"Default Format", @@ -491,6 +490,7 @@ class ILocaleCurrency(Interface): symbolChoice = Bool(title=u"Symbol Choice") + class ILocaleNumbers(Interface): """This object contains various data about numbers and currencies.""" @@ -556,7 +556,6 @@ class ILocaleNumbers(Interface): description=u"Name of the format length"), value_type=Field(title=u"ILocaleCurrency object")) - def getFormatter(category, length=None, name=u""): """Get the NumberFormat based on the category, length and name of the format. @@ -577,8 +576,11 @@ class ILocaleNumbers(Interface): def getDefaultCurrency(): """Get the default currency.""" + _orientations = [u"left-to-right", u"right-to-left", u"top-to-bottom", u"bottom-to-top"] + + class ILocaleOrientation(Interface): """Information about the orientation of text.""" @@ -586,13 +588,14 @@ class ILocaleOrientation(Interface): title=u"Orientation of characters", values=_orientations, default=u"left-to-right" - ) + ) lines = Choice( title=u"Orientation of characters", values=_orientations, default=u"top-to-bottom" - ) + ) + class ILocale(Interface): """This class contains all important information about the locale. @@ -699,6 +702,7 @@ class IDictionaryInheritance(ILocaleInheritance): object is consulted. """ + class ICollator(Interface): """Provide support for collating text strings diff --git a/src/zope/i18n/locales/__init__.py b/src/zope/i18n/locales/__init__.py index 030c453..9da515a 100644 --- a/src/zope/i18n/locales/__init__.py +++ b/src/zope/i18n/locales/__init__.py @@ -29,7 +29,7 @@ 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 + AttributeInheritance, InheritingDictionary, NoParentException from zope.i18n.locales.provider import LocaleProvider, LoadLocaleError @@ -73,6 +73,7 @@ calendarAliases = {'islamic': ('arabic',), 'islamic-civil': ('civil-arabic',), 'buddhist': ('thai-buddhist', )} + @implementer(ILocaleIdentity) class LocaleIdentity(object): """Represents a unique identification of the locale @@ -112,7 +113,7 @@ class LocaleIdentity(object): def __repr__(self): """See zope.i18n.interfaces.ILocaleIdentity """ - return "" %( + return "" % ( self.language, self.script, self.territory, self.variant) @@ -158,6 +159,7 @@ class LocaleVersion(object): return ((self.generationDate, self.number) == (other.generationDate, other.number)) + @implementer(ILocaleDisplayNames) class LocaleDisplayNames(AttributeInheritance): """Locale display names with inheritable data. @@ -233,7 +235,6 @@ class LocaleFormatLength(AttributeInheritance): """Specifies one of the format lengths of a specific quantity, like numbers, dates, times and datetimes.""" - def __init__(self, type=None): """Initialize the object.""" self.type = type @@ -652,6 +653,7 @@ class LocaleOrientation(AttributeInheritance): """Implementation of ILocaleOrientation """ + @implementer(ILocale) class Locale(AttributeInheritance): """Implementation of the ILocale interface.""" @@ -690,7 +692,7 @@ class Locale(AttributeInheritance): # Notice that 'pieces' is always empty. pieces = [key + '=' + type for (key, type) in ()] assert not pieces - if pieces: # pragma: no cover + if pieces: # pragma: no cover id_string += '@' + ','.join(pieces) return id_string diff --git a/src/zope/i18n/locales/fallbackcollator.py b/src/zope/i18n/locales/fallbackcollator.py index fc76a58..55c9b77 100644 --- a/src/zope/i18n/locales/fallbackcollator.py +++ b/src/zope/i18n/locales/fallbackcollator.py @@ -16,6 +16,7 @@ from unicodedata import normalize + class FallbackCollator: def __init__(self, locale): diff --git a/src/zope/i18n/locales/inheritance.py b/src/zope/i18n/locales/inheritance.py index 912d8c9..e597b78 100644 --- a/src/zope/i18n/locales/inheritance.py +++ b/src/zope/i18n/locales/inheritance.py @@ -24,11 +24,13 @@ from zope.deprecation import deprecate from zope.interface import implementer from zope.i18n.interfaces.locales import \ - ILocaleInheritance, IAttributeInheritance, IDictionaryInheritance + ILocaleInheritance, IAttributeInheritance, IDictionaryInheritance + class NoParentException(AttributeError): pass + @implementer(ILocaleInheritance) class Inheritance(object): """A simple base version of locale inheritance. @@ -37,7 +39,6 @@ class Inheritance(object): 'ILocaleInheritance' implementations. """ - # See zope.i18n.interfaces.locales.ILocaleInheritance __parent__ = None @@ -100,7 +101,6 @@ class AttributeInheritance(Inheritance): True """ - def __setattr__(self, name, value): """See zope.i18n.interfaces.locales.ILocaleInheritance""" # If we have a value that can also inherit data from other locales, we @@ -111,7 +111,6 @@ class AttributeInheritance(Inheritance): value.__name__ = name super(AttributeInheritance, self).__setattr__(name, value) - def __getattr__(self, name): """See zope.i18n.interfaces.locales.ILocaleInheritance""" try: @@ -134,7 +133,6 @@ class AttributeInheritance(Inheritance): return value - @implementer(IDictionaryInheritance) class InheritingDictionary(Inheritance, dict): """Implementation of a dictionary that can also inherit values. @@ -197,7 +195,6 @@ class InheritingDictionary(Inheritance, dict): `value` is a deprecated synonym for `values` """ - def __setitem__(self, name, value): """See zope.i18n.interfaces.locales.ILocaleInheritance""" if ILocaleInheritance.providedBy(value): diff --git a/src/zope/i18n/locales/provider.py b/src/zope/i18n/locales/provider.py index 3864b7a..9e7f66b 100644 --- a/src/zope/i18n/locales/provider.py +++ b/src/zope/i18n/locales/provider.py @@ -20,6 +20,7 @@ import os from zope.interface import implementer from zope.i18n.interfaces.locales import ILocaleProvider + class LoadLocaleError(Exception): """This error is raised if a locale cannot be loaded.""" @@ -28,7 +29,6 @@ class LoadLocaleError(Exception): class LocaleProvider(object): """A locale provider that gets its data from the XML data.""" - def __init__(self, locale_dir): self._locales = {} self._locale_dir = locale_dir diff --git a/src/zope/i18n/locales/tests/test_docstrings.py b/src/zope/i18n/locales/tests/test_docstrings.py index fa52078..9f75b44 100644 --- a/src/zope/i18n/locales/tests/test_docstrings.py +++ b/src/zope/i18n/locales/tests/test_docstrings.py @@ -20,6 +20,7 @@ from zope.i18n.locales.inheritance import NoParentException from zope.i18n.testing import unicode_checker + class LocaleInheritanceStub(AttributeInheritance): def __init__(self, nextLocale=None): @@ -36,7 +37,8 @@ def test_suite(): DocTestSuite('zope.i18n.locales', checker=unicode_checker), DocTestSuite('zope.i18n.locales.inheritance', checker=unicode_checker), DocTestSuite('zope.i18n.locales.xmlfactory', checker=unicode_checker), - )) + )) + if __name__ == '__main__': unittest.main() diff --git a/src/zope/i18n/locales/tests/test_fallbackcollator.py b/src/zope/i18n/locales/tests/test_fallbackcollator.py index 7e10b50..e7c84a8 100644 --- a/src/zope/i18n/locales/tests/test_fallbackcollator.py +++ b/src/zope/i18n/locales/tests/test_fallbackcollator.py @@ -17,11 +17,13 @@ import doctest from zope.i18n.testing import unicode_checker + def test_suite(): return unittest.TestSuite(( - doctest.DocFileSuite('../fallbackcollator.txt', checker=unicode_checker), - )) + doctest.DocFileSuite('../fallbackcollator.txt', + checker=unicode_checker), + )) + if __name__ == '__main__': unittest.main(defaultTest='test_suite') - diff --git a/src/zope/i18n/locales/tests/test_locales.py b/src/zope/i18n/locales/tests/test_locales.py index 2b100b8..523b1d2 100644 --- a/src/zope/i18n/locales/tests/test_locales.py +++ b/src/zope/i18n/locales/tests/test_locales.py @@ -24,6 +24,7 @@ from zope.i18n.locales.provider import LocaleProvider, LoadLocaleError import zope.i18n datadir = os.path.join(os.path.dirname(zope.i18n.__file__), 'locales', 'data') + class AbstractTestILocaleProviderMixin(object): """Test the functionality of an implmentation of the ILocaleProvider interface.""" @@ -143,6 +144,7 @@ class TestGlobalLocaleProvider(TestCase): self.assertEqual(locale.id.territory, 'GB') self.assertEqual(locale.id.variant, None) + class TestRootLocale(TestCase): """There were some complaints that the root locale does not work correctly, so make sure it does.""" diff --git a/src/zope/i18n/locales/tests/test_xmlfactory.py b/src/zope/i18n/locales/tests/test_xmlfactory.py index 792c96d..6b52dd2 100644 --- a/src/zope/i18n/locales/tests/test_xmlfactory.py +++ b/src/zope/i18n/locales/tests/test_xmlfactory.py @@ -19,6 +19,7 @@ from unittest import TestCase, TestSuite from zope.i18n.locales.xmlfactory import LocaleFactory import zope.i18n + class LocaleXMLFileTestCase(TestCase): """This test verifies that every locale XML file can be loaded.""" @@ -33,14 +34,14 @@ class LocaleXMLFileTestCase(TestCase): # XXX: The tests below are commented out because it's not # necessary for the xml files to have all format definitions. - ## Making sure all number format patterns parse - #for category in (u'decimal', u'scientific', u'percent', u'currency'): + # Making sure all number format patterns parse + # for category in (u'decimal', u'scientific', u'percent', u'currency'): # for length in getattr(locale.numbers, category+'Formats').values(): # for format in length.formats.values(): # self.assert_(parseNumberPattern(format.pattern) is not None) - ## Making sure all datetime patterns parse - #for calendar in locale.dates.calendars.values(): + # Making sure all datetime patterns parse + # for calendar in locale.dates.calendars.values(): # for category in ('date', 'time', 'dateTime'): # for length in getattr(calendar, category+'Formats').values(): # for format in length.formats.values(): @@ -48,7 +49,6 @@ class LocaleXMLFileTestCase(TestCase): # parseDateTimePattern(format.pattern) is not None) - def test_suite(): suite = TestSuite() locale_dir = os.path.join(os.path.dirname(zope.i18n.__file__), diff --git a/src/zope/i18n/locales/xmlfactory.py b/src/zope/i18n/locales/xmlfactory.py index 5b2dbf5..5dbcee0 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. @@ -285,7 +281,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 +380,15 @@ 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') @@ -441,7 +437,6 @@ class LocaleFactory(object): 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 calendar. @@ -529,14 +524,15 @@ 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') @@ -584,7 +580,6 @@ class LocaleFactory(object): 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 calendar. @@ -644,7 +639,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 +697,8 @@ 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 @@ -772,7 +766,8 @@ class LocaleFactory(object): 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 @@ -925,7 +920,6 @@ class LocaleFactory(object): return calendars - def _extractTimeZones(self, dates_node): """Extract all timezone information for the locale from the DOM tree. @@ -1009,7 +1003,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 +1018,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. @@ -1081,7 +1073,6 @@ class LocaleFactory(object): return symbols - def _extractNumberFormats(self, numbers_node, numbers): """Extract all number formats from the numbers_node and save the data in numbers. @@ -1174,7 +1165,6 @@ class LocaleFactory(object): 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. @@ -1232,7 +1222,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') == u"true" nodes = curr_node.getElementsByTagName('displayName') if nodes: @@ -1242,7 +1232,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 +1248,6 @@ class LocaleFactory(object): numbers.currencies = currencies return numbers - def _extractDelimiters(self): """Extract all delimiter entries from the DOM tree. @@ -1315,7 +1303,6 @@ class LocaleFactory(object): return delimiters - def _extractOrientation(self): """Extract orientation information. @@ -1345,7 +1332,6 @@ class LocaleFactory(object): setattr(orientation, name, value) return orientation - def __call__(self): """Create the Locale.""" locale = Locale(self._extractIdentity()) diff --git a/src/zope/i18n/testmessagecatalog.py b/src/zope/i18n/testmessagecatalog.py index 8420c58..a06b15a 100644 --- a/src/zope/i18n/testmessagecatalog.py +++ b/src/zope/i18n/testmessagecatalog.py @@ -18,6 +18,7 @@ from zope import interface import zope.i18n.interfaces from zope.i18n.translationdomain import TranslationDomain + @interface.implementer(zope.i18n.interfaces.IGlobalMessageCatalog) class TestMessageCatalog(object): @@ -43,13 +44,15 @@ class TestMessageCatalog(object): def reload(self): pass + @interface.implementer(zope.i18n.interfaces.ITranslationDomain) def TestMessageFallbackDomain(domain_id=u""): domain = TranslationDomain(domain_id) domain.addCatalog(TestMessageCatalog(domain_id)) return domain + interface.directlyProvides( TestMessageFallbackDomain, zope.i18n.interfaces.IFallbackTranslationDomainFactory, - ) +) diff --git a/src/zope/i18n/tests/test.py b/src/zope/i18n/tests/test.py index 4fb4f4c..05e1366 100644 --- a/src/zope/i18n/tests/test.py +++ b/src/zope/i18n/tests/test.py @@ -22,6 +22,7 @@ from zope.i18n.testing import unicode_checker def test_suite(): options = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS + def suite(name): return doctest.DocTestSuite( name, diff --git a/src/zope/i18n/tests/test_formats.py b/src/zope/i18n/tests/test_formats.py index 83c9129..24791b4 100644 --- a/src/zope/i18n/tests/test_formats.py +++ b/src/zope/i18n/tests/test_formats.py @@ -34,6 +34,7 @@ from zope.i18n.format import NumberPatternParseError class LocaleStub(object): pass + class LocaleCalendarStub(object): type = u"gregorian" @@ -102,13 +103,13 @@ class LocaleCalendarStub(object): class _TestCase(TestCase): # Avoid deprecation warnings in Python 3 by making the preferred # method name available for Python 2. - assertRaisesRegex = getattr(TestCase, 'assertRaisesRegex', TestCase.assertRaisesRegexp) + assertRaisesRegex = getattr( + TestCase, 'assertRaisesRegex', TestCase.assertRaisesRegexp) class TestDateTimePatternParser(_TestCase): """Extensive tests for the ICU-based-syntax datetime pattern parser.""" - def testParseSimpleTimePattern(self): self.assertEqual(parseDateTimePattern('HH'), [('H', 2)]) @@ -217,7 +218,8 @@ class TestBuildDateTimeParseInfo(_TestCase): for char in 'dDFkKhHmsSwW': for length in range(1, 6): self.assertEqual(self.info((char, length)), - '([0-9]{%i,1000})' %length) + '([0-9]{%i,1000})' % length) + def testYear(self): self.assertEqual(self.info(('y', 2)), '([0-9]{2})') self.assertEqual(self.info(('y', 4)), '([0-9]{4})') @@ -674,7 +676,6 @@ class TestDateTimeFormat(_TestCase): "F. EEEE 'im' MMMM, yyyy"), u"2. Freitag im Januar, 2003") - def testFormatGregorianEra(self): self.assertEqual( self.format.format(datetime.date(2017, 12, 17), 'G'), @@ -1329,7 +1330,7 @@ class TestNumberFormat(_TestCase): def testFormatBadThousandSeparator(self): self.assertRaises(ValueError, - self.format.format, 23341, '0,') + self.format.format, 23341, '0,') def testFormatDecimal(self): self.assertEqual(self.format.format(23341.02357, '###0.0#'), @@ -1348,7 +1349,6 @@ class TestNumberFormat(_TestCase): self.assertEqual(self.format.format(1.9999, '0.000'), '2.000') self.assertEqual(self.format.format(1.9999, '0.0000'), '1.9999') - def testFormatScientificDecimal(self): self.assertEqual(self.format.format(23341.02357, '0.00####E00'), '2.334102E04') diff --git a/src/zope/i18n/tests/test_gettextmessagecatalog.py b/src/zope/i18n/tests/test_gettextmessagecatalog.py index 07a0932..5bd93df 100644 --- a/src/zope/i18n/tests/test_gettextmessagecatalog.py +++ b/src/zope/i18n/tests/test_gettextmessagecatalog.py @@ -27,6 +27,5 @@ class GettextMessageCatalogTest(test_imessagecatalog.TestIMessageCatalog): catalog = GettextMessageCatalog('en', 'default', self._path) return catalog - def _getUniqueIndentifier(self): return self._path diff --git a/src/zope/i18n/tests/test_imessagecatalog.py b/src/zope/i18n/tests/test_imessagecatalog.py index 803d4f0..36fb43c 100644 --- a/src/zope/i18n/tests/test_imessagecatalog.py +++ b/src/zope/i18n/tests/test_imessagecatalog.py @@ -21,7 +21,6 @@ from zope.schema import getValidationErrors class TestIMessageCatalog(unittest.TestCase): - # This should be overridden by every class that inherits this test def _getMessageCatalog(self): raise NotImplementedError() @@ -29,7 +28,6 @@ class TestIMessageCatalog(unittest.TestCase): def _getUniqueIndentifier(self): raise NotImplementedError() - def setUp(self): self._catalog = self._getMessageCatalog() @@ -63,4 +61,4 @@ class TestIMessageCatalog(unittest.TestCase): def test_suite(): - return unittest.TestSuite() # Deliberately empty + return unittest.TestSuite() # Deliberately empty diff --git a/src/zope/i18n/tests/test_itranslationdomain.py b/src/zope/i18n/tests/test_itranslationdomain.py index 79c385f..85e4c6a 100644 --- a/src/zope/i18n/tests/test_itranslationdomain.py +++ b/src/zope/i18n/tests/test_itranslationdomain.py @@ -28,16 +28,17 @@ from zope.i18n.interfaces import ITranslationDomain text_type = str if bytes is not str else unicode + @implementer(IUserPreferredLanguages) class Environment(object): - def __init__(self, langs=()): self.langs = langs def getPreferredLanguages(self): return self.langs + class TestITranslationDomain(PlacelessSetup): # This should be overwritten by every class that inherits this test @@ -108,4 +109,4 @@ class TestITranslationDomain(PlacelessSetup): def test_suite(): - return unittest.TestSuite() # Deliberately empty + return unittest.TestSuite() # Deliberately empty diff --git a/src/zope/i18n/tests/test_negotiator.py b/src/zope/i18n/tests/test_negotiator.py index f8a0336..ff855e2 100644 --- a/src/zope/i18n/tests/test_negotiator.py +++ b/src/zope/i18n/tests/test_negotiator.py @@ -20,6 +20,7 @@ from zope.i18n.interfaces import IUserPreferredLanguages from zope.component.testing import PlacelessSetup from zope.interface import implementer + @implementer(IUserPreferredLanguages) class Env(object): @@ -39,12 +40,12 @@ class NegotiatorTest(PlacelessSetup, unittest.TestCase): def test_findLanguages(self): _cases = ( - (('en','de'), ('en','de','fr'), 'en'), - (('en'), ('it','de','fr'), None), - (('pt-br','de'), ('pt_BR','de','fr'), 'pt_BR'), - (('pt-br','en'), ('pt', 'en', 'fr'), 'pt'), - (('pt-br','en-us', 'de'), ('de', 'en', 'fr'), 'en'), - ) + (('en', 'de'), ('en', 'de', 'fr'), 'en'), + (('en'), ('it', 'de', 'fr'), None), + (('pt-br', 'de'), ('pt_BR', 'de', 'fr'), 'pt_BR'), + (('pt-br', 'en'), ('pt', 'en', 'fr'), 'pt'), + (('pt-br', 'en-us', 'de'), ('de', 'en', 'fr'), 'en'), + ) for user_pref_langs, obj_langs, expected in _cases: env = Env(user_pref_langs) @@ -55,7 +56,8 @@ class NegotiatorTest(PlacelessSetup, unittest.TestCase): def test_suite(): return unittest.TestSuite(( unittest.makeSuite(NegotiatorTest), - )) + )) + if __name__ == '__main__': unittest.main(defaultTest='test_suite') diff --git a/src/zope/i18n/tests/test_plurals.py b/src/zope/i18n/tests/test_plurals.py index d4f57c7..bc97bf3 100644 --- a/src/zope/i18n/tests/test_plurals.py +++ b/src/zope/i18n/tests/test_plurals.py @@ -160,18 +160,18 @@ class TestPlurals(unittest.TestCase): self.assertEqual(catalog.getPluralMessage( 'The item is rated 1/5 star.', 'The item is rated %s/5 stars.', 3.5), - 'The item is rated 3.5/5 stars.') + 'The item is rated 3.5/5 stars.') # It's cast either to an int or a float because of the %s in # the translation string. self.assertEqual(catalog.getPluralMessage( 'There is %d chance.', 'There are %f chances.', 1.5), - 'There are 1.500000 chances.') + 'There are 1.500000 chances.') self.assertEqual(catalog.getPluralMessage( 'There is %d chance.', 'There are %f chances.', 3.5), - 'There are 3.500000 chances.') + 'There are 3.500000 chances.') def test_translate_without_defaults(self): domain = self._getTranslationDomain('en') diff --git a/src/zope/i18n/tests/test_testmessagecatalog.py b/src/zope/i18n/tests/test_testmessagecatalog.py index ce5adc6..df426fc 100644 --- a/src/zope/i18n/tests/test_testmessagecatalog.py +++ b/src/zope/i18n/tests/test_testmessagecatalog.py @@ -15,10 +15,12 @@ import unittest import doctest + def test_suite(): return unittest.TestSuite(( doctest.DocFileSuite('../testmessagecatalog.rst') )) + if __name__ == '__main__': unittest.main(defaultTest='test_suite') diff --git a/src/zope/i18n/tests/test_translationdomain.py b/src/zope/i18n/tests/test_translationdomain.py index f8efbd9..550ec85 100644 --- a/src/zope/i18n/tests/test_translationdomain.py +++ b/src/zope/i18n/tests/test_translationdomain.py @@ -18,7 +18,7 @@ import os from zope.i18n.translationdomain import TranslationDomain from zope.i18n.gettextmessagecatalog import GettextMessageCatalog from zope.i18n.tests.test_itranslationdomain import \ - TestITranslationDomain, Environment + TestITranslationDomain, Environment from zope.i18nmessageid import MessageFactory from zope.i18n.interfaces import ITranslationDomain diff --git a/src/zope/i18n/tests/test_zcml.py b/src/zope/i18n/tests/test_zcml.py index 52ee437..e04362d 100644 --- a/src/zope/i18n/tests/test_zcml.py +++ b/src/zope/i18n/tests/test_zcml.py @@ -37,6 +37,7 @@ template = """\ %s """ + class DirectivesTest(PlacelessSetup, unittest.TestCase): # This test suite needs the [zcml] and [compile] extra dependencies diff --git a/src/zope/i18n/tests/testi18nawareobject.py b/src/zope/i18n/tests/testi18nawareobject.py index 21a61f4..996416b 100644 --- a/src/zope/i18n/tests/testi18nawareobject.py +++ b/src/zope/i18n/tests/testi18nawareobject.py @@ -54,6 +54,7 @@ class I18nAwareContentObject(object): # ############################################################ + class AbstractTestII18nAwareMixin(object): def setUp(self): @@ -73,7 +74,8 @@ class AbstractTestII18nAwareMixin(object): self.assertEqual(self.object.getDefaultLanguage(), 'lt') def testGetAvailableLanguages(self): - self.assertEqual(sorted(self.object.getAvailableLanguages()), ['en', 'fr', 'lt']) + self.assertEqual(sorted(self.object.getAvailableLanguages()), [ + 'en', 'fr', 'lt']) class TestI18nAwareObject(AbstractTestII18nAwareMixin, unittest.TestCase): diff --git a/src/zope/i18n/zcml.py b/src/zope/i18n/zcml.py index 4df9ccb..6934485 100644 --- a/src/zope/i18n/zcml.py +++ b/src/zope/i18n/zcml.py @@ -45,14 +45,14 @@ class IRegisterTranslationsDirective(Interface): title=u"Directory", description=u"Directory containing the translations", required=True - ) + ) domain = TextLine( title=u"Domain", description=(u"Translation domain to register. If not specified, " u"all domains found in the directory are registered"), required=False - ) + ) def allow_language(lang): -- cgit v1.2.1