/
usr
/
lib64
/
python2.6
/
site-packages
/
Cheetah
/
/usr/lib64/python2.6/site-packages/Cheetah
mkdir
upload
Name
Size
Mode
Actions
Macros/
-
0755
rm
Templates/
-
0755
rm
Tests/
-
0755
rm
Tools/
-
0755
rm
Utils/
-
0755
rm
CacheRegion.py
4421
0644
edit
dl
rm
CacheRegion.pyc
6636
0644
edit
dl
rm
CacheRegion.pyo
6593
0644
edit
dl
rm
CacheStore.py
3047
0644
edit
dl
rm
CacheStore.pyc
5875
0644
edit
dl
rm
CacheStore.pyo
5875
0644
edit
dl
rm
CheetahWrapper.py
23885
0644
edit
dl
rm
CheetahWrapper.pyc
22958
0644
edit
dl
rm
CheetahWrapper.pyo
22895
0644
edit
dl
rm
Compiler.py
80284
0644
edit
dl
rm
Compiler.pyc
76754
0644
edit
dl
rm
Compiler.pyo
76680
0644
edit
dl
rm
convertTmplPathToModuleName.py
496
0644
edit
dl
rm
convertTmplPathToModuleName.pyc
706
0644
edit
dl
rm
convertTmplPathToModuleName.pyo
706
0644
edit
dl
rm
DirectiveAnalyzer.py
2445
0644
edit
dl
rm
DirectiveAnalyzer.pyc
4043
0644
edit
dl
rm
DirectiveAnalyzer.pyo
4043
0644
edit
dl
rm
Django.py
592
0644
edit
dl
rm
Django.pyc
945
0644
edit
dl
rm
Django.pyo
945
0644
edit
dl
rm
DummyTransaction.py
3277
0644
edit
dl
rm
DummyTransaction.pyc
5672
0644
edit
dl
rm
DummyTransaction.pyo
5672
0644
edit
dl
rm
ErrorCatchers.py
1755
0644
edit
dl
rm
ErrorCatchers.pyc
3610
0644
edit
dl
rm
ErrorCatchers.pyo
3610
0644
edit
dl
rm
FileUtils.py
10664
0644
edit
dl
rm
FileUtils.pyc
13455
0644
edit
dl
rm
FileUtils.pyo
13455
0644
edit
dl
rm
Filters.py
7639
0644
edit
dl
rm
Filters.pyc
8675
0644
edit
dl
rm
Filters.pyo
8675
0644
edit
dl
rm
ImportHooks.py
4476
0644
edit
dl
rm
ImportHooks.pyc
4368
0644
edit
dl
rm
ImportHooks.pyo
4368
0644
edit
dl
rm
ImportManager.py
17547
0644
edit
dl
rm
ImportManager.pyc
17284
0644
edit
dl
rm
ImportManager.pyo
17284
0644
edit
dl
rm
NameMapper.py
13093
0644
edit
dl
rm
NameMapper.pyc
14161
0644
edit
dl
rm
NameMapper.pyo
14161
0644
edit
dl
rm
Parser.py
103599
0644
edit
dl
rm
Parser.pyc
81466
0644
edit
dl
rm
Parser.pyo
81277
0644
edit
dl
rm
Servlet.py
3406
0644
edit
dl
rm
Servlet.pyc
3884
0644
edit
dl
rm
Servlet.pyo
3884
0644
edit
dl
rm
SettingsManager.py
10361
0644
edit
dl
rm
SettingsManager.pyc
11811
0644
edit
dl
rm
SettingsManager.pyo
11811
0644
edit
dl
rm
SourceReader.py
9059
0644
edit
dl
rm
SourceReader.pyc
11964
0644
edit
dl
rm
SourceReader.pyo
11964
0644
edit
dl
rm
Template.py
84747
0644
edit
dl
rm
Template.pyc
68404
0644
edit
dl
rm
Template.pyo
68320
0644
edit
dl
rm
TemplateCmdLineIface.py
3311
0644
edit
dl
rm
TemplateCmdLineIface.pyc
3986
0644
edit
dl
rm
TemplateCmdLineIface.pyo
3986
0644
edit
dl
rm
Unspecified.py
258
0644
edit
dl
rm
Unspecified.pyc
809
0644
edit
dl
rm
Unspecified.pyo
809
0644
edit
dl
rm
Version.py
1540
0644
edit
dl
rm
Version.pyc
1867
0644
edit
dl
rm
Version.pyo
1299
0644
edit
dl
rm
_namemapper.so
13576
0644
edit
dl
rm
__init__.py
582
0644
edit
dl
rm
__init__.pyc
756
0644
edit
dl
rm
__init__.pyo
756
0644
edit
dl
rm
Edit:
/usr/lib64/python2.6/site-packages/Cheetah/SettingsManager.py
(10361B)
import sys import os.path import copy as copyModule from ConfigParser import ConfigParser import re from tokenize import Intnumber, Floatnumber, Number from types import * import types import new import time from StringIO import StringIO # not cStringIO because of unicode support import imp # used by SettingsManager.updateSettingsFromPySrcFile() numberRE = re.compile(Number) complexNumberRE = re.compile('[\(]*' +Number + r'[ \t]*\+[ \t]*' + Number + '[\)]*') convertableToStrTypes = (StringType, IntType, FloatType, LongType, ComplexType, NoneType, UnicodeType) ################################################## ## FUNCTIONS ## def mergeNestedDictionaries(dict1, dict2, copy=False, deepcopy=False): """Recursively merge the values of dict2 into dict1. This little function is very handy for selectively overriding settings in a settings dictionary that has a nested structure. """ if copy: dict1 = copyModule.copy(dict1) elif deepcopy: dict1 = copyModule.deepcopy(dict1) for key, val in dict2.iteritems(): if key in dict1 and isinstance(val, dict) and isinstance(dict1[key], dict): dict1[key] = mergeNestedDictionaries(dict1[key], val) else: dict1[key] = val return dict1 def stringIsNumber(S): """Return True if theString represents a Python number, False otherwise. This also works for complex numbers and numbers with +/- in front.""" S = S.strip() if S[0] in '-+' and len(S) > 1: S = S[1:].strip() match = complexNumberRE.match(S) if not match: match = numberRE.match(S) if not match or (match.end() != len(S)): return False else: return True def convStringToNum(theString): """Convert a string representation of a Python number to the Python version""" if not stringIsNumber(theString): raise Error(theString + ' cannot be converted to a Python number') return eval(theString, {}, {}) class Error(Exception): pass class NoDefault(object): pass class ConfigParserCaseSensitive(ConfigParser): """A case sensitive version of the standard Python ConfigParser.""" def optionxform(self, optionstr): """Don't change the case as is done in the default implemenation.""" return optionstr class _SettingsCollector(object): """An abstract base class that provides the methods SettingsManager uses to collect settings from config files and strings. This class only collects settings it doesn't modify the _settings dictionary of SettingsManager instances in any way. """ _ConfigParserClass = ConfigParserCaseSensitive def readSettingsFromModule(self, mod, ignoreUnderscored=True): """Returns all settings from a Python module. """ S = {} attrs = vars(mod) for k, v in attrs.iteritems(): if (ignoreUnderscored and k.startswith('_')): continue else: S[k] = v return S def readSettingsFromPySrcStr(self, theString): """Return a dictionary of the settings in a Python src string.""" globalsDict = {'True': (1==1), 'False': (0==1), } newSettings = {'self':self} exec((theString+os.linesep), globalsDict, newSettings) del newSettings['self'] module = new.module('temp_settings_module') module.__dict__.update(newSettings) return self.readSettingsFromModule(module) def readSettingsFromConfigFileObj(self, inFile, convert=True): """Return the settings from a config file that uses the syntax accepted by Python's standard ConfigParser module (like Windows .ini files). NOTE: this method maintains case unlike the ConfigParser module, unless this class was initialized with the 'caseSensitive' keyword set to False. All setting values are initially parsed as strings. However, If the 'convert' arg is True this method will do the following value conversions: * all Python numeric literals will be coverted from string to number * The string 'None' will be converted to the Python value None * The string 'True' will be converted to a Python truth value * The string 'False' will be converted to a Python false value * Any string starting with 'python:' will be treated as a Python literal or expression that needs to be eval'd. This approach is useful for declaring lists and dictionaries. If a config section titled 'Globals' is present the options defined under it will be treated as top-level settings. """ p = self._ConfigParserClass() p.readfp(inFile) sects = p.sections() newSettings = {} sects = p.sections() newSettings = {} for s in sects: newSettings[s] = {} for o in p.options(s): if o != '__name__': newSettings[s][o] = p.get(s, o) ## loop through new settings -> deal with global settings, numbers, ## booleans and None ++ also deal with 'importSettings' commands for sect, subDict in newSettings.items(): for key, val in subDict.items(): if convert: if val.lower().startswith('python:'): subDict[key] = eval(val[7:], {}, {}) if val.lower() == 'none': subDict[key] = None if val.lower() == 'true': subDict[key] = True if val.lower() == 'false': subDict[key] = False if stringIsNumber(val): subDict[key] = convStringToNum(val) ## now deal with any 'importSettings' commands if key.lower() == 'importsettings': if val.find(';') < 0: importedSettings = self.readSettingsFromPySrcFile(val) else: path = val.split(';')[0] rest = ''.join(val.split(';')[1:]).strip() parentDict = self.readSettingsFromPySrcFile(path) importedSettings = eval('parentDict["' + rest + '"]') subDict.update(mergeNestedDictionaries(subDict, importedSettings)) if sect.lower() == 'globals': newSettings.update(newSettings[sect]) del newSettings[sect] return newSettings class SettingsManager(_SettingsCollector): """A mixin class that provides facilities for managing application settings. SettingsManager is designed to work well with nested settings dictionaries of any depth. """ def __init__(self): super(SettingsManager, self).__init__() self._settings = {} self._initializeSettings() def _defaultSettings(self): return {} def _initializeSettings(self): """A hook that allows for complex setting initialization sequences that involve references to 'self' or other settings. For example: self._settings['myCalcVal'] = self._settings['someVal'] * 15 This method should be called by the class' __init__() method when needed. The dummy implementation should be reimplemented by subclasses. """ pass ## core post startup methods def setting(self, name, default=NoDefault): """Get a setting from self._settings, with or without a default value.""" if default is NoDefault: return self._settings[name] else: return self._settings.get(name, default) def hasSetting(self, key): """True/False""" return key in self._settings def setSetting(self, name, value): """Set a setting in self._settings.""" self._settings[name] = value def settings(self): """Return a reference to the settings dictionary""" return self._settings def copySettings(self): """Returns a shallow copy of the settings dictionary""" return copyModule.copy(self._settings) def deepcopySettings(self): """Returns a deep copy of the settings dictionary""" return copyModule.deepcopy(self._settings) def updateSettings(self, newSettings, merge=True): """Update the settings with a selective merge or a complete overwrite.""" if merge: mergeNestedDictionaries(self._settings, newSettings) else: self._settings.update(newSettings) ## source specific update methods def updateSettingsFromPySrcStr(self, theString, merge=True): """Update the settings from a code in a Python src string.""" newSettings = self.readSettingsFromPySrcStr(theString) self.updateSettings(newSettings, merge=newSettings.get('mergeSettings', merge) ) def updateSettingsFromConfigFileObj(self, inFile, convert=True, merge=True): """See the docstring for .updateSettingsFromConfigFile() The caller of this method is responsible for closing the inFile file object.""" newSettings = self.readSettingsFromConfigFileObj(inFile, convert=convert) self.updateSettings(newSettings, merge=newSettings.get('mergeSettings', merge)) def updateSettingsFromConfigStr(self, configStr, convert=True, merge=True): """See the docstring for .updateSettingsFromConfigFile() """ configStr = '[globals]\n' + configStr inFile = StringIO(configStr) newSettings = self.readSettingsFromConfigFileObj(inFile, convert=convert) self.updateSettings(newSettings, merge=newSettings.get('mergeSettings', merge))
Save
cmd:
run