Re: Does Cheetah count line numbers its written?

Nate Reid <[email protected]> Fri, 25 Mar 2011 12:27:32 -0700
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
--===============7827118098285012884==
Content-Type: multipart/alternative;
	boundary="_6d1a7894-4520-42eb-99b3-41ba1ffdab4a_"

--_6d1a7894-4520-42eb-99b3-41ba1ffdab4a_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


In code generation=2C I have a source file which has a combination of C++ a=
nd custom 'code/directives' which is interpreted and converted into C++ cod=
e.  When debugging a generated file=2C #line directives are used to signal =
to the debugger where the source of the of lines originates.
E.g.

// mycustom.file (adding line numbers for clarity in the explanation.  They=
 aren't in the original files)
1: HEADER
2: content name =3D test
3: content type =3D string
4: content default =3D "hello world"
5: END
6:=20
7: CUSTOM
8: #include <string>
9: #include <vector>
10: END

// Output from cheetah template below.  Generated 'this_file.cpp'
1: #line 8 "mycustom.file"
2: #include <string>
3: #include <vector>
4: #line 5 "this_file.cpp"
5: std::string contentTest =3D "hello world"
6: etc...

So the cheetah template is creating this_file.cpp=2C and needs to use the i=
nformation from the mycustom.file to insert the corret #line directives int=
o the file and then (more importantly) insert the #line directive of the fi=
le being generated at the correct line.
So=2C in the above example=2C a cheetah template like this would be used

// cheetah template
#def lineDirective()
\#line $LINE "this_file.cpp"
#end def
##
#for $custom in $customs
## first $custom is  -> #line 8 "mycustom.file"
$custom
#end for
$lineDirective() ## should output: #line 5 "this_file.cpp"
$type $var =3D $default
...


So=2C the $LINE variable needs to be updated to be the actual line number o=
f the current generated file that the cheetah template is producing=2C so i=
t needs to handle loops=2C conditionals=2C etc.  Basically=2C a run-time co=
unt of the lines written=2C so it can't be known at compile time.

I hope that helps clear up what I was trying to do.

Thanks!
-Nate
=20

Date: Wed=2C 23 Mar 2011 23:22:49 -0400
Subject: Re: [Cheetahtemplate-discuss] Does Cheetah count line numbers its =
written?
From: [email protected]
To: [email protected]
CC: [email protected]

Hi Nate=2C

I guess I'm not quite clear on what you're trying to do.  If you don't want=
 the line number from the original template then what line number do you wa=
nt?  Could you provide some small theoretical example of your desired input=
 and what you'd expect it to produce?


--=20
James Abbatiello


On Fri=2C Mar 11=2C 2011 at 9:29 PM=2C Nate Reid <[email protected]> wrot=
e:






Hi James=2C
In my work=2C I am using the command line cheetah compiler (e.g. cheetah sc=
ript) so I had to hack a version of the command-line CheetahWrapper by monk=
ey patching in a version that lets me specify a compilerClass to the Templa=
te.compile command.  My changes are specifying the compilerClass in the com=
pille command below.


#!/bin/env python
import Cheetah.CheetahWrapper
from Cheetah.CheetahWrapper import CheetahWrapper
from cheetah_compilers import LineNumberCompiler
import os
import shutil
moduleNameRE =3D Cheetah.CheetahWrapper.moduleNameRE


class MyCheetahWrapper(CheetahWrapper):
    def __init__(self=2C *args=2C **kwargs):
        super(MyCheetahWrapper=2C self).__init__(*args=2C **kwargs)

    def _compileOrFillBundle(self=2C b):
        C=2C D=2C W =3D self.chatter=2C self.debug=2C self.warn

        TemplateClass =3D self._getTemplateClass()
        compilerSettings =3D self._getCompilerSettings()
        src =3D b.src
        dst =3D b.dst
        base =3D b.base
        basename =3D b.basename
        dstDir =3D os.path.dirname(dst)

        what =3D self.isCompile and "Compiling" or "Filling"
        C("%s %s -> %s^"=2C what=2C src=2C dst) # No trailing newline.
        if os.path.exists(dst) and not self.opts.nobackup:

            bak =3D b.bak
            C(" (backup %s)"=2C bak) # On same line as previous message.
        else:
            bak =3D None
            C("")
        if self.isCompile:
            if not moduleNameRE.match(basename):

                tup =3D basename=2C src
                raise Error("""\
%s: base name %s contains invalid characters.  It must
be named according to the same rules as Python modules.""" % tup)

            pysrc =3D TemplateClass.compile(file=3Dsrc=2C returnAClass=3DFa=
lse=2C
                                          moduleName=3Dbasename=2C
                                          className=3Dbasename=2C
                                          commandlineopts=3Dself.opts=2C

                                          compilerSettings=3DcompilerSettin=
gs=2C
                                          compilerClass=3DLineNumberCompile=
r)
            output =3D pysrc
        else:
            #output =3D str(TemplateClass(file=3Dsrc=2C searchList=3Dself.s=
