コード例 #1
0
ファイル: spyce.py プロジェクト: arunsh-git/xbmc-fork
 def __init__(self, 
     config_file=None,
     overide_www_root=None,
     overide_www_port=None,
   ):
   # server object
   self.serverobject = spyceServerObject()
   # http headers
   try: self.entry = os.environ[SPYCE_ENTRY]
   except: self.entry = 'UNKNOWN'
   self.spyceHeader = 'Spyce/%s_%s Python/%s' % (self.entry, str(__version__), sys.version[:3])
   # configuration dictionary
   self.config = spyceConfig.spyceConfig(
     file=config_file,
     overide_www_root=overide_www_root,
     overide_www_port=overide_www_port,
   )
   # server globals/constants
   self.globals = self.config.getSpyceGlobals()
   # spyce module search path
   self.path = self.config.getSpycePath()
   # concurrency mode
   self.concurrency = self.config.getSpyceConcurrency()
   # imports
   self.imports = self.config.getSpyceImport()
   # debug mode
   self.debug = self.config.getSpyceDebug()
   # spyce cache
   type, info = self.config.getSpyceCache()
   if type in ('file',):
     type = spyceCache.fileCache(info)
   elif type in ('mem', 'memory'):
     type = spyceCache.memoryCache(info)
   else: type = spyceCache.memoryCache()
   if self.debug: type = None
   self.spyce_cache = spyceCache.semanticCache(type, spyceCacheValid, spyceCacheGenerate)
   # spyce module cache
   self.module_cache = {}
   if self.debug:
     self.module_cache = None
   # page error handler
   pageerror = self.config.getSpycePageError()
   if pageerror[0]=='string':
     pageerror = pageerror[0], self.loadModule(pageerror[2], pageerror[1]+'.py')
   self.pageerror = pageerror
   # engine error handler
   error = self.config.getSpyceError()
   self.error = self.loadModule(error[1], error[0]+'.py')
   # spyce thread-safe stdout object
   if self.concurrency == spyceConfig.SPYCE_CONCURRENCY_THREAD:
     self.stdout = spyceUtil.ThreadedWriter(sys.stdout)
     self.lock = spyceLock.threadLock()
   else:
     self.stdout = spyceUtil.NonThreadedWriter(sys.stdout)
     self.lock = spyceLock.dummyLock()
   # set sys.stdout
   sys.stdout = self.stdout
コード例 #2
0
    def cheetah(self, filename, lookup=None):
        "Hook into the Cheetah template engine."
        # check whether cheetah installed
        from Cheetah.Compiler import Compiler

        # define template cache
        if not self._api.getModule("pool").has_key("cheetahCache"):
            self._api.getModule("pool")["cheetahCache"] = spyceCache.semanticCache(
                spyceCache.memoryCache(), cheetahValid, cheetahGenerate
            )
        cheetahCache = self._api.getModule("pool")["cheetahCache"]
        # absolute filename, relative to script filename
        filename = os.path.abspath(os.path.join(os.path.dirname(self._api.getFilename()), filename))
        # set lookup variables
        if lookup == None:
            import inspect

            lookup = [inspect.currentframe().f_back.f_locals, inspect.currentframe().f_back.f_globals]
        elif type(lookup) != type([]):
            lookup = [lookup]
        # compile (or get cached) and run template
        return cheetahCache[filename](searchList=lookup)
コード例 #3
0
ファイル: template.py プロジェクト: arunsh-git/xbmc-fork
 def cheetah(self, filename, lookup=None):
     "Hook into the Cheetah template engine."
     # check whether cheetah installed
     from Cheetah.Compiler import Compiler
     # define template cache
     if not self._api.getModule('pool').has_key('cheetahCache'):
         self._api.getModule(
             'pool')['cheetahCache'] = spyceCache.semanticCache(
                 spyceCache.memoryCache(), cheetahValid, cheetahGenerate)
     cheetahCache = self._api.getModule('pool')['cheetahCache']
     # absolute filename, relative to script filename
     filename = os.path.abspath(
         os.path.join(os.path.dirname(self._api.getFilename()), filename))
     # set lookup variables
     if lookup == None:
         import inspect
         lookup = [
             inspect.currentframe().f_back.f_locals,
             inspect.currentframe().f_back.f_globals
         ]
     elif type(lookup) != type([]):
         lookup = [lookup]
     # compile (or get cached) and run template
     return cheetahCache[filename](searchList=lookup)