/usr/share/pyshared/glitch/context.py is in python-glitch 0.6-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | "The rendering context object."
import copy
_no_value = object()
class Context(dict):
"""The rendering context object.
The rendering context is used by a node to communicate state to its
children. It acts like a dictionary, in that values are stored and
retrieved by keys, and like a stack, in that its state can be saved and
restored.
"""
def __init__(self, init=None):
self.stack = []
if init is not None:
dict.__init__(self, init)
else:
dict.__init__(self)
def push(self, key, value=_no_value):
"""Save the current state, then save a value.
@return: A value that pops the current state on the exit of a
C{with} statement.
"""
if key in self:
old = copy.copy(self[key])
def restore():
self[key] = old
else:
def restore():
if key in self:
del self[key]
self.stack.append(restore)
if value is not _no_value:
self[key] = value
class Push(object):
def __enter__(self_):
pass
def __exit__(self_, type, exc, tb):
self.pop()
return Push()
def pop(self):
"Pop the current state, undoing any changes since the last push."
restore = self.stack.pop()
restore()
def __repr__(self):
return 'Context(%s)' % dict.__repr__(self)
|