earchList))

            tclass =3D TemplateClass.compile(file=3Dsrc=2C compilerSettings=
=3DcompilerSettings=2C compilerClass=3DLineNumberCompiler)
            output =3D str(tclass(searchList=3Dself.searchList))

        if bak:
            shutil.copyfile(dst=2C bak)

        if dstDir and not os.path.exists(dstDir):
            if self.isCompile:
                mkdirsWithPyInitFiles(dstDir)
            else:
                os.makedirs(dstDir)
        if self.opts.stdout:

            sys.stdout.write(output)
        else:
            f =3D open(dst=2C 'w')
            f.write(output)
            f.close()

if __name__ =3D=3D '__main__':
    MyCheetahWrapper().main()



Where LineNumberCompiler is the MyCompiler class you created in the origina=
l e-mail.
The problem is that when the templates are compiled=2C it seems to hardcode=
 the $LINE variable directly into the source code=2C so when I actually fil=
l the templates=2C

the $LINE variable no longer corresponds to the actual line in the source c=
ode.  It also doesn't allow me to use a #def to define a function that lets=
 me spit out the #line $LINE "filename.cpp" directive.  E.g. it just replac=
es $LINE with the line number that it was first defined=2C rather than the =
dynamic one.


Is there another way that Cheetah can actually count the lines it's written=
 while filling the template?

Thanks!
-Nate

From: [email protected]

To: [email protected]
Date: Wed=2C 9 Mar 2011 11:23:04 -0800
CC: [email protected]

Subject: Re: [Cheetahtemplate-discuss] Does Cheetah count line numbers its =
written?








Thanks James=2C I'll give this a try and thanks for taking the time to writ=
e this up.
Cheers
-Nate

Date: Wed=2C 9 Mar 2011 01:03:20 -0500
Subject: Re: [Cheetahtemplate-discuss] Does Cheetah count line numbers its =
written?

From: [email protected]
To: [email protected]
CC: [email protected]


This is a bit ugly but it may work for you:

#!/usr/bin/env python
import Cheetah.Compiler
import Cheetah.Template

class MyAutoMethodCompiler(Cheetah.Compiler.AutoMethodCompiler):
    def addPlaceholder(self=2C expr=2C filterArgs=2C rawPlaceholder=2C


                       cacheTokenParts=2C lineCol=2C
                       silentMode=3DFalse):
        if rawPlaceholder =3D=3D u'$LINE':
            self.addFilteredChunk(repr(unicode(lineCol[0]))=2C
                                  filterArgs=2C


                                  rawPlaceholder=2C
                                  lineCol=3DlineCol)
        else:
            super(MyAutoMethodCompiler=2C self).addPlaceholder(
                expr=2C filterArgs=2C rawPlaceholder=2C


                cacheTokenParts=2C lineCol=2C
                silentMode=3DsilentMode)


class MyAutoClassCompiler(Cheetah.Compiler.AutoClassCompiler):
    methodCompilerClass =3D MyAutoMethodCompiler


class MyCompiler(Cheetah.Compiler.Compiler):


    classCompilerClass =3D MyAutoClassCompiler


tclass =3D Cheetah.Template.Template.compile('''\
This is line $LINE
Hello=2C $name!
And this is line $LINE'''=2C compilerClass=3DMyCompiler)


print tclass(searchList=3D[{"name": "Nate"}])


--=20
James Abbatiello


On Tue=2C Mar 8=2C 2011 at 1:45 PM=2C Nate Reid <[email protected]> wrote=
:







I'm writing a source generator using Cheetah templates for C++ and would li=
ke to add #line directives into the generated source.  Without delving deep=
 into the Cheetah source code=2C I was wondering if anyone on the list knew=
 if Cheetah keeps track of how many lines are written so I can easily query=
 the current line number in the template and use that in the template outpu=
t itself for inserting #line directives into the generated source code.


Thanks!
-Nate
 		 	   		 =20

---------------------------------------------------------------------------=
---

What You Don't Know About Data Connectivity CAN Hurt You

This paper provides an overview of data connectivity=2C details

its effect on application quality=2C and explores various alternative

solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________

Cheetahtemplate-discuss mailing list

[email protected]

https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss



 		 	   		 =20

