1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 The I{query} module defines a class for performing schema queries.
19 """
20
21 from logging import getLogger
22 from suds import *
23 from suds.sudsobject import *
24 from suds.xsd import qualify, isqref
25 from suds.xsd.sxbuiltin import Factory
26
27 log = getLogger(__name__)
28
29
31 """
32 Schema query base class.
33 """
34
36 """
37 @param ref: The schema reference being queried.
38 @type ref: qref
39 """
40 Object.__init__(self)
41 self.id = objid(self)
42 self.ref = ref
43 self.history = []
44 self.resolved = False
45 if not isqref(self.ref):
46 raise Exception('%s, must be qref' % tostr(self.ref))
47
49 """
50 Execute this query using the specified schema.
51 @param schema: The schema associated with the query. The schema
52 is used by the query to search for items.
53 @type schema: L{schema.Schema}
54 @return: The item matching the search criteria.
55 @rtype: L{sxbase.SchemaObject}
56 """
57 raise Exception, 'not-implemented by subclass'
58
60 """
61 Filter the specified result based on query criteria.
62 @param result: A potential result.
63 @type result: L{sxbase.SchemaObject}
64 @return: True if result should be excluded.
65 @rtype: boolean
66 """
67 if result is None:
68 return True
69 reject = ( result in self.history )
70 if reject:
71 log.debug('result %s, rejected by\n%s', Repr(result), self)
72 return reject
73
75 """
76 Query result post processing.
77 @param result: A query result.
78 @type result: L{sxbase.SchemaObject}
79 """
80 if result is None:
81 log.debug('%s, not-found', self.ref)
82 return
83 if self.resolved:
84 result = result.resolve()
85 log.debug('%s, found as: %s', self.ref, Repr(result))
86 self.history.append(result)
87 return result
88
89
91 """
92 Schema query class that I{blindly} searches for a reference in
93 the specified schema. It may be used to find Elements and Types but
94 will match on an Element first. This query will also find builtins.
95 """
96
115
116
118 """
119 Schema query class that searches for Type references in
120 the specified schema. Matches on root types only.
121 """
122
133
134
136 """
137 Schema query class that searches for Group references in
138 the specified schema.
139 """
140
146
147
149 """
150 Schema query class that searches for Attribute references in
151 the specified schema. Matches on root Attribute by qname first, then searches
152 deep into the document.
153 """
154
160
171
172
174 """
175 Schema query class that searches for attributeGroup references in
176 the specified schema.
177 """
178
184
185
187 """
188 Schema query class that searches for Element references in
189 the specified schema. Matches on root Elements by qname first, then searches
190 deep into the document.
191 """
192
198
209