aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-01-29 00:23:16 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-01-29 00:23:16 +0000
commit833ef69d6dfbd1202b615b20a6e0c6879dda23c4 (patch)
tree9cef836a6ddd9b58cfd1ffc9c349c801b88b0074
parent7fce0b7e0d76a72b15e4385fec5bb3b8a2cbcfeb (diff)
downloadexternal_python_mako-833ef69d6dfbd1202b615b20a6e0c6879dda23c4.tar.gz
external_python_mako-833ef69d6dfbd1202b615b20a6e0c6879dda23c4.tar.bz2
external_python_mako-833ef69d6dfbd1202b615b20a6e0c6879dda23c4.zip
- support for CRLF templates...whoops ! welcome to all the windows users.
[ticket:16] - cleanup in unit tests
-rw-r--r--CHANGES59
-rw-r--r--lib/mako/codegen.py1
-rw-r--r--lib/mako/lexer.py6
-rw-r--r--test/filters.py2
-rw-r--r--test/lexer.py9
-rw-r--r--test/template.py2
-rw-r--r--test/util.py4
-rw-r--r--test_htdocs/crlf.html15
8 files changed, 64 insertions, 34 deletions
diff --git a/CHANGES b/CHANGES
index 960217e..5ace2ac 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,36 +1,45 @@
0.1.2
-- fix to parsing of code/expression blocks to insure that non-ascii characters, combined
-with a template that indicates a non-standard encoding, are expanded into backslash-escaped
-glyphs before being AST parsed [ticket:11]
-- added module_filename argument to Template to allow specification of a specific module
-file
-- added modulename_callable to TemplateLookup to allow a function to determine module filenames
-(takes filename, uri arguments). used for [ticket:14]
-- added optional input_encoding flag to Template, to allow sending a unicode() object with no
-magic encoding comment
+- fix to parsing of code/expression blocks to insure that non-ascii
+ characters, combined with a template that indicates a non-standard
+ encoding, are expanded into backslash-escaped glyphs before being AST
+ parsed [ticket:11]
+- added module_filename argument to Template to allow specification of a
+ specific module file
+- added modulename_callable to TemplateLookup to allow a function to
+ determine module filenames (takes filename, uri arguments). used for
+ [ticket:14]
+- added optional input_encoding flag to Template, to allow sending a
+ unicode() object with no magic encoding comment
- "expression_filter" argument in <%page> applies only to expressions
-- added "default_filters" argument to Template, TemplateLookup. applies only to expressions,
-gets prepended to "expression_filter" arg from <%page>. defaults to ["unicode"], so that
-all expressions get stringified into u'' by default (this is what Mako already does).
-By setting to [], expressions are passed through raw.
-- added "imports" argument to Template, TemplateLookup. so you can predefine a list of
-import statements at the top of the template. can be used in conjunction with
-default_filters.
-- small fix to local variable propigation for locals that are conditionally declared
+- added "default_filters" argument to Template, TemplateLookup. applies only
+ to expressions, gets prepended to "expression_filter" arg from <%page>.
+ defaults to ["unicode"], so that all expressions get stringified into u''
+ by default (this is what Mako already does). By setting to [], expressions
+ are passed through raw.
+- added "imports" argument to Template, TemplateLookup. so you can predefine
+ a list of import statements at the top of the template. can be used in
+ conjunction with default_filters.
+- support for CRLF templates...whoops ! welcome to all the windows users.
+ [ticket:16]
+- small fix to local variable propigation for locals that are conditionally
+ declared
0.1.1
-- buffet plugin supports string-based templates, allows ToscaWidgets to work [ticket:8]
+- buffet plugin supports string-based templates, allows ToscaWidgets to work
+ [ticket:8]
- AST parsing fixes: fixed TryExcept identifier parsing
-- removed textmate tmbundle from contrib and into separate SVN location; windows users
-cant handle those files, setuptools not very good at "pruning" certain directories
+- removed textmate tmbundle from contrib and into separate SVN location;
+ windows users cant handle those files, setuptools not very good at
+ "pruning" certain directories
- fix so that "cache_timeout" parameter is propigated
-- fix to expression filters so that string conversion (actually unicode) properly
-occurs before filtering
-- better error message when a lookup is attempted with a template that has no lookup
+- fix to expression filters so that string conversion (actually unicode)
+ properly occurs before filtering
+- better error message when a lookup is attempted with a template that has no
+ lookup
- implemented "module" attribute for namespace
- fix to code generation to correctly track multiple defs with the same name
-- "directories" can be passed to TemplateLookup as a scalar in which case it gets
-converted to a list [ticket:9]
+- "directories" can be passed to TemplateLookup as a scalar in which case it
+ gets converted to a list [ticket:9]
0.1.0
diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py
index a18dffc..d17ae64 100644
--- a/lib/mako/codegen.py
+++ b/lib/mako/codegen.py
@@ -357,7 +357,6 @@ class _GenerateRenderMethod(object):
self.printer.writeline("__%s = %s" % (name, name))
cachekey = node_or_pagetag.parsed_attributes.get('cache_key', repr(name))
cacheargs = {}
- print node_or_pagetag
for arg in (('cache_type', 'type'), ('cache_dir', 'data_dir'), ('cache_timeout', 'expiretime')):
val = node_or_pagetag.parsed_attributes.get(arg[0], None)
if val is not None:
diff --git a/lib/mako/lexer.py b/lib/mako/lexer.py
index 5b6e97d..ee3309d 100644
--- a/lib/mako/lexer.py
+++ b/lib/mako/lexer.py
@@ -131,7 +131,7 @@ class Lexer(object):
return self.template
def match_encoding(self):
- match = self.match(r'#.*coding[:=]\s*([-\w.]+).*\n')
+ match = self.match(r'#.*coding[:=]\s*([-\w.]+).*\r?\n')
if match:
return match.group(1)
else:
@@ -209,7 +209,7 @@ class Lexer(object):
(?=</?[%&]) # a substitution or block or call start or end
# - don't consume
|
- (\\\n) # an escaped newline - throw away
+ (\\\r?\n) # an escaped newline - throw away
|
\Z # end of string
)""", re.X | re.S)
@@ -247,7 +247,7 @@ class Lexer(object):
return False
def match_control_line(self):
- match = self.match(r"(?<=^)[\t ]*([%#])[\t ]*([^\n]*)(?:\n|\Z)", re.M)
+ match = self.match(r"(?<=^)[\t ]*([%#])[\t ]*([^\r\n]*)(?:\r?\n|\Z)", re.M)
if match:
operator = match.group(1)
text = match.group(2)
diff --git a/test/filters.py b/test/filters.py
index d9ecb25..314a6bc 100644
--- a/test/filters.py
+++ b/test/filters.py
@@ -50,7 +50,7 @@ class FilterTest(unittest.TestCase):
t = Template("""
trim this string: ${" some string to trim " | filters.trim} continue\
""", imports=["from mako import filters"])
- print t.code
+ #print t.code
assert t.render().strip()=="trim this string: some string to trim continue"
def test_custom_default(self):
diff --git a/test/lexer.py b/test/lexer.py
index 482c899..091bde5 100644
--- a/test/lexer.py
+++ b/test/lexer.py
@@ -2,6 +2,8 @@ import unittest
from mako.lexer import Lexer
from mako import exceptions
+from util import flatten_result, result_lines
+from mako.template import Template
class LexerTest(unittest.TestCase):
def test_text_and_tag(self):
@@ -332,6 +334,11 @@ text text la la
nodes = Lexer(template).parse()
assert repr(nodes) == r"""TemplateNode({}, [NamespaceTag('namespace', {'name': 'foo', 'file': 'somefile.html'}, (1, 1), []), Text('\n', (1, 46)), Comment('inherit from foobar.html', (2, 1)), InheritTag('inherit', {'file': 'foobar.html'}, (3, 1), []), Text('\n\n', (3, 31)), DefTag('def', {'name': 'header()'}, (5, 1), ["Text('\\n <div>header</div>\\n', (5, 23))"]), Text('\n', (7, 8)), DefTag('def', {'name': 'footer()'}, (8, 1), ["Text('\\n <div> footer</div>\\n', (8, 23))"]), Text('\n\n<table>\n', (10, 8)), ControlLine('for', 'for j in data():', False, (13, 1)), Text(' <tr>\n', (14, 1)), ControlLine('for', 'for x in j:', False, (15, 1)), Text(' <td>Hello ', (16, 1)), Expression('x', ['h'], (16, 23)), Text('</td>\n', (16, 30)), ControlLine('for', 'endfor', True, (17, 1)), Text(' </tr>\n', (18, 1)), ControlLine('for', 'endfor', True, (19, 1)), Text('</table>\n', (20, 1))])"""
-
+ def test_crlf(self):
+ template = file("./test_htdocs/crlf.html").read()
+ nodes = Lexer(template).parse()
+ assert repr(nodes) == r"""TemplateNode({}, [Text('<html>\r\n\r\n', (1, 1)), PageTag('page', {}, (3, 1), []), Text('\r\n\r\nlike the name says.\r\n\r\n', (3, 9)), ControlLine('for', 'for x in [1,2,3]:', False, (7, 1)), Text(' ', (8, 1)), Expression('x', [], (8, 9)), Text('', (8, 13)), ControlLine('for', 'endfor', True, (9, 1)), Text('\r\n', (10, 1)), DefTag('def', {'name': 'hi()'}, (11, 1), ["Text('\\r\\n hi!\\r\\n', (11, 19))"]), Text('\r\n\r\n</html>', (13, 8))])"""
+ assert flatten_result(Template(template).render()) == """<html> like the name says. 1 2 3 </html>"""
+
if __name__ == '__main__':
unittest.main()
diff --git a/test/template.py b/test/template.py
index 5b613ce..67311f8 100644
--- a/test/template.py
+++ b/test/template.py
@@ -113,7 +113,7 @@ class PageArgsTest(unittest.TestCase):
this is page, ${x}, ${y}, ${z}, ${w}
""")
- print template.code
+ #print template.code
assert flatten_result(template.render(x=5, y=10, w=17)) == "this is page, 5, 10, 7, 17"
def test_overrides_builtins(self):
diff --git a/test/util.py b/test/util.py
index e1e3c3b..605269f 100644
--- a/test/util.py
+++ b/test/util.py
@@ -1,7 +1,7 @@
import re
def flatten_result(result):
- return re.sub(r'[\s\n]+', ' ', result).strip()
+ return re.sub(r'[\s\r\n]+', ' ', result).strip()
def result_lines(result):
- return [x.strip() for x in re.sub(r' +', ' ', result).split('\n') if x.strip() != ''] \ No newline at end of file
+ return [x.strip() for x in re.split(r'\r?\n', re.sub(r' +', ' ', result)) if x.strip() != ''] \ No newline at end of file
diff --git a/test_htdocs/crlf.html b/test_htdocs/crlf.html
new file mode 100644
index 0000000..4507f41
--- /dev/null
+++ b/test_htdocs/crlf.html
@@ -0,0 +1,15 @@
+<html>
+
+<%page/>
+
+like the name says.
+
+ % for x in [1,2,3]:
+ ${x}\
+ % endfor
+
+<%def name="hi()">
+ hi!
+</%def>
+
+</html> \ No newline at end of file