---------------------------------------------------------------------------=
---
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss 		 	  =
 		 =20

---------------------------------------------------------------------------=
---

Colocation vs. Managed Hosting

A question and answer guide to determining the best fit

for your organization - today and in the future.

http://p.sf.net/sfu/internap-sfd2d
_______________________________________________

Cheetahtemplate-discuss mailing list

[email protected]

https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss



 		 	   		  =

--_6d1a7894-4520-42eb-99b3-41ba1ffdab4a_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Tahoma
}
--></style>
</head>
<body class=3D'hmmessage'>
In code generation=2C I have a source file which has a combination of C++ a=
nd custom 'code/directives' which is interpreted and converted into C++ cod=
e.&nbsp=3B When debugging a generated file=2C #line directives are used to =
signal to the debugger where the source of the of lines originates.<br>E.g.=
<br><br>// mycustom.file (adding line numbers for clarity in the explanatio=
n.&nbsp=3B They aren't in the original files)<br>1: HEADER<br>2: content na=
me =3D test<br>3: content type =3D string<br>4: content default =3D "hello =
world"<br>5: END<br>6: <br>7: CUSTOM<br>8: #include &lt=3Bstring&gt=3B<br>9=
: #include &lt=3Bvector&gt=3B<br>10: END<br><br>// Output from cheetah temp=
late below.&nbsp=3B Generated 'this_file.cpp'<br>1: #line 8 "mycustom.file"=
<br>2: #include &lt=3Bstring&gt=3B<br>3: #include &lt=3Bvector&gt=3B<br>4: =
#line 5 "this_file.cpp"<br>5: std::string contentTest =3D "hello world"<br>=
6: etc...<br><br>So the cheetah template is creating this_file.cpp=2C and n=
eeds to use the information from the mycustom.file to insert the corret #li=
ne directives into the file and then (more importantly) insert the #line di=
rective of the file being generated at the correct line.<br>So=2C in the ab=
ove example=2C a cheetah template like this would be used<br><br>// cheetah=
 template<br>#def lineDirective()<br>\#line $LINE "this_file.cpp"<br>#end d=
ef<br>##<br>#for $custom in $customs<br>## first $custom is&nbsp=3B -&gt=3B=
 #line 8 "mycustom.file"<br>$custom<br>#end for<br>$lineDirective() ## shou=
ld output: #line 5 "this_file.cpp"<br>$type $var =3D $default<br>...<br><br=
><br>So=2C the $LINE variable needs to be updated to be the actual line num=
ber of the current generated file that the cheetah template is producing=2C=
 so it needs to handle loops=2C conditionals=2C etc.&nbsp=3B Basically=2C a=
 run-time count of the lines written=2C so it can't be known at compile tim=
e.<br><br>I hope that helps clear up what I was trying to do.<br><br>Thanks=
!<br>-Nate<br>&nbsp=3B<br><br><hr id=3D"stopSpelling">Date: Wed=2C 23 Mar 2=
011 23:22:49 -0400<br>Subject: Re: [Cheetahtemplate-discuss] Does Cheetah c=
ount line numbers its written?<br>From: [email protected]<br>To: gnatty7@hot=
mail.com<br>CC: [email protected]<br><br>Hi Nat=
e=2C<br><br>I guess I'm not quite clear on what you're trying to do.&nbsp=
=3B If you don't want the line number from the original template then what =
line number do you want?&nbsp=3B Could you provide some small theoretical e=
xample of your desired input and what you'd expect it to produce?<br>
<br>-- <br>James Abbatiello<br><br><br><div class=3D"ecxgmail_quote">On Fri=
=2C Mar 11=2C 2011 at 9:29 PM=2C Nate Reid <span dir=3D"ltr">&lt=3B<a href=
=3D"mailto:[email protected]">[email protected]</a>&gt=3B</span> wrote:=
<br><blockquote class=3D"ecxgmail_quote" style=3D"border-left: 1px solid rg=
b(204=2C 204=2C 204)=3B padding-left: 1ex=3B">




