Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated library to Python 3 and replaced tabs by spaces as well as d… #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions tornadobabel/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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:
Expand All @@ -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', '<string>')
template = DummyTemplate(
fileobj.read(),
file.name or options.get('name', '<string>'),
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, []
12 changes: 6 additions & 6 deletions tornadobabel/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion tornadobabel/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down