Package Products :: Package ZenUtils :: Module ZenTales |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenUtils.ZenTales

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 as published by
     8  # the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13
    14  from Products.PageTemplates.Expressions import getEngine
    15  from DateTime import DateTime
    16
    17  _compiled = {}
    18
    19 -def talesEvalStr(expression, context, extra=None):
    20      return talesEval('string:%s' % expression, context, extra)
    21
    22
    23 -def talesEval(express, context, extra=None):
    24      """Perform a TALES eval on the express using context.
    25      """
    26      compiled = talesCompile(express)
    27      contextDict = { 'here':context,
    28                      'nothing':None,
    29                      'now': DateTime(),
    30                      }
    31      if isinstance(extra, dict):
    32          contextDict.update(extra)
    33      res = compiled(getEngine().getContext(contextDict))
    34      if isinstance(res, Exception):
    35          raise res
    36      return res
    37
    38 -def talesCompile(express):
    39      compiled = _compiled.get(express, None)
    40      if not compiled:
    41          _compiled[express] = compiled = getEngine().compile(express)
    42      return compiled
    43