"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Cheetah/NameMapper.py" between
cheetah3-3.1.0.tar.gz and cheetah3-3.2.0.tar.gz

About: Cheetah3 is a template engine and code generation tool for e.g. for Web development or Java, SQL, LaTeX, form email ... (written in Python).

NameMapper.py  (cheetah3-3.1.0):NameMapper.py  (cheetah3-3.2.0)
skipping to change at line 195 skipping to change at line 195
def _isInstanceOrClass(obj): def _isInstanceOrClass(obj):
if isinstance(obj, type): if isinstance(obj, type):
# oldstyle # oldstyle
return True return True
if hasattr(obj, "__class__"): if hasattr(obj, "__class__"):
# newstyle # newstyle
if hasattr(obj, 'mro'): if hasattr(obj, 'mro'):
# type/class # type/class
return True return True
elif (hasattr(obj, '__func__') or hasattr(obj, '__code__') or elif (hasattr(obj, '__func__') or hasattr(obj, '__code__')
hasattr(obj, '__self__')): or hasattr(obj, '__self__')):
# method, func, or builtin func # method, func, or builtin func
return False return False
elif hasattr(obj, '__init__'): elif hasattr(obj, '__init__'):
# instance # instance
return True return True
return False return False
def hasKey(obj, key): def hasKey(obj, key):
"""Determine if 'obj' has 'key' """ """Determine if 'obj' has 'key' """
if isinstance(obj, Mapping) and key in obj: if isinstance(obj, Mapping) and key in obj:
skipping to change at line 253 skipping to change at line 253
if not hasKey(obj, key): if not hasKey(obj, key):
return False return False
try: try:
valueForName(obj, name) valueForName(obj, name)
return True return True
except NotFound: except NotFound:
return False return False
try: try:
from Cheetah._namemapper import NotFound, valueForKey, valueForName, \ from Cheetah._namemapper import NotFound, valueForKey, valueForName, \
valueFromSearchList, valueFromFrameOrSearchList, valueFromFrame valueFromSearchList, valueFromFrameOrSearchList, valueFromFrame
C_VERSION = True C_VERSION = True
except Exception: except Exception:
class NotFound(LookupError): class NotFound(LookupError):
pass pass
def valueForKey(obj, key): def valueForKey(obj, key):
if isinstance(obj, Mapping) and key in obj: if isinstance(obj, Mapping) and key in obj:
return obj[key] return obj[key]
elif hasattr(obj, key): elif hasattr(obj, key):
return getattr(obj, key) return getattr(obj, key)
skipping to change at line 355 skipping to change at line 355
classBvar = 'classBvar val' classBvar = 'classBvar val'
a = A() a = A()
a.one = 'valueForOne' a.one = 'valueForOne'
def function(whichOne='default'): def function(whichOne='default'):
values = { values = {
'default': 'default output', 'default': 'default output',
'one': 'output option one', 'one': 'output option one',
'two': 'output option two' 'two': 'output option two'
} }
return values[whichOne] return values[whichOne]
a.dic = { a.dic = {
'func': function, 'func': function,
'method': a.method3, 'method': a.method3,
'item': 'itemval', 'item': 'itemval',
'subDict': {'nestedMethod': a.method3} 'subDict': {'nestedMethod': a.method3}
} }
# b = 'this is local b' # b = 'this is local b'
print(valueForKey(a.dic, 'subDict')) print(valueForKey(a.dic, 'subDict'))
print(valueForName(a, 'dic.item')) print(valueForName(a, 'dic.item'))
print(valueForName(vars(), 'b')) print(valueForName(vars(), 'b'))
print(valueForName(__builtins__, 'dir')()) print(valueForName(__builtins__, 'dir')())
print(valueForName(vars(), 'a.classVar')) print(valueForName(vars(), 'a.classVar'))
print(valueForName(vars(), 'a.dic.func', executeCallables=True)) print(valueForName(vars(), 'a.dic.func', executeCallables=True))
print(valueForName(vars(), 'a.method2.item1', executeCallables=True)) print(valueForName(vars(), 'a.method2.item1', executeCallables=True))
 End of changes. 4 change blocks. 
5 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)