<div>
Hi James=2C<br>In my work=2C I am using the command line cheetah compiler (=
e.g. cheetah script) so I had to hack a version of the command-line Cheetah=
Wrapper by monkey patching in a version that lets me specify a compilerClas=
s to the Template.compile command.&nbsp=3B My changes are specifying the co=
mpilerClass in the compille command below.<br>
<br>#!/bin/env python<br>import Cheetah.CheetahWrapper<br>from Cheetah.Chee=
tahWrapper import CheetahWrapper<br>from cheetah_compilers import LineNumbe=
rCompiler<br>import os<br>import shutil<br>moduleNameRE =3D Cheetah.Cheetah=
Wrapper.moduleNameRE<br>
<br>class MyCheetahWrapper(CheetahWrapper):<br>&nbsp=3B&nbsp=3B&nbsp=3B def=
 __init__(self=2C *args=2C **kwargs):<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B super(MyCheetahWrapper=2C self).__init__(*args=2C **=
kwargs)<br><br>&nbsp=3B&nbsp=3B&nbsp=3B def _compileOrFillBundle(self=2C b)=
:<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B C=2C D=2C W =
=3D self.chatter=2C self.debug=2C self.warn<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B TemplateClass =3D =
self._getTemplateClass()<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B compilerSettings =3D self._getCompilerSettings()<br>&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B src =3D b.src<br>&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B dst =3D b.dst<br>&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B base =3D b.base<br>&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B basename =3D b.basename<br>&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B dstDir =3D os.path.di=
rname(dst)<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B what =3D self.isCo=
mpile and "Compiling" or "Filling"<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B C("%s %s -&gt=3B %s^"=2C what=2C src=2C dst) # No trail=
ing newline.<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if=
 os.path.exists(dst) and not self.opts.nobackup:<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B bak =3D b.bak<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B C(" (backup %s)"=2C bak) # On =
same line as previous message.<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&=
nbsp=3B&nbsp=3B else:<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B bak =3D None<br>&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B C("")<=
br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if self.isCompi=
le:<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B if not moduleNameRE.match(basename):<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B tup =3D basename=2C src<br>&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B raise Error("""\<br>%s: base na=
me %s contains invalid characters.&nbsp=3B It must<br>be named according to=
 the same rules as Python modules.""" % tup)<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B pysrc =3D TemplateClass.compile(file=3Dsrc=2C returnAClass=3D=
False=2C<br>&nbsp=3B&nbsp=3B&nbsp=3B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.searchList))<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B tclass =3D TemplateClass.compile(file=3Dsrc=2C compilerSettin=
gs=3DcompilerSettings=2C compilerClass=3DLineNumberCompiler)<br>&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B output =3D str(tclass(searchList=3Dself.searchList))<br><br>&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if bak:<br>&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B shut=
il.copyfile(dst=2C bak)<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if dstDir and not =
os.path.exists(dstDir):<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if self.isCompile:<br>&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B mkdirsWithPyInitFiles(dstDir)<br>&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
&nbsp=3B else:<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&=
nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B os.makedirs=
(dstDir)<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if sel=
f.opts.stdout:<br>
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B sys.stdout.write(output)<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&=
nbsp=3B&nbsp=3B&nbsp=3B else:<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B f =3D open(dst=2C 'w')<br>&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B f.write(output)<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B f.close()<br><br>if __name__ =
=3D=3D '__main__':<br>&nbsp=3B&nbsp=3B&nbsp=3B MyCheetahWrapper().main()<br=
>
<br><br>Where LineNumberCompiler is the MyCompiler class you created in the=
 original e-mail.<br>The problem is that when the templates are compiled=2C=
 it seems to hardcode the $LINE variable directly into the source code=2C s=
o when I actually fill the templates=2C<br>
the $LINE variable no longer corresponds to the actual line in the source c=
ode.&nbsp=3B It also doesn't allow me to use a #def to define a function th=
at lets me spit out the #line $LINE "filename.cpp" directive.&nbsp=3B E.g. =
it just replaces $LINE with the line number that it was first defined=2C ra=
ther than the dynamic one.<br>
<br>Is there another way that Cheetah can actually count the lines it's wri=
tten while filling the template?<br><br>Thanks!<br>-Nate<br><br><hr>From: <=
a href=3D"mailto:[email protected]">[email protected]</a><br>
To: <a href=3D"mailto:[email protected]">[email protected]</a><br>Date: Wed=
=2C 9 Mar 2011 11:23:04 -0800<div class=3D"ecxim"><br>CC: <a href=3D"mailto=
:[email protected]">cheetahtemplate-discuss@lis=
ts.sourceforge.net</a><br>
</div><div><div></div><div class=3D"h5">Subject: Re: [Cheetahtemplate-discu=
ss] Does Cheetah count line numbers its written?<br><br>






