cubictemp-2.0/0000755000175000017500000000000010774552246011762 5ustar aldoaldocubictemp-2.0/doc/0000755000175000017500000000000010774552246012527 5ustar aldoaldocubictemp-2.0/doc/subs.html0000644000175000017500000001151510774552236014373 0ustar aldoaldo Cubictemp Manual - Tags

Cubictemp - Tags

Tags and Expressions

Cubictemp evaluates expressions between tag delimiters as expressions in the specified namespace. The result is converted to a string, and placed in the rendered template. There are two flavours of delimiters - escaped:

@!...!@

and unescaped:

$!...!$

In Python, an expression can be thought of as anything that can be assigned to a variable. Arithmetic operators, boolean operators, parentheses for grouping, method/function calls, object instantiation and conditional expressions are all valid components of expressions. Python statements include things like while, print, variable assignment and full if blocks. Cubictemp allows only expressions in subtitution tags.

Example

Template:

@!foo!@ times two is @!foo*2!@
@!foo!@ squared is @!foo*foo!@
@!"yes" if (1==2) else "no"!@
key is @!mydict["key"]!@

Code:

import cubictemp
print cubictemp.File(
            "template",
            foo=3,
            mydict=dict(key="value")
        )

Output:

3 times two is 6
3 squared is 9
no
key is value

Escaping

In an escaped substitution tag, the &, <, >, ", ’ characters are converted to their corresponding HTML escape sequences. Always use the escaped substitution syntax if you can. When you really need to place HTML in a substitution tag, make sure you carefully evaluate the application context to make sure that users cannot inject malicious data.

Example

import cubictemp
print cubictemp.Template(
        "@!x!@ $!x!$",
        x = "<H1>foo</H1>"
    )

... will print:

<H1>foo</H1> &lt;H1&gt;foo&lt;/H1&gt;

Controlling Escaping

Sometimes, it is handy to be able to construct objects that bypass Cubictemp's escaping mechanism, regardless of the type of tag in which they occur. You can signal this to cubictemp by giving the object a special attribute _cubictemp_unescaped which evaluates to true.

Template, File, and named block objects all have a _cubictemp_unescaped attribute, so none of these objects will be escaped when referenced inside an escaped tag.

Copyright Nullcube 2008

