summaryrefslogtreecommitdiff
path: root/mako/ext/extract.py
diff options
context:
space:
mode:
Diffstat (limited to 'mako/ext/extract.py')
-rw-r--r--mako/ext/extract.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/mako/ext/extract.py b/mako/ext/extract.py
index ad2348a..66e3c19 100644
--- a/mako/ext/extract.py
+++ b/mako/ext/extract.py
@@ -4,14 +4,17 @@
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
+from io import BytesIO
+from io import StringIO
import re
-from mako import compat
from mako import lexer
from mako import parsetree
-class MessageExtractor(object):
+class MessageExtractor:
+ use_bytes = True
+
def process_file(self, fileobj):
template_node = lexer.Lexer(
fileobj.read(), input_encoding=self.config["encoding"]
@@ -90,7 +93,7 @@ class MessageExtractor(object):
comment[1] for comment in translator_comments
]
- if isinstance(code, compat.text_type):
+ if isinstance(code, str) and self.use_bytes:
code = code.encode(input_encoding, "backslashreplace")
used_translator_comments = False
@@ -99,7 +102,10 @@ class MessageExtractor(object):
# 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)
+ if self.use_bytes:
+ code = BytesIO(b"\n" + code)
+ else:
+ code = StringIO("\n" + code)
for message in self.process_python(
code, node.lineno - 1, translator_strings