Back to index

plone3  3.1.7
Classes | Functions
archetypes.kss.utils Namespace Reference

Classes

class  FrameError

Functions

def get_econtext

Class Documentation

class archetypes::kss::utils::FrameError

Definition at line 8 of file utils.py.


Function Documentation

Inspects full context of the caller page

We access the caller stack and thus the *entire*
context of the page template, including globals (defines).
(This could not be passed from the template, normally, due to
its restricted nature.)

Some explanation:

We walk up the the python expression stack until we find the
Pagetemplates.ZRPythonExpr.__call__ that has econtext
in the locals. The econtext is a 
<Products.PageTemplates.Expressions.ZopeContext object that has: 

    vars:           global and local variables combined, readonly.

    setLocal:       set local context variable

    setGlobal:      set global context variable

Definition at line 11 of file utils.py.

00011 
00012 def get_econtext():
00013     '''Inspects full context of the caller page
00014 
00015     We access the caller stack and thus the *entire*
00016     context of the page template, including globals (defines).
00017     (This could not be passed from the template, normally, due to
00018     its restricted nature.)
00019 
00020     Some explanation:
00021 
00022     We walk up the the python expression stack until we find the
00023     Pagetemplates.ZRPythonExpr.__call__ that has econtext
00024     in the locals. The econtext is a 
00025     <Products.PageTemplates.Expressions.ZopeContext object that has: 
00026 
00027         vars:           global and local variables combined, readonly.
00028 
00029         setLocal:       set local context variable
00030 
00031         setGlobal:      set global context variable
00032     
00033     '''
00034     frame = inspect.currentframe().f_back
00035     econtext = None
00036     try:
00037         while frame is not None:
00038             try:
00039                 econtext = frame.f_locals['econtext']
00040             except KeyError:
00041                 # go one frame up
00042                 frame = frame.f_back
00043             else:
00044                 # found
00045                 return econtext
00046         else: 
00047             # Econtext frame not found
00048             return None
00049     finally:
00050         del frame
00051         del econtext

Here is the caller graph for this function: