Git Product home page Git Product logo

ezt's People

Contributors

futatuki avatar gstein avatar sebbasf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ezt's Issues

Small patch + tests to fix Unicode support

Currently EZT gets confused when the input is unicode, e.g. in Python 2.6:

>>> import ezt, sys, StringIO
>>> template = ezt.Template()
>>> template.parse(u'♥')
>>> f = StringIO.StringIO()
>>> template.generate(f, {})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ezt.py", line 137, in generate
    self._execute(self.program, fp, ctx)
  File "ezt.py", line 296, in _execute
    method, method_args, filename, line_number = step
ValueError: need more than 1 value to unpack

I've attached below a patch with a small fix to ezt.py and new tests in 
tests/ezt_test.py.

Note that I switched from cStringIO to StringIO because cStringIO doesn't 
support unicode. This will make templates with [define ...] directives (and 
only them) slightly slower, but it's an acceptable tradeoff IMHO.

The patch should not introduce any backward incompatibilities since unicode 
templates were previously not supported.

P.S.: on a personal note, Daniel Berlin says "hi" to Greg Stein. I guess you 
guys know each other. :-)

Original issue reported on code.google.com by [email protected] on 17 Jul 2012 at 10:57

Attachments:

EZT comment syntax

I think ezt needs its own comment syntax. 

