Package Cheetah :: Module Compiler :: Class GenUtils
[show private | hide private]
[frames | no frames]

Class GenUtils

Known Subclasses:
ClassCompiler, MethodCompiler, ModuleCompiler

An abstract baseclass for the Compiler classes that provides methods that perform generic utility functions or generate pieces of output code from information passed in by the Parser baseclass. These methods don't do any parsing themselves.
Method Summary
  addGetTextVar(self, nameChunks)
Output something that gettext can recognize.
  genCacheInfo(self, cacheTokenParts)
Decipher a placeholder cachetoken
  genCacheInfoFromArgList(self, argList)
  genCheetahVar(self, nameChunks, plain)
  genNameMapperVar(self, nameChunks)
Generate valid Python code for a Cheetah $var, using NameMapper (Unified Dotted Notation with the SearchList).
  genPlainVar(self, nameChunks)
Generate Python code for a Cheetah $var without using NameMapper (Unified Dotted Notation with the SearchList).
  genTimeInterval(self, timeString)

Method Details

addGetTextVar(self, nameChunks)

Output something that gettext can recognize.

This is a harmless side effect necessary to make gettext work when it is scanning compiled templates for strings marked for translation.

@@TR: another marginally more efficient approach would be to put the output in a dummy method that is never called.

genCacheInfo(self, cacheTokenParts)

Decipher a placeholder cachetoken

genNameMapperVar(self, nameChunks)

Generate valid Python code for a Cheetah $var, using NameMapper
(Unified Dotted Notation with the SearchList).

nameChunks = list of var subcomponents represented as tuples
  [ (name,useAC,remainderOfExpr),
  ]
where:
  name = the dotted name base
  useAC = where NameMapper should use autocalling on namemapperPart
  remainderOfExpr = any arglist, index, or slice

If remainderOfExpr contains a call arglist (e.g. '(1234)') then useAC
is False, otherwise it defaults to True. It is overridden by the global
setting 'useAutocalling' if this setting is False.

EXAMPLE
------------------------------------------------------------------------
if the raw Cheetah Var is
  $a.b.c[1].d().x.y.z
  
nameChunks is the list
  [ ('a.b.c',True,'[1]'), # A
    ('d',False,'()'),     # B
    ('x.y.z',True,''),    # C
  ]

When this method is fed the list above it returns
  VFN(VFN(VFFSL(SL, 'a.b.c',True)[1], 'd',False)(), 'x.y.z',True)
which can be represented as
  VFN(B`, name=C[0], executeCallables=(useAC and C[1]))C[2]
where:
  VFN = NameMapper.valueForName
  VFFSL = NameMapper.valueFromFrameOrSearchList
  VFSL = NameMapper.valueFromSearchList # optionally used instead of VFFSL
  SL = self.searchList()
  useAC = self.setting('useAutocalling') # True in this example
  
  A = ('a.b.c',True,'[1]')
  B = ('d',False,'()')
  C = ('x.y.z',True,'')

  C` = VFN( VFN( VFFSL(SL, 'a.b.c',True)[1],
                 'd',False)(),
            'x.y.z',True)
     = VFN(B`, name='x.y.z', executeCallables=True)
     
  B` = VFN(A`, name=B[0], executeCallables=(useAC and B[1]))B[2]
  A` = VFFSL(SL, name=A[0], executeCallables=(useAC and A[1]))A[2]


Note, if the compiler setting useStackFrames=False (default is true)
then
  A` = VFSL([locals()]+SL+[globals(), __builtin__], name=A[0], executeCallables=(useAC and A[1]))A[2]
This option allows Cheetah to be used with Psyco, which doesn't support
stack frame introspection.

genPlainVar(self, nameChunks)

Generate Python code for a Cheetah $var without using NameMapper (Unified Dotted Notation with the SearchList).

Generated by Epydoc 2.1 on Sat Mar 4 13:36:27 2006 http://epydoc.sf.net