/usr/share/pyshared/nevow/query.py is in python-nevow 0.10.0-5.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | # Copyright (c) 2004 Divmod.
# See LICENSE for details.
"""inevow.IQ adapter implementations.
"""
import twisted.python.components as tpc
from nevow import inevow, stan
from zope.interface import implements
class QueryContext(tpc.Adapter):
implements(inevow.IQ)
def _locatePatterns(self, pattern, default, loop=True):
if self.original.tag.pattern == pattern:
yield self.original.tag.clone(deep=False, clearPattern=True)
for node in stan._locatePatterns(self.original.tag, pattern, default):
yield node
def patternGenerator(self, pattern, default=None):
return stan.PatternTag(self._locatePatterns(pattern, default))
def allPatterns(self, pattern):
if self.original.tag.pattern == pattern:
yield self.original.tag
for pat in self.original.tag.allPatterns(pattern):
yield pat
def onePattern(self, pattern):
return self.original.tag.onePattern(pattern)
class QueryList(tpc.Adapter):
def _locatePatterns(self, pattern, default, loop=True):
produced = []
for item in self.original:
try:
for x in inevow.IQ(stan.Tag("")[item])._locatePatterns(pattern, None, loop=False):
produced.append(x)
yield x.clone(deep=False, clearPattern=True)
except stan.NodeNotFound:
continue
if produced:
while True:
for x in produced:
yield x.clone(deep=False, clearPattern=True)
if default is None:
raise stan.NodeNotFound, ("pattern", pattern)
if hasattr(default, 'clone'):
while True: yield default.clone(deep=False)
else:
while True: yield default
def patternGenerator(self, pattern, default=None):
return stan.PatternTag(
self._locatePatterns(pattern, default))
def allPatterns(self, pattern):
for item in self.original:
for pat in inevow.IQ(item).allPatterns(pattern):
yield pat
def onePattern(self, pattern):
node = None
for item in self.original:
try:
newNode = inevow.IQ(item).onePattern(pattern)
except stan.NodeNotFound:
continue
else:
if node is None:
node = newNode
else:
raise stan.TooManyNodes('pattern', pattern)
if node is None:
raise stan.NodeNotFound('pattern', pattern)
return node
class QuerySlot(QueryList):
def __init__(self, original):
QueryList.__init__(self, original.children)
class QueryNeverFind(tpc.Adapter):
def patternGenerator(self, pattern, default=None):
raise stan.NodeNotFound, ('pattern', pattern)
def allPatterns(self, pattern):
return []
def onePattern(self, pattern):
raise stan.NodeNotFound, ('pattern', pattern)
def _locatePatterns(self, pattern, default, loop=True):
return []
class QueryLoader(tpc.Adapter):
def patternGenerator(self, pattern, default=None):
return inevow.IQ(self.original.load()).patternGenerator(pattern, default)
def allPatterns(self, pattern):
return inevow.IQ(self.original.load()).allPatterns(pattern)
def onePattern(self, pattern):
return inevow.IQ(self.original.load()).onePattern(pattern)
|