Thanks James=2C I'll give this a try and thanks for taking the time to writ=
e this up.<br>Cheers<br>-Nate<br><br><hr>Date: Wed=2C 9 Mar 2011 01:03:20 -=
0500<br>Subject: Re: [Cheetahtemplate-discuss] Does Cheetah count line numb=
ers its written?<br>
From: <a href=3D"mailto:[email protected]">[email protected]</a><br>To: <a hr=
ef=3D"mailto:[email protected]">[email protected]</a><br>CC: <a href=3D=
"mailto:[email protected]">cheetahtemplate-disc=
[email protected]</a><br>
<br>This is a bit ugly but it may work for you:<br><br>#!/usr/bin/env pytho=
n<br>import Cheetah.Compiler<br>import Cheetah.Template<br><br>class MyAuto=
MethodCompiler(Cheetah.Compiler.AutoMethodCompiler):<br>&nbsp=3B&nbsp=3B&nb=
sp=3B def addPlaceholder(self=2C expr=2C filterArgs=2C rawPlaceholder=2C<br=
>

&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B cacheTokenParts=2C lineCol=2C<br>&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B silentMode=3DFalse):<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B if rawPlaceholder =3D=3D u'$LINE':<br>&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bsp=3B&nbsp=3B else:<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B super(MyAutoMethodCo=
mpiler=2C self).addPlaceholder(<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B expr=2C filterArgs=2C rawPlaceholder=2C<br>

&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B cacheTokenParts=2C lineCol=2C=
<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B silentMode=3DsilentMode=
)<br><br><br>class MyAutoClassCompiler(Cheetah.Compiler.AutoClassCompiler):=
<br>&nbsp=3B&nbsp=3B&nbsp=3B methodCompilerClass =3D MyAutoMethodCompiler<b=
r><br><br>class MyCompiler(Cheetah.Compiler.Compiler):<br>

&nbsp=3B&nbsp=3B&nbsp=3B classCompilerClass =3D MyAutoClassCompiler<br><br>=
<br>tclass =3D Cheetah.Template.Template.compile('''\<br>This is line $LINE=
<br>Hello=2C $name!<br>And this is line $LINE'''=2C compilerClass=3DMyCompi=
ler)<br>

print tclass(searchList=3D[{"name": "Nate"}])<br><br><br>-- <br>James Abbat=
iello<br><br><br><div>On Tue=2C Mar 8=2C 2011 at 1:45 PM=2C Nate Reid <span=
 dir=3D"ltr">&lt=3B<a href=3D"mailto:[email protected]">[email protected]=
om</a>&gt=3B</span> wrote:<br>

<blockquote style=3D"padding-left: 1ex=3B">



<div>
I'm writing a source generator using Cheetah templates for C++ and would li=
ke to add #line directives into the generated source.&nbsp=3B Without delvi=
ng deep into the Cheetah source code=2C I was wondering if anyone on the li=
st knew if Cheetah keeps track of how many lines are written so I can easil=
y query the current line number in the template and use that in the templat=
e output itself for inserting #line directives into the generated source co=
de.<br>

Thanks!<br>-Nate<br> 		 	   		  </div>
<br>-----------------------------------------------------------------------=
-------<br>
What You Don't Know About Data Connectivity CAN Hurt You<br>
This paper provides an overview of data connectivity=2C details<br>
its effect on application quality=2C and explores various alternative<br>
solutions. <a href=3D"http://p.sf.net/sfu/progress-d2d" target=3D"_blank">h=
ttp://p.sf.net/sfu/progress-d2d</a><br>____________________________________=
___________<br>
Cheetahtemplate-discuss mailing list<br>
<a href=3D"mailto:[email protected]">Cheetahtem=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta=
htemplate-discuss</a><br>
<br></blockquote></div><br> 		 	   		 =20
<br></div></div>-----------------------------------------------------------=
-------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
<a href=3D"http://p.sf.net/sfu/internap-sfd2d" target=3D"_blank">http://p.s=
f.net/sfu/internap-sfd2d</a><br>___________________________________________=
____
Cheetahtemplate-discuss mailing list
<a href=3D"mailto:[email protected]">Cheetahtem=
[email protected]</a>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta=
htemplate-discuss</a> 		 	   		  </div>
<br>-----------------------------------------------------------------------=
-------<br>
Colocation vs. Managed Hosting<br>
A question and answer guide to determining the best fit<br>
for your organization - today and in the future.<br>
<a href=3D"http://p.sf.net/sfu/internap-sfd2d" target=3D"_blank">http://p.s=
f.net/sfu/internap-sfd2d</a><br>___________________________________________=
____<br>
Cheetahtemplate-discuss mailing list<br>
<a href=3D"mailto:[email protected]">Cheetahtem=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta=
htemplate-discuss</a><br>
<br></blockquote></div><br> 		 	   		  </body>
</html>=

--_6d1a7894-4520-42eb-99b3-41ba1ffdab4a_--


--===============7827118098285012884==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
--===============7827118098285012884==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss

--===============7827118098285012884==--