List Info

Thread: from __future__ import ... hack




from __future__ import ... hack
user name
2007-09-19 05:56:02
I really wanted to use with statements in the .ptl files.
Since
"from __future__ import with_statement" didn't
work, I did this:

--- ptl_compile.py.orig	2006-08-08 00:53:53.000000000 +0300
+++ ptl_compile.py	2007-09-19 12:47:22.000000000 +0300
 -63,6
+63,18 
 
         for node in nodelist:
             if node[0] != token.ENDMARKER and node[0] !=
token.NEWLINE:
+                try:
+                    if node[0] == symbol.stmt and 
+                           node[1][0] == symbol.simple_stmt
and 
+                           node[1][1][0] ==
symbol.small_stmt and 
+                           node[1][1][1][0] ==
symbol.import_stmt and 
+                           node[1][1][1][1][0] ==
symbol.import_from and 
+                           node[1][1][1][1][2][0] ==
symbol.dotted_name and 
+                           node[1][1][1][1][2][1][0] ==
token.NAME and 
+                           node[1][1][1][1][2][1][1] ==
'__future__':
+                        continue
+                except:
+                    pass
                 self.com_append_stmt(stmts, node)
 
         return ast.Module(doc, ast.Stmt(stmts))

-- 
Patrik
_______________________________________________
Quixote-users mailing list
Quixote-usersmems-exchange.org
http://mail.mems-exchange.org/mailman/listinfo/quixo
te-users

Re: from __future__ import ... hack
user name
2007-10-01 17:57:09
> I really wanted to use with statements in the .ptl
files. Since
> "from __future__ import with_statement"
didn't work, I did this:

I think this patch does the right thing.  I'll test it for a
while.
If other people have success or failure, please shoot me an
email.

  Neil


=== modified file 'quixote/ptl/ptl_compile.py'
--- quixote/ptl/ptl_compile.py	2006-08-07 21:44:13 +0000
+++ quixote/ptl/ptl_compile.py	2007-10-01 22:53:14 +0000
 -59,12
+59,20 
                 'quixote.html',
                 [('TemplateIO', '_q_TemplateIO'),
('htmltext', '_q_htmltext')])
             vars_imp = ast.From("__builtin__",
[("vars", "_q_vars")])
-        stmts = [ vars_imp, html_imp ]
 
+        ptl_imports = [ vars_imp, html_imp ]
+        stmts = []
         for node in nodelist:
             if node[0] != token.ENDMARKER and node[0] !=
token.NEWLINE:
                 self.com_append_stmt(stmts, node)
-
+        # count __future__ statements
+        i = 0
+        for stmt in stmts:
+            if isinstance(stmt, ast.From) and stmt.modname
== '__future__':
+                i += 1
+            else:
+                break
+        stmts[i:i] = ptl_imports
         return ast.Module(doc, ast.Stmt(stmts))
 
     def funcdef(self, nodelist):



_______________________________________________
Quixote-users mailing list
Quixote-usersmems-exchange.org
http://mail.mems-exchange.org/mailman/listinfo/quixo
te-users

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )