Mantis Bug Tracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000011 [Cheetah] Templates minor always 1969-12-31 19:33 1969-12-31 19:33
Reporter Zr40 View Status public  
Assigned To rtyler
Priority normal Resolution fixed  
Status resolved   Product Version v2.1.1
Summary 0000011: Calling a function with arguments calls the function with None
Description The code to reproduce this:

import cgi
from Cheetah.Template import Template
 
data = {
    'escape': cgi.escape,
    'request': 'foo' # simplified
}
 
t = Template("$escape($request)", searchList = [data])
t.respond()
 
 
Output:
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    t.respond()
  File "DynamicallyCompiledCheetahTemplate.py", line 86, in respond
  File "/usr/lib64/python2.6/cgi.py", line 1035, in escape
    s = s.replace("&", "&") # Must be done first!
AttributeError: 'NoneType' object has no attribute 'replace'
Additional Information
Tags No tags attached.
Attached Files

- Relationships
related to 0000017closedrtyler Discrepency between C and Python NameMapper and generated Python 

-  Notes
User avatar (0000014)
rtyler (administrator)
1969-12-31 19:33
edited on: 1969-12-31 19:33

More just a note or two to myself.

When stepping through the regression test in pdb, it appears we have bunk data in our searchList:
(Pdb) print self._CHEETAH__searchList
[{}, <DynamicallyCompiledCheetahTemplate.DynamicallyCompiledCheetahTemplate object at 0x9c6050>
;, {'request': 'foobar', 'escape': <function escape at 0x810d70>}]
(Pdb) 


Yet for some reason `escape` will be properly looked up in the searchList, but `request` will not:
(Pdb) VFFSL(self._CHEETAH__searchList,"request",True)
(Pdb) print VFFSL(self._CHEETAH__searchList,"request",True)
None
(Pdb) print VFFSL(self._CHEETAH__searchList,"escape",True)
*** TypeError: escape() takes at least 1 argument (0 given)


Odd.

User avatar (0000016)
rtyler (administrator)
1969-12-31 19:33
edited on: 1969-12-31 19:33

Brief summary of what's going on, basically "request" is a special searchList item since it's actually the name of a member of the `Template` class. How the searchList works is by building a list of "namespaces", these namespaces are by default:
  1. keyword arguments to the `respond` method
  2. Members of the `Template` object (i.e. `self`)
  3. `searchList` parameters passed in through the Template __init__() `searchList` keyword arg


The members on the Template object (i.e. `self`) are:
['NonNumericInputError', '_CHEETAH__cacheRegions', '_CHEETAH__cacheStore', '_CHEETAH__cheetahInclude
s', '_CHEETAH__currentFilter', '_CHEETAH__errorCatcher', '_CHEETAH__errorCatchers', '_CHEETAH__filte
rs', '_CHEETAH__filtersLib', '_CHEETAH__globalSetVars', '_CHEETAH__indenter', '_CHEETAH__initErrorCa
tcher', '_CHEETAH__initialFilter', '_CHEETAH__instanceInitialized', '_CHEETAH__isBuffering', '_CHEET
AH__isControlledByWebKit', '_CHEETAH__searchList', '_CHEETAH_cacheCompilationResults', '_CHEETAH_cac
heDirForModuleFiles', '_CHEETAH_cacheModuleFilesForTracebacks', '_CHEETAH_cacheRegionClass', '_CHEET
AH_cacheStore', '_CHEETAH_cacheStoreClass', '_CHEETAH_cacheStoreIdPrefix', '_CHEETAH_compileCache', 
'_CHEETAH_compileLock', '_CHEETAH_compilerClass', '_CHEETAH_compilerSettings', '_CHEETAH_defaultBase
classForTemplates', '_CHEETAH_defaultClassNameForTemplates', '_CHEETAH_defaultMainMethodName', '_CHE
ETAH_defaultMainMethodNameForTemplates', '_CHEETAH_defaultModuleGlobalsForTemplates', '_CHEETAH_defa
ultModuleNameForTemplates', '_CHEETAH_defaultPreprocessorClass', '_CHEETAH_genTime', '_CHEETAH_genTi
mestamp', '_CHEETAH_generatedModuleCode', '_CHEETAH_isInCompilationCache', '_CHEETAH_keepRefToGenera
tedCode', '_CHEETAH_preprocessors', '_CHEETAH_requiredCheetahClassAttributes', '_CHEETAH_requiredChe
etahClassMethods', '_CHEETAH_requiredCheetahMethods', '_CHEETAH_src', '_CHEETAH_srcLastModified', '_
CHEETAH_useCompilationCache', '_CHEETAH_version', '_CHEETAH_versionTuple', '__class__', '__delattr__
', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '_
_new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subcl
asshook__', '__weakref__', '_addCheetahPlumbingCodeToClass', '_compile', '_createCacheRegion', '_fil
eBaseName', '_fileDirName', '_fileMtime', '_filePath', '_getCacheStore', '_getCacheStoreIdPrefix', '
_getCompilerClass', '_getCompilerSettings', '_getTemplateAPIClassForIncludeDirectiveCompilation', '_
handleCheetahInclude', '_initCheetahInstance', '_mainCheetahMethod_for_DynamicallyCompiledCheetahTem
plate', '_normalizePreprocessorArg', '_normalizePreprocessorSettings', '_preprocessSource', '_reusab
le', '_threadSafe', '_updateSettingsWithPreprocessTokens', 'application', 'awake', 'compile', 'error
Catcher', 'generatedClassCode', 'generatedModuleCode', 'getCacheRegion', 'getCacheRegions', 'getFile
Contents', 'getVar', 'hasVar', 'i18n', 'refreshCache', 'request', 'respond', 'runAsMainProgram', 'se
archList', 'serverSidePath', 'session', 'shutdown', 'sleep', 'subclass', 'transaction', 'varExists',
 'webInput']


And since `self` takes precedence in the searchList, the NameMapper is finding `request` on the Template object, which just so happens to be None, and is passing that into your `escape` function.


What I plan on doing is placing warnings about using "reserved" keys in the searchList, but also add an compile-time option "***prioritizeSearchListOverSelf***" that will allow you to pass in items like "request" since the NameMapper will search the searchList *before* self.

User avatar (0000017)
rtyler (administrator)
1969-12-31 19:33

If you use a searchList key that will collide, Cheetah will now warn against that.

If you still want to use a key like "request", you can compile your template with the compiler setting: "prioritizeSearchListOverSelf=True"

- Issue History
Date Modified Username Field Change
1969-12-31 19:33 Zr40 New Issue
1969-12-31 19:33 rtyler Note Added: 0000013
1969-12-31 19:33 rtyler Note Added: 0000014
1969-12-31 19:33 rtyler Note Deleted: 0000013
1969-12-31 19:33 rtyler Note Edited: 0000014 View Revisions
1969-12-31 19:33 rtyler Relationship added related to 0000017
1969-12-31 19:33 rtyler Status new => assigned
1969-12-31 19:33 rtyler Assigned To => rtyler
1969-12-31 19:33 rtyler Note Added: 0000016
1969-12-31 19:33 rtyler Note Edited: 0000016 View Revisions
1969-12-31 19:33 rtyler Note Added: 0000017
1969-12-31 19:33 rtyler Status assigned => resolved
1969-12-31 19:33 rtyler Fixed in Version => v2.2.0
1969-12-31 19:33 rtyler Resolution open => fixed


Copyright © 2000 - 2009 MantisBT Group
Powered by Mantis Bugtracker