[Python-modules-commits] [mako] 01/03: Import mako_1.0.3+ds1.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Sat Oct 31 22:56:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository mako.
commit d43f9b6428cf19a5a6cc7ce897707fa6c4b3a0e7
Author: Piotr Ożarowski <piotr at debian.org>
Date: Sat Oct 31 23:26:40 2015 +0100
Import mako_1.0.3+ds1.orig.tar.gz
---
PKG-INFO | 2 +-
doc/_sources/changelog.txt | 12 ++++++++++++
doc/build/changelog.rst | 12 ++++++++++++
mako/__init__.py | 2 +-
mako/ext/extract.py | 12 +++++++++---
mako/lookup.py | 3 +++
test/ext/test_babelplugin.py | 20 ++++++++++++++++----
test/templates/gettext_cp1251.mako | 1 +
test/templates/gettext_utf8.mako | 1 +
9 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index fb5f608..6ee793f 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: Mako
-Version: 1.0.2
+Version: 1.0.3
Summary: A super-fast templating language that borrows the best ideas from the existing templating languages.
Home-page: http://www.makotemplates.org/
Author: Mike Bayer
diff --git a/doc/_sources/changelog.txt b/doc/_sources/changelog.txt
index c932495..9cf8089 100644
--- a/doc/_sources/changelog.txt
+++ b/doc/_sources/changelog.txt
@@ -6,6 +6,18 @@ Changelog
===
.. changelog::
+ :version: 1.0.3
+ :released: Tue Oct 27 2015
+
+ .. change::
+ :tags: bug, babel
+ :pullreq: bitbucket:21
+
+ Fixed an issue where the Babel plugin would not handle a translation
+ symbol that contained non-ascii characters. Pull request courtesy
+ Roman Imankulov.
+
+.. changelog::
:version: 1.0.2
:released: Wed Aug 26 2015
diff --git a/doc/build/changelog.rst b/doc/build/changelog.rst
index c932495..9cf8089 100644
--- a/doc/build/changelog.rst
+++ b/doc/build/changelog.rst
@@ -6,6 +6,18 @@ Changelog
===
.. changelog::
+ :version: 1.0.3
+ :released: Tue Oct 27 2015
+
+ .. change::
+ :tags: bug, babel
+ :pullreq: bitbucket:21
+
+ Fixed an issue where the Babel plugin would not handle a translation
+ symbol that contained non-ascii characters. Pull request courtesy
+ Roman Imankulov.
+
+.. changelog::
:version: 1.0.2
:released: Wed Aug 26 2015
diff --git a/mako/__init__.py b/mako/__init__.py
index 59d4060..74526ec 100644
--- a/mako/__init__.py
+++ b/mako/__init__.py
@@ -5,4 +5,4 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-__version__ = '1.0.2'
+__version__ = '1.0.3'
diff --git a/mako/ext/extract.py b/mako/ext/extract.py
index 313c088..8dd2e96 100644
--- a/mako/ext/extract.py
+++ b/mako/ext/extract.py
@@ -16,6 +16,7 @@ class MessageExtractor(object):
def extract_nodes(self, nodes):
translator_comments = []
in_translator_comments = False
+ input_encoding = self.config['encoding'] or 'ascii'
comment_tags = list(
filter(None, re.split(r'\s+', self.config['comment-tags'])))
@@ -76,13 +77,18 @@ class MessageExtractor(object):
comment[1] for comment in translator_comments]
if isinstance(code, compat.text_type):
- code = code.encode('ascii', 'backslashreplace')
+ code = code.encode(input_encoding, 'backslashreplace')
used_translator_comments = False
- code = compat.byte_buffer(code)
+ # We add extra newline to work around a pybabel bug
+ # (see python-babel/babel#274, parse_encoding dies if the first
+ # input string of the input is non-ascii)
+ # Also, because we added it, we have to subtract one from
+ # node.lineno
+ code = compat.byte_buffer(compat.b('\n') + code)
for message in self.process_python(
- code, node.lineno, translator_strings):
+ code, node.lineno - 1, translator_strings):
yield message
used_translator_comments = True
diff --git a/mako/lookup.py b/mako/lookup.py
index 794d853..e6dff9d 100644
--- a/mako/lookup.py
+++ b/mako/lookup.py
@@ -248,6 +248,9 @@ class TemplateLookup(TemplateCollection):
except KeyError:
u = re.sub(r'^\/+', '', uri)
for dir in self.directories:
+ # make sure the path seperators are posix - os.altsep is empty
+ # on POSIX and cannot be used.
+ dir = dir.replace(os.path.sep, posixpath.sep)
srcfile = posixpath.normpath(posixpath.join(dir, u))
if os.path.isfile(srcfile):
return self._load(srcfile, uri)
diff --git a/test/ext/test_babelplugin.py b/test/ext/test_babelplugin.py
index c66260e..3658c50 100644
--- a/test/ext/test_babelplugin.py
+++ b/test/ext/test_babelplugin.py
@@ -6,11 +6,10 @@ from mako import compat
try:
import babel.messages.extract as babel
-except:
- babel = None
-
-if babel is not None:
from mako.ext.babelplugin import extract
+
+except ImportError:
+ babel = None
def skip():
@@ -79,3 +78,16 @@ class ExtractMakoTestCase(TemplateTest):
(99, '_', 'No action at a distance.', []),
]
self.assertEqual(expected, messages)
+
+ @skip()
+ def test_extract_utf8(self):
+ mako_tmpl = open(os.path.join(template_base, 'gettext_utf8.mako'), 'rb')
+ message = next(extract(mako_tmpl, set(['_', None]), [], {'encoding': 'utf-8'}))
+ assert message == (1, '_', u'K\xf6ln', [])
+
+ @skip()
+ def test_extract_cp1251(self):
+ mako_tmpl = open(os.path.join(template_base, 'gettext_cp1251.mako'), 'rb')
+ message = next(extract(mako_tmpl, set(['_', None]), [], {'encoding': 'cp1251'}))
+ # "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
+ assert message == (1, '_', u'\u0442\u0435\u0441\u0442', [])
diff --git a/test/templates/gettext_cp1251.mako b/test/templates/gettext_cp1251.mako
new file mode 100644
index 0000000..9341d93
--- /dev/null
+++ b/test/templates/gettext_cp1251.mako
@@ -0,0 +1 @@
+${_("����")}
diff --git a/test/templates/gettext_utf8.mako b/test/templates/gettext_utf8.mako
new file mode 100644
index 0000000..761f946
--- /dev/null
+++ b/test/templates/gettext_utf8.mako
@@ -0,0 +1 @@
+${_("Köln")}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/mako.git
More information about the Python-modules-commits
mailing list