diff --git a/tests/test_extract.py b/tests/test_extract.py index b9a3075..a74a576 100644 --- a/tests/test_extract.py +++ b/tests/test_extract.py @@ -10,7 +10,7 @@ import sys sys.path.append('../') -from StringIO import StringIO +from io import StringIO import unittest from tornadobabel.extract import extract_tornado diff --git a/tornadobabel/extract.py b/tornadobabel/extract.py index e30f7ee..90c6bdc 100644 --- a/tornadobabel/extract.py +++ b/tornadobabel/extract.py @@ -66,7 +66,7 @@ def extract_from_node(expression, gettext_functions=None): gettext_functions = GETTEXT_FUNCTIONS for node in ast.walk(ast.parse(expression.expression)): - # Recursively walk through all descendant nodes + # Recursively walk through all descendant nodes if isinstance(node, ast.Call): # If the type is a function call if not ( @@ -83,9 +83,9 @@ def extract_from_node(expression, gettext_functions=None): for arg in node.keywords: strings.append(None) - if node.starargs is not None: + if hasattr(node, 'startags') and node.starargs: strings.append(None) - if node.kwargs is not None: + if hasattr(node, 'kwargs') and node.kwargs: strings.append(None) if len(strings) == 1: @@ -110,14 +110,15 @@ def extract_tornado(fileobj, keywords, comment_tags, options): :return: an iterator over ``(lineno, funcname, message, comments)`` tuples :rtype: ``iterator`` """ + filename = fileobj.name if hasattr(fileobj, 'name') else options.get('name', '') template = DummyTemplate( fileobj.read(), - file.name or options.get('name', ''), + filename, ) for node in walk(template.file): if isinstance(node, _Expression): for lineno, func, message in extract_from_node(node): - # TODO: Implement the comment feature, right now an empty + # TODO: Implement the comment feature, right now an empty # iterable is returned yield lineno, func, message, [] diff --git a/tornadobabel/locale.py b/tornadobabel/locale.py index 86ab055..fbe6e4b 100644 --- a/tornadobabel/locale.py +++ b/tornadobabel/locale.py @@ -4,7 +4,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The locale support of tornado as such is pretty basic and does not offer - support for merging translation catalogs and several other features most + support for merging translation catalogs and several other features most multi language applications require. This module tries to retain the same API as that of tornado.locale while @@ -19,7 +19,7 @@ :changes: 12/11/23 - E. PASCUAL (Centre Scientifique et Technique du Batiment): - fixed implementation of translations merge process in + fixed implementation of translations merge process in load_gettext_translations """ import gettext @@ -61,7 +61,7 @@ def set_default_locale(code): global _default_locale global _supported_locales _default_locale = code - _supported_locales = frozenset(_translations.keys() + [_default_locale]) + _supported_locales = frozenset(list(_translations.keys()) + [_default_locale]) def load_gettext_translations(directory, domain): @@ -80,11 +80,11 @@ def load_gettext_translations(directory, domain): _translations[lang].merge(translation) else: _translations[lang] = translation - - except Exception, e: + + except Exception as e: logging.error("Cannot load translation for '%s': %s", lang, str(e)) continue - _supported_locales = frozenset(_translations.keys() + [_default_locale]) + _supported_locales = frozenset(list(_translations.keys()) + [_default_locale]) _use_gettext = True logging.info("Supported locales: %s", sorted(_supported_locales)) diff --git a/tornadobabel/mixin.py b/tornadobabel/mixin.py index b372f90..e3694b2 100644 --- a/tornadobabel/mixin.py +++ b/tornadobabel/mixin.py @@ -71,7 +71,7 @@ def get_browser_locale(self, default="en_US"): score = 1.0 locales.append((parts[0], score)) if locales: - locales.sort(key=lambda (l, s): s, reverse=True) + locales.sort(key=lambda l, s: s, reverse=True) codes = [l[0] for l in locales] return locale.get(*codes) return locale.get(default)