Currently if I want to add some comments to an ezt file (to the template file, 
in the source tree of some web application project) destined to be read by 
developers of the project there is no way to do that properly. To do it I'm 
using HTML comment tags but those will get copied verbatim in the produced HTML 
by ezt so users of the web application can see them in the HTML source (and 
they don't make much sense in that context).

Please add some kind of ezt comment syntax that is not copied by ezt in the 
produced output but just ignored.

Original issue reported on code.google.com by [email protected] on 23 Jun 2010 at 8:16

EZT should allow dictionary access if attribute access fails on an object

Django supports accessing dictionary entries when attribute accesses fail, 
which is a really handy feature in my experience. It'd be nice if EZT supported 
this as well.

What steps will reproduce the problem?

1. Reference an entry in a dictionary in your template somewhere,
   e.g. <h1>[mydict.one]</h1>
2. Pass in a dictionary for the corresponding data variable to generate, 
   e.g. generate(fd, {'mydict': {'one': 1, 'two': 2}})

What is the expected output? What do you see instead?

In Django, the attribute access would fail, but the system would check that the 
object is a dictionary, and try a dictionary access, which would then return 1. 
In EZT, this simply fails with an UnknownReference exception

What version of the product are you using? On what operating system?

I'm not entirely sure what version I'm using, but the _get_value function looks 
no different when compared with the trunk version in this repository.

Please provide any additional information below.

Something like this seems to work for me:

@@ -672,7 +672,11 @@ def _get_value((refname, start, rest), ctx, filename, 
line_number):
     try:
       ob = getattr(ob, attr)
     except AttributeError:
-      raise UnknownReference(refname, filename, line_number)
+      if (hasattr(ob, 'has_key') and hasattr(ob, '__getitem__')
+          and ob.has_key(attr)):
+        ob = ob[attr]
+      else:
+        raise UnknownReference(refname, filename, line_number)

   # make sure we return a string instead of some various Python types
   if isinstance(ob, (IntType, FloatType, LongType)):

Original issue reported on code.google.com by [email protected] on 30 Aug 2010 at 12:42

'for' could carry an implied 'if-any'

A template containing "[for SEQ_ITEM]", where there's no SEQ_ITEM in the
data dictionary, will raise an Exception.  I'm okay with that, and the
workaround is generally just to ensure that there *is* a SEQ_ITEM item in
the data dictionary.

Now if, by way of workaround, you make SEQ_ITEM's dummy value [], stuff
works.  But if (as part of a pattern of initializing data dictionary items)
you instead use None, the template complains.  You can work around this in
the templates by always doing:

  [if-any SEQ_ITEM][for SEQ_ITEM] ... [end][end]

But I wonder if [for] shouldn't imply an existence check, and just be as
satisfied with gracefully not looping over a None value as it is with not
looping over an empty sequence value.

Original issue reported on code.google.com by cmpilato on 19 Mar 2009 at 4:55

Would like a line-continuation syntax for EZT

A complex series of EZT directives in a whitespace-sensitive context can
get really ugly, really fast.  Something that might help is a
line-continuation code for EZT.  Perhaps [\]?

Here's an example (using the proposed continuation sequence) from ViewVC,
where we have to do a bunch of EZT mumbojumbo to print out a sequent of
path components and separators.  We don't want whitespace in there because
that affects copy-n-paste of the paths, but ideally we don't want this
whole chunk of logic on a single line in the template file, either:

{{{
[if-any roots_href]<a href="[roots_href]">root</a>[end][\]
[if-any nav_path]<span class="pathdiv">/</span>[\]
[for nav_path][\]
[if-any nav_path.href]<a href="[nav_path.href]">[end][\]
[if-index nav_path last]<span class="thisitem">[end][\]
[nav_path.name][\]
[if-index nav_path last]</span>[end][if-any nav_path.href]</a>[end][\]
[if-index nav_path last][else]<span class="pathdiv">[end][\]
[end]
[end]
}}}

Original issue reported on code.google.com by cmpilato on 18 Aug 2008 at 6:04

Nested [format] blocks don't have the expected effect.

One you would expect that this data dictionary:

   { 'foo' = 'hi & lois' }

passed through this EZT language:

   [format "html"][format "html"][foo][end][end]

would produce this output:

   hi &amp;amp; lois

But it doesn't.

Original issue reported on code.google.com by cmpilato on 20 May 2010 at 5:31

No sources are checked in

[bsergean@amanda sandbox]$ svn checkout http://ezt.googlecode.com/svn/trunk/ ezt
[bsergean@amanda sandbox]$ ls ezt/
[bsergean@amanda sandbox]$ 

... 

Original issue reported on code.google.com by [email protected] on 31 Dec 2006 at 6:35

Wishlist: iteration len()-type operator

Rather than have an application provide an iterable list of objects (like,
say, 'changes') *and* a value like 'num_changes', it'd be right handy if
the template could simply ask for the length of the list in some way.

Original issue reported on code.google.com by cmpilato on 19 Dec 2008 at 6:57

support for [define VARIABLE] where VARIABLE contains dotted attributes

I have a use case for overriding attributes of objects provided through the 
template's fed data, i'd like to be considered for inclusion in EZT.

Next to being useful in my case, i read the documented syntax to leave room for 
it (the define takes a VARIABLE, and a variable is described to optionally 
contain dotted attributes).

Below is a patch that works for me. It still requires every component of a 
provided refname to be a valid reference.  If it isn't adequate, i'm glad to 
rework it upon your review.

thanks,
-seb.


$ svn diff
Index: ezt.py
===================================================================
--- ezt.py  (revision 38)
+++ ezt.py  (working copy)
@@ -486,11 +486,16 @@
     raise UnknownReference(refname, filename, line_number)

   # walk the rest of the dotted reference
+  partial_refname = start
   for attr in rest:
-    try:
-      ob = getattr(ob, attr)
-    except AttributeError:
-      raise UnknownReference(refname, filename, line_number)
+    partial_refname = '%s.%s' % (partial_refname, attr)
+    if ctx.defines.has_key(partial_refname):
+      ob = ctx.defines[partial_refname]
+    else:
+      try:
+        ob = getattr(ob, attr)
+      except AttributeError:
+        raise UnknownReference(refname, filename, line_number)

   # make sure we return a string instead of some various Python types
   if isinstance(ob, (IntType, FloatType, LongType)):
Index: tests/ezt_test.py
===================================================================
--- tests/ezt_test.py   (revision 38)
+++ tests/ezt_test.py   (working copy)
@@ -178,6 +178,16 @@
     d = self._runTemplate('[define RED]blue[end]RED = [RED]', {})
     self.assertEquals('RED = blue', d)

+  def testDefineAttributes(self):
+    class _BlahBlah:
+      def __init__(self, foo, bar):
+        self.foo = foo
+        self.bar = bar
+    o = _BlahBlah('freedom', 'good')
+    d = self._runTemplate('[define X.bar]slavery[end][X.foo] = [X.bar]',
+                          {'X': o})
+    self.assertEquals('freedom = slavery', d)
+
   def testDefineUnicode(self):
     d = self._runTemplate(u'[define HEART]���[end]HEART = [HEART]', {})
     self.assertEquals(u'HEART = ���', d)

Original issue reported on code.google.com by [email protected] on 27 May 2015 at 8:40

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.