Expression.py :  » Issue-Tracker » IssueTracker » IssueTrackerProduct » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Issue Tracker » IssueTracker 
IssueTracker » IssueTrackerProduct » Expression.py
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
""" Expressions in a web-configurable workflow.

$Id: Expression.py 67708 2006-04-28 10:45:12Z yuppie $

Copied from CMFCore and modified for IssueTrackerProduct

"""



from AccessControl import ClassSecurityInfo
from Acquisition import aq_base,aq_inner,aq_parent
from Products.PageTemplates.Expressions import getEngine
from Products.PageTemplates.Expressions import SecureModuleImporter

try:
    # >= Zope 2.12
    from Persistence import Persistent
    from App.class_init import InitializeClass
except ImportError:
    # < Zope 2.12
    from Globals import Persistent,InitializeClass



class Expression (Persistent):
    text = ''
    _v_compiled = None

    security = ClassSecurityInfo()

    def __init__(self, text):
        self.text = text
        self._v_compiled = getEngine().compile(text)

    def __call__(self, econtext):
        compiled = self._v_compiled
        if compiled is None:
            compiled = self._v_compiled = getEngine().compile(self.text)
        # ?? Maybe expressions should manipulate the security
        # context stack.
        res = compiled(econtext)
        if isinstance(res, Exception):
            raise res
        #print 'returning %s from %s' % (`res`, self.text)
        return res

InitializeClass(Expression)


def getExprContext(context, object=None, extra_namespaces={}, use_cache_if_possible=False):
    request = getattr(context, 'REQUEST', None)
    if request:
        if use_cache_if_possible:
            cache = request.get('_ec_cache', None)
        else:
            cache = None
            
        if cache is None:
            request['_ec_cache'] = cache = {}
        ec = cache.get( id(object), None )
    else:
        ec = None
    if ec is None:
        #utool = getToolByName(context, 'portal_url')
        #portal = utool.getPortalObject()
        issuetracker = context.getRoot()
        if object is None or not hasattr(object, 'aq_base'):
            folder = issuetracker
        else:
            folder = object
            # Search up the containment hierarchy until we find an
            # object that claims it's a folder.
            while folder is not None:
                if getattr(aq_base(folder), 'isPrincipiaFolderish', 0):
                    # found it.
                    break
                else:
                    folder = aq_parent(aq_inner(folder))
        ec = createExprContext(folder, issuetracker, object, **extra_namespaces)
        if request:
            cache[ id(object) ] = ec
    return ec


def createExprContext(folder, issuetracker, object, **extra_namespaces):
    '''
    An expression context provides names for TALES expressions.
    '''
    #pm = getToolByName(portal, 'portal_membership')
    if object is None:
        object_url = ''
    else:
        object_url = object.absolute_url()
    #if pm.isAnonymousUser():
    #    member = None
    #else:
    #    member = pm.getAuthenticatedMember()
    data = {
        'object_url':   object_url,
        'folder_url':   folder.absolute_url(),
        #'portal_url':   portal.absolute_url(),
        'object':       object,
        'folder':       folder,
        #'portal':       portal,
        'issuetracker': issuetracker,
        'nothing':      None,
        'request':      getattr(folder, 'REQUEST', None),
        'modules':      SecureModuleImporter,
        #'member':       member,
        'here':         object,
        }
    data.update(extra_namespaces)
    return getEngine().getContext(data)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.