cubictemp-2.0/doc/static/0000755000175000017500000000000010774552246014016 5ustar aldoaldocubictemp-2.0/doc/static/yui/0000755000175000017500000000000010774552246014624 5ustar aldoaldocubictemp-2.0/doc/static/yui/base/0000755000175000017500000000000010774552246015536 5ustar aldoaldocubictemp-2.0/doc/static/yui/base/base.css0000644000175000017500000000335510774552236017167 0ustar aldoaldo/* Copyright (c) 2007, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.4.1 */ /* base.css, part of YUI's CSS Foundation */ h1 { /*18px via YUI Fonts CSS foundation*/ font-size:138.5%; } h2 { /*16px via YUI Fonts CSS foundation*/ font-size:123.1%; } h3 { /*14px via YUI Fonts CSS foundation*/ font-size:108%; } h1,h2,h3 { /* top & bottom margin based on font size */ margin:1em 0; } h1,h2,h3,h4,h5,h6,strong { /*bringing boldness back to headers and the strong element*/ font-weight:bold; } abbr,acronym { /*indicating to users that more info is available */ border-bottom:1px dotted #000; cursor:help; } em { /*bringing italics back to the em element*/ font-style:italic; } blockquote,ul,ol,dl { /*giving blockquotes and lists room to breath*/ margin:1em; } ol,ul,dl { /*bringing lists on to the page with breathing room */ margin-left:2em; } ol li { /*giving OL's LIs generated numbers*/ list-style: decimal outside; } ul li { /*giving UL's LIs generated disc markers*/ list-style: disc outside; } dl dd { /*giving UL's LIs generated numbers*/ margin-left:1em; } th,td { /*borders and padding to make the table readable*/ border:1px solid #000; padding:.5em; } th { /*distinguishing table headers from data cells*/ font-weight:bold; text-align:center; } caption { /*coordinated margin to match cell's padding*/ margin-bottom:.5em; /*centered so it doesn't blend in to other content*/ text-align:center; } p,fieldset,table,pre { /*so things don't run into each other*/ margin-bottom:1em; } /* setting a consistent width, 160px; control of type=file still not possible */ input[type=text],input[type=password],textarea{width:12.25em;*width:11.9em;} cubictemp-2.0/doc/static/yui/grids/0000755000175000017500000000000010774552246015734 5ustar aldoaldocubictemp-2.0/doc/static/yui/grids/grids.css0000644000175000017500000000623510774552236017563 0ustar aldoaldo/* Copyright (c) 2007, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.2.1 */ /* for all templates and grids */ body{text-align:center;} #ft{clear:both;} /**/ /* 750 centered, and backward compatibility */ #doc,#doc2,#doc3,.yui-t1,.yui-t2,.yui-t3,.yui-t4,.yui-t5,.yui-t6,.yui-t7 { margin:auto;text-align:left; width:57.69em;*width:56.3em;min-width:750px;} /* 950 centered */ #doc2 { width:73.074em;*width:71.313em;min-width:950px;} /* 100% with 10px viewport side matting */ #doc3 { margin:auto 10px; /* not for structure, but so content doesn't bleed to edge */ width:auto;} /* below required for all fluid grids; adjust widths and margins above accordingly */ /* to preserve source-order independence for Gecko */ .yui-b{position:relative;} .yui-b{_position:static;} /* for IE < 7 */ #yui-main .yui-b{position:static;} #yui-main {width:100%;} .yui-t1 #yui-main, .yui-t2 #yui-main, .yui-t3 #yui-main{float:right;margin-left:-25em;/* IE: preserve layout at narrow widths */} .yui-t4 #yui-main, .yui-t5 #yui-main, .yui-t6 #yui-main{float:left;margin-right:-25em;/* IE: preserve layout at narrow widths */} .yui-t1 .yui-b { float:left; width:12.3207em;*width:12.0106em;} .yui-t1 #yui-main .yui-b{ margin-left:13.3207em;*margin-left:13.0106em; } .yui-t2 .yui-b { float:left; width:13.8456em;*width:13.512em;} .yui-t2 #yui-main .yui-b { margin-left:14.8456em;*margin-left:14.512em; } .yui-t3 .yui-b { float:left; width:23.0759em;*width:22.52em;} .yui-t3 #yui-main .yui-b { margin-left:24.0759em;*margin-left:23.52em; } .yui-t4 .yui-b { float:right; width:13.8456em;*width:13.512em;} .yui-t4 #yui-main .yui-b { margin-right:14.8456em;*margin-right:14.512em; } .yui-t5 .yui-b { float:right; width:18.4608em;*width:18.016em;} .yui-t5 #yui-main .yui-b { margin-right:19.4608em;*margin-right:19.016em; } .yui-t6 .yui-b { float:right; width:23.0759em;*width:22.52em;} .yui-t6 #yui-main .yui-b { margin-right:24.0759em;*margin-right:23.52em; } .yui-t7 #yui-main .yui-b { display:block;margin:0 0 1em 0; } #yui-main .yui-b {float:none;width:auto;} /* GRIDS (not TEMPLATES) */ .yui-g .yui-u, .yui-g .yui-g, .yui-gc .yui-u, .yui-gc .yui-g .yui-u, .yui-ge .yui-u, .yui-gf .yui-u{float:right;display:inline;} .yui-g div.first, .yui-gc div.first, .yui-gc div.first div.first, .yui-gd div.first, .yui-ge div.first, .yui-gf div.first{float:left;} .yui-g .yui-u, .yui-g .yui-g{width:49.1%;} .yui-g .yui-g .yui-u, .yui-gc .yui-g .yui-u {width:48.1%;} .yui-gb .yui-u, .yui-gc .yui-u, .yui-gd .yui-u{float:left;margin-left:2%;*margin-left:1.895%;width:32%;} .yui-gb div.first, .yui-gc div.first, .yui-gd div.first{margin-left:0;} .yui-gc div.first, .yui-gd .yui-u{width:66%;} .yui-gd div.first{width:32%;} .yui-ge .yui-u{width:24%;} .yui-ge div.first, .yui-gf .yui-u{width:74.2%;} .yui-gf div.first{width:24%;} .yui-ge div.first{width:74.2%;} #bd:after, .yui-g:after, .yui-gb:after, .yui-gc:after, .yui-gd:after, .yui-ge:after, .yui-gf:after{content:".";display:block;height:0;clear:both;visibility:hidden;} #bd, .yui-g, .yui-gb, .yui-gc, .yui-gd, .yui-ge, .yui-gf{zoom:1;}cubictemp-2.0/doc/static/yui/reset/0000755000175000017500000000000010774552246015746 5ustar aldoaldocubictemp-2.0/doc/static/yui/reset/reset.css0000644000175000017500000000112310774552236017576 0ustar aldoaldo/* Copyright (c) 2007, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.2.1 */ body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;} table{border-collapse:collapse;border-spacing:0;} fieldset,img{border:0;} address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;} ol,ul {list-style:none;} caption,th {text-align:left;} h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;} q:before,q:after{content:'';} abbr,acronym {border:0;}cubictemp-2.0/doc/static/yui/fonts/0000755000175000017500000000000010774552246015755 5ustar aldoaldocubictemp-2.0/doc/static/yui/fonts/fonts.css0000644000175000017500000000142410774552236017620 0ustar aldoaldo/* Copyright (c) 2007, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.2.1 */ /** * Percents could work for IE, but for backCompat purposes, we are using keywords. * x-small is for IE6/7 quirks mode. * */ body {font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;} table {font-size:inherit;font:100%;} /** * 99% for safari; 100% is too large */ select, input, textarea {font:99% arial,helvetica,clean,sans-serif;} /** * Bump up !IE to get to 13px equivalent */ pre, code {font:115% monospace;*font-size:100%;} /** * Default line-height based on font-size rather than "computed-value" * see: http://www.w3.org/TR/CSS21/visudet.html#line-height */ body * {line-height:1.22em;} cubictemp-2.0/doc/static/style.css0000644000175000017500000000370310774552236015672 0ustar aldoaldo .pageindex ul { list-style-image:none; list-style-position:outside; list-style-type:none; margin: 0px; } .pageindex li { list-style-image:none; list-style-position:outside; list-style-type:none; margin: 0; } .pageindex li.active { padding-left: 4px; border-left: 5px solid #ff0000; } .pageindex li.inactive{ border-left: none; margin-left: 9px; } .pageindex li li a { display: block; background-color: transparent; margin: 0; border-top: none; border-bottom: none; } .pageindex ul ul { margin-left: 20px; padding: 0; list-style-type: none; } .sourceindex { margin-left: 100px; } .sourceindex ul { list-style-image:none; list-style-position:outside; list-style-type:none; margin-left: 0px; margin-bottom: 0px; } .sourceindex a { font-size: 18px; color: #aaaadd; } .sourceindex a:hover { color: #aaffff; } .sourceindex li { margin: 0; } .sourceindex li.active { padding-left: 10px; border-left: 5px solid #ff0000; } .sourceindex li.inactive{ border-left: none; margin-left: 15px; } .sourceindex li li a { display: block; background-color: transparent; margin: 0; border-top: none; border-bottom: none; } .sourceindex ul ul { margin-left: 50px; padding: 0; list-style-type: none; } /* * Countershape Code Generation */ .grokdoc_class { margin-bottom: 15px; } .grokdoc_class_title { margin-bottom: 5px; } .grokdoc_function_title { margin-bottom: 5px; } .grokdoc_description { padding-left: 40px; } .grokdoc pre { margin: 0px; } .grokdoc_description p { margin-top: 5px; margin-bottom: 5px; } .grokdoc_vartable { border-style: solid; border-color: #c0c0c0; border-width: 1px; } .grokdoc_vartable td { border-style: solid; border-color: #c0c0c0; border-width: 1px; padding: 5px; } .grokdoc_varname { } cubictemp-2.0/doc/admin.html0000644000175000017500000000540410774552237014510 0ustar aldoaldo Cubictemp Manual - Administrivia

Cubictemp - Administrivia

Contact

Please send any comments, suggestions and bug reports to dev@nullcube.com.

License

This project is distributed under the MIT license.


Copyright (c) 2007, Nullcube Pty Ltd
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright Nullcube 2008

cubictemp-2.0/doc/docstyle.css0000644000175000017500000000234710774552237015075 0ustar aldoaldo .pageindex a { color: #437095; } .pageindex a:hover { color: #437095; } body { font-family:Georgia,serif; font-size:15px; } #hd h1 { font-size: 2em; font-weight: bold; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #aaaaaa; margin-bottom: 15px; } .highlight pre { border-bottom: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; padding: 10px; background: #F8F8F8 none repeat scroll 0% 0%; margin-bottom: 10px; overflow: auto; } .grokdoc { background: transparent !important; } .grokdoc_module { background: #F8F8F8; padding: 5px; } .grokdoc_vartable { margin-bottom: 10px; } .grokdoc_vartable p { margin: 0px; } .grokdoc_class { background: #F8F8F8; } .output { border-bottom: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; padding: 10px; background: #F8F8F8 none repeat scroll 0% 0%; margin-bottom: 10px; overflow: auto; } #ft { padding: 10px 15px 17px 10px; font-size: 0.8em; } dl { margin: 0px; margin-top: 5px; } dt { font-weight: bold; } cubictemp-2.0/doc/processors.html0000644000175000017500000000676610774552237015636 0ustar aldoaldo Cubictemp Manual - Processors

Cubictemp - Processors

Processors

One common use for blocks is to declare a named block, and then perform some transformation on it when it is inserted back into the document. One way to do this is to write a transformation function that takes a string and returns a string, and pass it straight in the template namespace for use:

<!--(block codesnippet)-->
    for i in range(10):
        print i
<!--(end)-->
@!syntaxHighlight(codesnippet)!@

Cubictemp has a special processor syntax to facilitate this use pattern.

<!--(block codesnippet|syntaxHighlight)-->
    for i in range(10):
        print i
<!--(end)-->
@!codesnippet!@

Using processors is similar to using pipes in Unix shells. Any callable that takes a string and returns a string can be used as a processor. Processors can be chained together:

<!--(block codesnippet|trimWhitespace|syntaxHighlight)-->
    for i in range(10):
        print i
<!--(end)-->
@!codesnippet!@

In this case, trimWhitespace would be run first, then syntaxHighlight. The processor declarations are just expressions evaluated in the namespace of the block declaration. Processors should be passed in to a template namespace for use.

Anonymous Blocks

There is one further refinement to the block syntax. In the examples above, naming the block is redundant - it is created, and then immediately substituted into the template. Anonymous blocks remove this redundancy. An anonymous block is immediately inserted into he template at its place of definition. The following template is equivalent to the last definition above:

<!--(block|trimWhitespace|syntaxHighlight)-->
    for i in range(10):
        print i
<!--(end)-->

Copyright Nullcube 2008

cubictemp-2.0/doc/syntax.css0000644000175000017500000001642610774552237014600 0ustar aldoaldo.highlight { background: #f8f8f8; } .highlight .c { color: #408080; font-style: italic } /* Comment */ .highlight .err { border: 1px solid #FF0000 } /* Error */ .highlight .k { color: #008000; font-weight: bold } /* Keyword */ .highlight .o { color: #666666 } /* Operator */ .highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */ .highlight .cp { color: #BC7A00 } /* Comment.Preproc */ .highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */ .highlight .cs { color: #408080; font-style: italic } /* Comment.Special */ .highlight .gd { color: #A00000 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #FF0000 } /* Generic.Error */ .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ .highlight .gi { color: #00A000 } /* Generic.Inserted */ .highlight .go { color: #808080 } /* Generic.Output */ .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ .highlight .gt { color: #0040D0 } /* Generic.Traceback */ .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ .highlight .kp { color: #008000 } /* Keyword.Pseudo */ .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #B00040 } /* Keyword.Type */ .highlight .m { color: #666666 } /* Literal.Number */ .highlight .s { color: #BA2121 } /* Literal.String */ .highlight .na { color: #7D9029 } /* Name.Attribute */ .highlight .nb { color: #008000 } /* Name.Builtin */ .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ .highlight .no { color: #880000 } /* Name.Constant */ .highlight .nd { color: #AA22FF } /* Name.Decorator */ .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ .highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0000FF } /* Name.Function */ .highlight .nl { color: #A0A000 } /* Name.Label */ .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #19177C } /* Name.Variable */ .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mf { color: #666666 } /* Literal.Number.Float */ .highlight .mh { color: #666666 } /* Literal.Number.Hex */ .highlight .mi { color: #666666 } /* Literal.Number.Integer */ .highlight .mo { color: #666666 } /* Literal.Number.Oct */ .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ .highlight .sc { color: #BA2121 } /* Literal.String.Char */ .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ .highlight .s2 { color: #BA2121 } /* Literal.String.Double */ .highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ .highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ .highlight .sx { color: #008000 } /* Literal.String.Other */ .highlight .sr { color: #BB6688 } /* Literal.String.Regex */ .highlight .s1 { color: #BA2121 } /* Literal.String.Single */ .highlight .ss { color: #19177C } /* Literal.String.Symbol */ .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ .highlight .vc { color: #19177C } /* Name.Variable.Class */ .highlight .vg { color: #19177C } /* Name.Variable.Global */ .highlight .vi { color: #19177C } /* Name.Variable.Instance */ .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ .grokdoc { background: #f8f8f8; } .grokdoc .c { color: #408080; font-style: italic } /* Comment */ .grokdoc .err { border: 1px solid #FF0000 } /* Error */ .grokdoc .k { color: #008000; font-weight: bold } /* Keyword */ .grokdoc .o { color: #666666 } /* Operator */ .grokdoc .cm { color: #408080; font-style: italic } /* Comment.Multiline */ .grokdoc .cp { color: #BC7A00 } /* Comment.Preproc */ .grokdoc .c1 { color: #408080; font-style: italic } /* Comment.Single */ .grokdoc .cs { color: #408080; font-style: italic } /* Comment.Special */ .grokdoc .gd { color: #A00000 } /* Generic.Deleted */ .grokdoc .ge { font-style: italic } /* Generic.Emph */ .grokdoc .gr { color: #FF0000 } /* Generic.Error */ .grokdoc .gh { color: #000080; font-weight: bold } /* Generic.Heading */ .grokdoc .gi { color: #00A000 } /* Generic.Inserted */ .grokdoc .go { color: #808080 } /* Generic.Output */ .grokdoc .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ .grokdoc .gs { font-weight: bold } /* Generic.Strong */ .grokdoc .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ .grokdoc .gt { color: #0040D0 } /* Generic.Traceback */ .grokdoc .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ .grokdoc .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ .grokdoc .kp { color: #008000 } /* Keyword.Pseudo */ .grokdoc .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ .grokdoc .kt { color: #B00040 } /* Keyword.Type */ .grokdoc .m { color: #666666 } /* Literal.Number */ .grokdoc .s { color: #BA2121 } /* Literal.String */ .grokdoc .na { color: #7D9029 } /* Name.Attribute */ .grokdoc .nb { color: #008000 } /* Name.Builtin */ .grokdoc .nc { color: #0000FF; font-weight: bold } /* Name.Class */ .grokdoc .no { color: #880000 } /* Name.Constant */ .grokdoc .nd { color: #AA22FF } /* Name.Decorator */ .grokdoc .ni { color: #999999; font-weight: bold } /* Name.Entity */ .grokdoc .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ .grokdoc .nf { color: #0000FF } /* Name.Function */ .grokdoc .nl { color: #A0A000 } /* Name.Label */ .grokdoc .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ .grokdoc .nt { color: #008000; font-weight: bold } /* Name.Tag */ .grokdoc .nv { color: #19177C } /* Name.Variable */ .grokdoc .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ .grokdoc .w { color: #bbbbbb } /* Text.Whitespace */ .grokdoc .mf { color: #666666 } /* Literal.Number.Float */ .grokdoc .mh { color: #666666 } /* Literal.Number.Hex */ .grokdoc .mi { color: #666666 } /* Literal.Number.Integer */ .grokdoc .mo { color: #666666 } /* Literal.Number.Oct */ .grokdoc .sb { color: #BA2121 } /* Literal.String.Backtick */ .grokdoc .sc { color: #BA2121 } /* Literal.String.Char */ .grokdoc .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ .grokdoc .s2 { color: #BA2121 } /* Literal.String.Double */ .grokdoc .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ .grokdoc .sh { color: #BA2121 } /* Literal.String.Heredoc */ .grokdoc .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ .grokdoc .sx { color: #008000 } /* Literal.String.Other */ .grokdoc .sr { color: #BB6688 } /* Literal.String.Regex */ .grokdoc .s1 { color: #BA2121 } /* Literal.String.Single */ .grokdoc .ss { color: #19177C } /* Literal.String.Symbol */ .grokdoc .bp { color: #008000 } /* Name.Builtin.Pseudo */ .grokdoc .vc { color: #19177C } /* Name.Variable.Class */ .grokdoc .vg { color: #19177C } /* Name.Variable.Global */ .grokdoc .vi { color: #19177C } /* Name.Variable.Instance */ .grokdoc .il { color: #666666 } /* Literal.Number.Integer.Long */ cubictemp-2.0/doc/index.html0000644000175000017500000000576510774552236014540 0ustar aldoaldo Cubictemp Manual - Introduction

Cubictemp - Introduction

A small, elegant templating system for Python.

Features

  • Simple, well-tested and well-documented.

  • Integrates tightly with Python - pass arbitrary Python objects into a template, walk sequences and iterators, evaluate expressions.

  • Default escaping helps to prevent common classes of Cross-Site Scripting vulnerabilities.

  • Encourages separation of interface and program logic by disallowing statements in templates.

  • Tiny - only ~ 170 SLOC. There are many large, over-designed Python templating systems out there. Cubictemp proves that a templating sytem can be complete, elegant, powerful, fast and remain compact.

Cubictemp requires Python 2.4 or newer.

Hello walrus

import cubictemp

template = cubictemp.Template("Hello @!foo!@!", foo="walrus")
print template
print template(foo="world")

Output:

Hello walrus!
Hello world!

Copyright Nullcube 2008

cubictemp-2.0/doc/blocks.html0000644000175000017500000001041310774552236014670 0ustar aldoaldo Cubictemp Manual - Blocks

Cubictemp - Blocks

Named blocks

Cubictemp blocks are chunks of text that are defined in the template body, and can be referenced in various ways. The simplest block variety is the named block:

<!--(block bar)-->
    The time has come the walrus said
<!--(end)-->
one
@!bar!@
two
@!bar!@
three

Output:

one
    The time has come the walrus said...
two
    The time has come the walrus said...
three

Like a function, named blocks only produce output when they are referenced. The block definition itself does not appear in the template output.

Named blocks are callable objects that accept an over-riding namespace argument:

<!--(block bar)-->
    The time has come the @!foo!@ said...
<!--(end)-->
@!bar(foo="walrus")!@

@!bar(foo="carpenter")!@

Output:

    The time has come the walrus said

    The time has come the carpenter said

Blocks can be nested to arbitrary depths. Block namespaces and scopes work similarly to Python namespaces and scopes.

Named blocks have the _cubictemp_unescaped attribute defined by default, so they will go unescaped when inserted using the standard @!...!@ escaped substitution syntax.

Repeat Blocks

Cubictemp provides a repeat construct to allow traversal of iterables:

<!--(for foo in bar)-->
    @!foo!@
<!--(end)-->

Like a Python for loop, the template above loops through all elements of "bar", setting the value of "foo" to each element in turn. As in simple substitutions, any valid expression can be used as the sequence definition:

<!--(for foo in range(3))-->
    Counting: @!foo!@
<!--(end)-->

Output:

Counting: 0
Counting: 1
Counting: 2

Playing nice with your designers: closed and open tags

There is a minor variation on the block definition syntax to help preserve document structure during template design. Since the start and end directives of Cubictemp blocks look like HTML comments, they are not visible when the document is viewed as HTML. It is often convenient to be able to also comment everything inside the block. This is accomplished using the open tag variation:

<!--(block foo)
    The time has come the walrus said...
(end)-->

There is no functional difference between the two flavours.

Copyright Nullcube 2008

cubictemp-2.0/doc/api.html0000644000175000017500000001506710774552237014177 0ustar aldoaldo Cubictemp Manual - API

Cubictemp - API

def escape(s)

Replace special characters '&', '<', '>', ''', and '"' with the appropriate HTML escape sequences.

class TemplateError(Exception)

Template evaluation exception class.

pos = None

Character offset within the raw template at which the error occurred

template = None

Template object

lineNo = None

Line number

contextLen = 2

Error context length

def __init__(self, message, pos, template)
def __str__(self)
class Template()
name = "<string>"

Name by which this template is referred to in exceptions.

def __init__(self, txt, **nsDict)
txt
Template body
nsDict
Namespace dictionary
def __str__(self)

Evaluate the template in the namespace provided at instantiation.

def __call__(self, **override)
override

A set of key/value pairs.

Evaluate the template, over-riding the instantiation namespace with the specified key/value pairs. Returns a string.

class File(Template)

Convenience class that extends Template to provide easy instantiation from a file.

def __init__(self, filename, **nsDict)
filename
Full Path to file containing template body.
nsDict
Instantiation namespace dictionary.

Copyright Nullcube 2008

cubictemp-2.0/cubictemp.py0000644000175000017500000002113610773542037014306 0ustar aldoaldo# Copyright (c) 2003-2008, Nullcube Pty Ltd All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # import cgi, re, itertools class TemplateError(Exception): """ Template evaluation exception class. """ # Character offset within the raw template at which the error occurred pos = None # Template object template = None # Line number lineNo = None # Error context length contextLen = 2 def __init__(self, message, pos, template): Exception.__init__(self, message) self.pos, self.template = pos, template self.lineNo, self._contextStr = self._getLines(template.txt, pos) def _getLines(self, txt, pos): lines = txt.splitlines(True) cur = 0 for i, l in enumerate(lines): cur += len(l) if cur > pos: break if i < self.contextLen: startc = 0 else: startc = i - self.contextLen if i + self.contextLen > len(lines): endc = len(lines) else: endc = i + self.contextLen + 1 marker = "%s\n"%("^"*len(lines[i].rstrip())) _contextStr = lines[startc:i+1] + [marker] + lines[i+1:endc] _contextStr = [" " + l.rstrip() for l in _contextStr] _contextStr = "\n".join(_contextStr) return i + 1, _contextStr def __str__(self): ret = [ "%s"%self.message, "\tContext: line %s in %s:"%(self.lineNo, self.template.name), ] ret.append(self._contextStr) return "\n".join(ret) def escape(s): """ Replace special characters '&', '<', '>', ''', and '"' with the appropriate HTML escape sequences. """ s = s.replace("&", "&") # Must be done first! s = s.replace("<", "<") s = s.replace(">", ">") s = s.replace('"', """) s = s.replace("'", "'") return s class _Processor: def __init__(self): self.funcs = [] def __or__(self, other): self.funcs.append(other) return self def __call__(self, s): for i in self.funcs: s = i(s) return s class _Text: def __init__(self, txt): self.txt = txt def __call__(self, **ns): return self.txt class _Eval: def _compile(self, expr, pos, tmpl): try: return compile(expr, "", "eval") except SyntaxError, value: s = 'Invalid expression: "%s"'%(expr) raise TemplateError(s, pos, tmpl) def _eval(self, e, ns): try: return eval(e, {}, ns) except NameError, value: s = 'NameError: "%s"'%value raise TemplateError(s, self.pos, self.tmpl) class _Expression(_Eval): def __init__(self, expr, flavor, pos, tmpl, ns): self.expr, self.flavor = expr, flavor self.pos, self.tmpl = pos, tmpl self.ns = ns self._ecache = self._compile(expr, pos, tmpl) def __call__(self, **ns): ns.update(self.ns) ret = self._eval(self._ecache, ns) if isinstance(ret, _Block): ret = ret(**ns) if self.flavor == "@": if not getattr(ret, "_cubictemp_unescaped", 0): return escape(str(ret)) return str(ret) class _Block(list, _Eval): def __init__(self, processor, pos, tmpl, ns): self.ns, self.processor = ns, processor self.pos, self.tmpl = pos, tmpl if processor: self._ecache = self._compile( "_cubictemp_processor | " + processor, pos, tmpl ) def __call__(self, **ns): r = "".join([i(**ns) for i in self]) if self.processor: ns["_cubictemp_processor"] = _Processor() proc = self._eval(self._ecache, ns) return proc(r) else: return r class _Iterable(list, _Eval): def __init__(self, iterable, varname, pos, tmpl, ns): self.iterable, self.varname = iterable, varname self.pos, self.tmpl = pos, tmpl self.ns = ns self._ecache = self._compile(iterable, pos, tmpl) def __call__(self, **ns): loopIter = self._eval(self._ecache, ns) try: loopIter = iter(loopIter) except TypeError: s = "Can not iterate over %s"%self.iterable raise TemplateError(s, self.pos, self.tmpl) s = [] for i in loopIter: ns[self.varname] = i s.append("".join([i(**ns) for i in self])) return "".join(s) class Template: _cubictemp_unescaped = 1 _bStart = r""" # Two kinds of tags: named blocks and for loops (^[ \t]*)?[ \t\r\f\v]*?\n) | # The end of a tag (?P^[ \t]*([ \t\r\f\v]*\n) | # An expression ((?P@|\$)!(?P.+?)!(?P=flavor)) """ _reParts = re.compile(_bStart, re.X|re.M) # Name by which this template is referred to in exceptions. name = "" def __init__(self, txt, **nsDict): """ :txt Template body :nsDict Namespace dictionary """ self.nsDict, self.txt = nsDict, txt matches = self._reParts.finditer(txt) pos = 0 self.block = _Block(None, pos, self, {}) stack = [self.block] for m in matches: parent = stack[-1] if m.start() > pos: parent.append(_Text(txt[pos:m.start()])) pos = m.end() g = m.groupdict() if g["blockName"]: b = _Block(g["processor"], pos, self, parent.ns.copy()) parent.ns[g["blockName"]] = b stack.append(b) if g["processor"]: b = _Block(g["processor"], pos, self, parent.ns.copy()) stack.append(b) parent.append(b) elif g["iterable"]: b = _Iterable( g["iterable"], g["varName"], pos, self, parent.ns.copy() ) parent.append(b) stack.append(b) elif g["end"]: stack.pop() if not stack: raise TemplateError("Unbalanced block.", pos, self) elif g["expr"]: e = _Expression(g["expr"], g["flavor"], pos, self, parent.ns.copy()) parent.append(e) if pos < len(txt): stack[-1].append(_Text(txt[pos:])) def __str__(self): """ Evaluate the template in the namespace provided at instantiation. """ return self() def __call__(self, **override): """ :override A set of key/value pairs. Evaluate the template, over-riding the instantiation namespace with the specified key/value pairs. Returns a string. """ ns = self.nsDict.copy() ns.update(override) return self.block(**ns) class File(Template): """ Convenience class that extends Template to provide easy instantiation from a file. """ def __init__(self, filename, **nsDict): """ :filename Full Path to file containing template body. :nsDict Instantiation namespace dictionary. """ self.name = filename data = open(filename).read() Template.__init__(self, data, **nsDict) cubictemp-2.0/PKG-INFO0000644000175000017500000000303010774552246013053 0ustar aldoaldoMetadata-Version: 1.0 Name: cubictemp Version: 2.0 Summary: A more elegant templating library for a more civilised age Home-page: http://dev.nullcube.com Author: Nullcube Pty Ltd Author-email: aldo@nullcube.com License: MIT Download-URL: http://dev.nullcube.com/download/cubictemp-2.0.tar.gz Description: A small, elegant templating system for Python. Features ======== * Simple, well-tested and well-documented. * Integrates tightly with Python - pass arbitrary Python objects into a template, walk sequences and iterators, evaluate expressions. * Default escaping helps to prevent common classes of Cross-Site Scripting vulnerabilities. * Encourages separation of interface and program logic by disallowing statements in templates. * Tiny - only ~ 170 SLOC. There are many large, over-designed Python templating systems out there. Cubictemp proves that a templating sytem can be complete, elegant, powerful, fast and remain compact. Cubictemp requires Python 2.4 or newer. Platform: UNKNOWN Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Development Status :: 5 - Production/Stable Classifier: Programming Language :: Python Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Text Processing cubictemp-2.0/setup.py0000644000175000017500000000324010774551615013472 0ustar aldoaldofrom distutils.core import setup long_description = """ A small, elegant templating system for Python. Features ======== * Simple, well-tested and well-documented. * Integrates tightly with Python - pass arbitrary Python objects into a template, walk sequences and iterators, evaluate expressions. * Default escaping helps to prevent common classes of Cross-Site Scripting vulnerabilities. * Encourages separation of interface and program logic by disallowing statements in templates. * Tiny - only ~ 170 SLOC. There are many large, over-designed Python templating systems out there. Cubictemp proves that a templating sytem can be complete, elegant, powerful, fast and remain compact. Cubictemp requires Python 2.4 or newer. """ setup( name="cubictemp", version="2.0", description="A more elegant templating library for a more civilised age", long_description=long_description, author="Nullcube Pty Ltd", author_email="aldo@nullcube.com", license="MIT", url="http://dev.nullcube.com", download_url="http://dev.nullcube.com/download/cubictemp-2.0.tar.gz", py_modules = ["cubictemp"], classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Development Status :: 5 - Production/Stable", "Programming Language :: Python", "Operating System :: OS Independent", "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries", "Topic :: Software Development :: Libraries", "Topic :: Text Processing" ] ) cubictemp-2.0/test/0000755000175000017500000000000010774552246012741 5ustar aldoaldocubictemp-2.0/test/test_template.py0000644000175000017500000000767110744315673016176 0ustar aldoaldo#!/usr/local/bin/python import glob, sys, os.path import libpry import cubictemp class uBasic(libpry.AutoTree): def test_simple(self): test = "@!1!@" ct = cubictemp.Template(test) assert str(ct) == "1" def test_simple2(self): test = "@!a!@" ns = {"a": 1} ct = cubictemp.Template(test, **ns) assert str(ct) == "1" class TemplateTester(libpry.AutoTree): def _runTemp(self, filename, nsDict): return str(cubictemp.File(filename + ".test", **nsDict)) class uTemplate(TemplateTester): PREFIX = "ptests" def _runTemp(self, filename, nsDict={}): filename = os.path.join(self.PREFIX, filename) mtemp = TemplateTester._runTemp(self, filename, nsDict) out = open(filename + ".out", "r").read().split() mout = mtemp.split() if not mout == out: print "Expected output:" print "-------" print out print "-------" print "Actual output:" print "-------" print mout print "-------" self.fail("Actual output does not match expected output") def test_if(self): self._runTemp("if") def test_block(self): ns = { "bar": "rab", } self._runTemp("block", ns) def test_commonuse(self): ns = { "foo": open("ptests/commonuse.data") } self._runTemp("commonuse", ns) def test_nested(self): self._runTemp("nested") def test_repeat(self): self._runTemp("repeat") def test_simple(self): ns = { "foo": "one", "bar": "two", "boo": "three", "mdict": {"entry": "foo"} } self._runTemp("simple", ns) class uErrors(TemplateTester): PREFIX = "ntests" def _runTemp(self, filename, err): filename = os.path.join(self.PREFIX, filename) libpry.raises(err, TemplateTester._runTemp, self, filename, {}) def test_blockLine(self): self._runTemp("blockLine", "'a' is not defined") def test_ifundefined(self): self._runTemp("ifundefined", "'a' is not defined") def test_loopsyntax(self): self._runTemp("loopsyntax", "invalid expression") def test_loopundefined(self): self._runTemp("loopundefined", "'a' is not defined") def test_noniterable(self): self._runTemp("noniterable", "can not iterate") def test_syntax(self): self._runTemp("syntax", "invalid expression") def test_undefined(self): self._runTemp("undefined", "'foo' is not defined") class uQuoting(TemplateTester): PREFIX = "qtests" def _runTemp(self, filename, nsDict={}): filename = os.path.join(self.PREFIX, filename) output = TemplateTester._runTemp(self, filename, nsDict) if (output.find("<") >= 0): self.fail() if (output.find(">") >= 0): self.fail() def test_commonuse(self): class Dummy: def __repr__(self): return "" mdict = { "foo": "", "object": Dummy() } self._runTemp("commonuse", mdict) class uNonQuoting(TemplateTester): PREFIX = "nqtests" def _runTemp(self, filename, nsDict): filename = os.path.join(self.PREFIX, filename) output = TemplateTester._runTemp(self, filename, nsDict) if (output.find("<") < 0): self.fail() if (output.find(">") < 0): self.fail() def test_commonuse(self): class Dummy: _cubictemp_unescaped = 1 def __repr__(self): return "" mdict = { "object": Dummy() } self._runTemp("object", mdict) def test_tag(self): mdict = { "tag": "" } self._runTemp("tag", mdict) tests = [ uBasic(), uTemplate(), uErrors(), uQuoting(), uNonQuoting(), ] cubictemp-2.0/test/ntests/0000755000175000017500000000000010774552246014261 5ustar aldoaldocubictemp-2.0/test/ntests/blockLine.test0000644000175000017500000000006310744315672017060 0ustar aldoaldo. . . . @!foo!@ cubictemp-2.0/test/ntests/loopsyntax.test0000644000175000017500000000003510744315672017375 0ustar aldoaldo cubictemp-2.0/test/ntests/undefined.test0000644000175000017500000000001010744315672017107 0ustar aldoaldo@!foo!@ cubictemp-2.0/test/ntests/syntax.test0000644000175000017500000000003210744315672016500 0ustar aldoaldo@!if (a^) then 1 else 2!@ cubictemp-2.0/test/ntests/ifundefined.test0000644000175000017500000000002210744315672017431 0ustar aldoaldo@!a if 1 else 2!@ cubictemp-2.0/test/ntests/loopundefined.test0000644000175000017500000000003610744315672020011 0ustar aldoaldo cubictemp-2.0/test/ntests/noniterable.test0000644000175000017500000000003310744315672017455 0ustar aldoaldo cubictemp-2.0/test/qtests/0000755000175000017500000000000010774552246014264 5ustar aldoaldocubictemp-2.0/test/qtests/commonuse.test0000644000175000017500000000002310744315673017163 0ustar aldoaldo@!foo!@ @!object!@ cubictemp-2.0/test/nqtests/0000755000175000017500000000000010774552246014442 5ustar aldoaldocubictemp-2.0/test/nqtests/tag.test0000644000175000017500000000001010744315672016102 0ustar aldoaldo$!tag!$ cubictemp-2.0/test/nqtests/object.test0000644000175000017500000000001310744315672016600 0ustar aldoaldo@!object!@ cubictemp-2.0/test/test_cubictemp.py0000644000175000017500000002103210772601401016305 0ustar aldoaldoimport string import libpry import cubictemp def dummyproc(s): return "::%s::"%s def dummyproc2(s): return "**%s**"%s class u_Processor(libpry.AutoTree): def test_procs(self): p = cubictemp._Processor() | dummyproc assert p("foo") == "::foo::" def test_procs_chain(self): p = cubictemp._Processor() p = p | dummyproc | dummyproc2 s = p("foo") assert s == "**::foo::**" p = cubictemp._Processor() p = p | dummyproc2 | dummyproc s = p("foo") assert s == "::**foo**::" class uTemplateError(libpry.AutoTree): def setUp(self): self.s = cubictemp.Template("text") self.t = cubictemp.TemplateError("foo", 0, self.s) def test_getLines(self): txt = """ one two three """ x = txt.find("one") i, ctx = self.t._getLines(txt, x) assert i == 2 lines = ctx.splitlines() assert len(lines) == 5 assert lines[1].strip() == "one" x = txt.find("three") i, ctx = self.t._getLines(txt, x) assert i == 4 lines = ctx.splitlines() assert len(lines) == 5 def test_format_compiletime(self): s = """ @!foo!@ @![!@ @!foo!@ """ libpry.raises("line 5", cubictemp.Template, s) s = """ @![!@ """ libpry.raises("line 2", cubictemp.Template, s) s = """ @!]!@ @!foo!@ """ libpry.raises("line 3", cubictemp.Template, s) s = "@!]!@" libpry.raises("line 1", cubictemp.Template, s) def test_format_execution(self): s = """ @!bar!@ @!foo!@ """ libpry.raises("line 3", str, cubictemp.Template(s)) class u_Expression(libpry.AutoTree): def setUp(self): self.s = cubictemp.Template("text") def test_call(self): e = cubictemp._Expression("foo", "@", 0, self.s, {}) assert e(foo="bar") == "bar" def test_block(self): e = cubictemp._Expression("foo", "@", 0, self.s, {}) t = cubictemp._Block(None, 0, self.s, {}) t.append(cubictemp._Text("bar")) assert e(foo=t) == "bar" def test_syntaxerr(self): libpry.raises( "invalid expression", cubictemp._Expression, "for x", "@", 0, self.s, {} ) def test_namerr(self): e = cubictemp._Expression("foo", "@", 0, self.s, {}) libpry.raises( "NameError", e, ) def test_escaping(self): e = cubictemp._Expression( "foo", "@", 0, "foo", {} ) f = e(foo="<>") assert "<" in f assert not "<" in f assert not ">" in f def test_unescaped(self): class T: _cubictemp_unescaped = True def __str__(self): return "<>" t = T() e = cubictemp._Expression("foo", "@", 0, "foo", {}) f = e(foo=t) assert "<" in f assert ">" in f class uText(libpry.AutoTree): def test_call(self): t = cubictemp._Text("foo") assert t() == "foo" class uBlock(libpry.AutoTree): def setUp(self): self.s = cubictemp.Template("text") def test_call(self): t = cubictemp._Block(None, 0, self.s, {}) t.append(cubictemp._Text("bar")) assert t() == "bar" def test_processor(self): t = cubictemp._Block("dummyproc", 0, self.s, {}) t.append(cubictemp._Text("foo")) assert t(dummyproc=dummyproc) == "::foo::" class uIterable(libpry.AutoTree): def test_call(self): t = cubictemp._Iterable("foo", "bar", 0, "foo", {}) t.append(cubictemp._Expression("bar", "@", 0, "foo", {})) assert t(foo=[1, 2, 3]) == "123" class uTemplate(libpry.AutoTree): def setUp(self): self.s = """ @!tag!@ @!foo!@ @!foo!@ one """ def test_init(self): c = cubictemp.Template(self.s).block assert len(c) == 4 assert not c[0].txt.strip() assert not c[1].txt.strip() assert c[2].expr == "foo" assert c[3].txt.strip() == "one" assert c.ns["foo"] nest = c.ns["foo"].ns["foo"] assert len(nest) == 1 assert nest[0].iterable == "[1, 2, 3]" assert nest[0][1].expr == "tag" def test_str(self): s = str(cubictemp.Template("foo")) assert s == "foo" def test_call(self): s = cubictemp.Template(self.s)(tag="voing") assert "voing" in s def test_unbalanced(self): s = """ @!foo!@ @!foo!@ one """ libpry.raises("unbalanced block", cubictemp.Template, s) def test_complexIterable(self): s = """ @!i!@ """ s = str(cubictemp.Template(s)) assert "[0, 1, 2, 3, 4" in s def test_simpleproc(self): s = """ one @!foo!@ """ t = cubictemp.Template(s, strip=string.strip) assert "::one::" in t(dummyproc=dummyproc) def test_inlineproc(self): s = """ one """ t = cubictemp.Template(s, strip=string.strip) assert "::one::" in t(dummyproc=dummyproc) def test_namespace_err(self): s = """ @!one!@ one """ t = cubictemp.Template(s) libpry.raises("not defined", t) def test_namespace_follow(self): s = """ one @!one!@ """ t = cubictemp.Template(s) assert t().strip() == "one" def test_namespace_follow(self): s = """ one @!one!@ two @!one!@ """ t = str(cubictemp.Template(s)) assert "one" in t assert "two" in t def test_namespace_nest(self): s = """ foo @!one!@ @!two!@ @!one!@ bar @!one!@ """ t = str(cubictemp.Template(s)) assert "foo" in t assert "bar" in t def test_blockspacing(self): s = """ one """ t = cubictemp.Template(s, strip=string.strip) assert t(dummyproc=dummyproc).strip() == "::one::" def test_block_following_whitespace(self): s = """ one test """ t = cubictemp.Template(s, strip=string.strip) assert "\n\n" in t(dummyproc=dummyproc) def test_processorchain(self): s = """ one """ t = cubictemp.Template(s, strip=string.strip, dummyproc2=dummyproc2) assert t(dummyproc=dummyproc).strip() == "**::one::**" def test_lines(self): s = """ : one : """ t = cubictemp.Template(s) s = t() assert ": @!foo(one="<%s>"%i)!@ (end)--> lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet lorem ipsum sic dolor samet """ class uBench(libpry.AutoTree): def test_bench(self): t = cubictemp.Template(tmpl) str(t) tests = [ uBench() ] cubictemp-2.0/test/ptests/0000755000175000017500000000000010774552246014263 5ustar aldoaldocubictemp-2.0/test/ptests/simple.test0000644000175000017500000000011310744315672016445 0ustar aldoaldo@!foo!@ @!foo!@|@!bar!@|@!boo!@ @!foo!@ @!bar!@ @!boo!@ @!mdict["entry"]!@ cubictemp-2.0/test/ptests/nested.test0000644000175000017500000000101410744315672016437 0ustar aldoaldo @!foo!@ (end)--> @!bar!@ @!moo!@ (end)--> @!one!@ (end)--> cubictemp-2.0/test/ptests/repeat.out0000644000175000017500000000011510744315672016266 0ustar aldoaldoone one one two two two three three three four four four 0 1 2 00 11 22 cubictemp-2.0/test/ptests/block.test0000644000175000017500000000047710744315672016263 0ustar aldoaldo @!one!@ two @!two!@ @!bar!@ @!two!@ @!three!@ @!bar!@ @!hoo!@ @!four(bar="hoink", hoo="farble")!@ @!bar!@ @!foo(bar="hoink")!@ cubictemp-2.0/test/ptests/block.out0000644000175000017500000000004710744315672016104 0ustar aldoaldoone two rab two hoink farble hoink cubictemp-2.0/test/ptests/if.test0000644000175000017500000000023010744315672015552 0ustar aldoaldo@!"a" if 1 else "b"!@ @!"a" if 0 else "b"!@ @!foo if 1 else "none"!@ @!foo if 0 else "none"!@ @!"safe" if 1 else 1/0!@ cubictemp-2.0/test/ptests/commonuse.test0000644000175000017500000000005010744315672017161 0ustar aldoaldo cubictemp-2.0/test/ptests/if.out0000644000175000017500000000002710744315672015406 0ustar aldoaldoa b a b none safe cubictemp-2.0/test/ptests/commonuse.out0000644000175000017500000000002110744315672017007 0ustar aldoaldoone two three cubictemp-2.0/test/ptests/nested.out0000644000175000017500000000006310744315672016272 0ustar aldoaldo0 1 2 3 4 0 0 1 1 0 1 bar bar barg 00 01 10 11 cubictemp-2.0/test/ptests/commonuse.data0000644000175000017500000000001610744315672017115 0ustar aldoaldoone two three cubictemp-2.0/test/ptests/simple.out0000644000175000017500000000004410744315672016300 0ustar aldoaldoone one|two|three one two three foo cubictemp-2.0/test/ptests/repeat.test0000644000175000017500000000046210744315672016443 0ustar aldoaldo one three