1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Extensions of standard exceptions for PyXB events.
17
18 Yeah, I'd love this module to be named exceptions.py, but it can't
19 because the standard library has one of those, and we need to
20 reference it below.
21 """
22
23 import exceptions
26 """Base class for exceptions that indicate a problem that the user should fix."""
27
28 """The arguments passed to the exception constructor."""
29 _args = None
30
31 """The keywords passed to the exception constructor.
32
33 @note: Do not pop values from the keywords array in subclass
34 constructors that recognize and extract values from them. They
35 should be kept around so they're accessible generically."""
36 _kw = None
37
39 """Create an exception indicating a PyXB-related problem.
40
41 If no args are present, a default argument is taken from the
42 C{message} keyword.
43
44 @keyword message : Text to provide the user with information about the problem.
45 """
46 if 0 == len(args) and 'message' in kw:
47 args = (kw.pop('message'),)
48 self._args = args
49 self._kw = kw
50 exceptions.Exception.__init__(self, *args)
51
53 """Raised when the XML hierarchy does not appear to be valid for an XML schema."""
54 pass
55
57 """Violation of some rule relevant to XML Namespaces"""
58 - def __init__ (self, namespace, *args, **kw):
61
63
65 """Problem related to namespace archives"""
66 pass
67
69 """Raised when somebody tries to create a schema component using a
70 schema that has already been used in that namespace. Import and
71 include processing would have avoided this, so somebody asked for
72 it specifically."""
73 - def __init__ (self, namespace, schema_location, existing_schema, *args, **kw):
81
85
87 """Raised when something goes wrong generating the binding classes"""
88 pass
89
91 """Raised when an attempt is made to record multiple objects of the same name in the same namespace category."""
92 pass
93
95 """Raised when a value in an XML attribute does not conform to the simple type."""
96 pass
97
99 '''Raised when a name is referenced that is not defined in the appropriate namespace.'''
100 __namespace = None
101 __ncName = None
102
104 """Raised when a schema component property is accessed on a component instance that does not define that property."""
105 pass
106
108 """Raised when processing document content and an error is encountered."""
109 pass
110
112 """Raised when processing document and the content model is not satisfied."""
113 @property
115 """The L{pyxb.binding.content.ElementUse} instance to which the content should conform, if available."""
116 return self.__elementUse
117
118 @property
120 """The L{pyxb.binding.basis.complexTypeDefinition} instance to which the content would belong, if available."""
121 return self.__container
122
123 @property
124 - def content (self):
125 """The value which could not be reconciled with the content model."""
126 return self.__content
127
129 """Raised when processing document and the content model is not satisfied.
130
131 @keyword content : The value that could not be reconciled with the content model
132 @keyword container : Optional binding instance into which the content was to be assigned
133 @keyword element_use : Optional reference to an element use identifying the element to which the value was to be reconciled
134 """
135 self.__content = kw.pop('content', None)
136 if args:
137 self.__content = args[0]
138 self.__container = kw.pop('container', None)
139 self.__elementUse = kw.pop('element_use', None)
140 if self.__content is not None:
141 if self.__container is not None:
142 kw.setdefault('message', '%s cannot accept wildcard content %s' % (self.__container, self.__content))
143 elif self.__elementUse is not None:
144 kw.setdefault('message', '%s not consistent with content model for %s' % (self.__content, self.__elementUse))
145 else:
146 kw.setdefault('message', str(self.__content))
147 BadDocumentError.__init__(self, **kw)
148
150 """Raised when attempting to construct an element that is abstract."""
151 pass
152
153 -class UnrecognizedContentError (StructuralBadDocumentError):
154 """Raised when processing document and an element does not match the content model."""
155 pass
156
158 """Raised when creating an instance from a document with an unrecognized root element."""
159
160 @property
162 """The L{pyxb.namespace.ExpandedName} of the element that was not recognized."""
163 return self.__elementName
164
165 @property
167 """The DOM node associated with the unrecognized element, if available."""
168 return self.__domNode
169
171 """Raised when creating an instance from a document with an unrecognized root element.
172
173 @keyword element_name : The expanded name of the outermost element
174 @keyword dom_node : The DOM node of the outermost element, if available
175 """
176 self.__domNode = kw.get('dom_node')
177 self.__elementName = kw.get('element_name')
178 if self.__elementName is None:
179 if self.__domNode is not None:
180 import pyxb.namespace
181 self.__elementName = pyxb.namespace.ExpandedName(self.__domNode.namespaceURI, self.__domNode.localName)
182 else:
183 raise LogicError('No source for element_name in UnrecognizedElementError')
184 kw['content'] = self.__domNode
185 kw.setdefault('message', 'No element binding available for %s' % (self.__elementName,))
186 UnrecognizedContentError.__init__(self, **kw)
187
189 """Content requires an element that is not present."""
190 pass
191
193 """More instances of an element are present than permitted by the content model."""
194 pass
195
197 """Raised when processing document and there is more material in an element content than expected."""
198
199 -class ContentInNilElementError (ExtraContentError):
200 """Raised when an element that is marked to be nil has content."""
201 pass
202
203 -class MissingContentError (StructuralBadDocumentError):
204 """Raised when processing document and expected content is not present. See also UnrecognizedContentError."""
205
207 """Raised when processing document and a tag that is a type but not an element is encountered."""
208
209 @property
211 """The L{pyxb.namespace.ExpandedName} of the element that was not recognized."""
212 return self.__elementName
213
214 @property
216 """The L{pyxb.binding.content.complexTypeDefinition} in which the element was unrecognized."""
217 return self.__containingType
218
219 - def __init__ (self, element_name, containing_type, **kw):
220 """Raised when a document inner element is recognized as a type rather than an element.
221
222 @param element_name : The name of the inner element from the document
223 @param containing_type : The L{pyxb.binding.content.complexTypeDefinition} class in which the lookup failed
224 """
225 self.__elementName = element_name
226 self.__containingType = containing_type
227 kw.setdefault('message', 'Unable to locate element %s in type %s' % (element_name, self.__containingType._ExpandedName))
228 UnrecognizedContentError.__init__(self, **kw)
229
231 """Raised when an attribute is found that is not sanctioned by the content model."""
232
234 """Raised when something in the infoset fails to satisfy a content model or attribute requirement."""
235 pass
236
238 """Raised when an attribute requirement is not satisfied."""
239 pass
240
242 """Raised when an attribute that is prohibited is provided in an element."""
243
245 """Raised when an attribute that is required is missing in an element."""
246
248 """Raised when an attribute with a fixed value constraint is set to a different value."""
249
251 """Raised when somebody tries to instantiate an abstract complex type."""
252
254 """Raised when converting binding to DOM and something goes wrong."""
255 pass
256
258 """Raised when checking _isNil on a type that does not support nillable."""
259 pass
260
262 """Raised when the content of a binding object is not consistent with its content model"""
263 pass
264
266 """Raised when an element is given non-element content but may not contain such."""
267 pass
268
269 -class NoContentModel (BindingValidationError):
270 """Raised when an operation is attempted that requires a content
271 model, but the complex type has empty or simple content."""
272 pass
273
275 """Raised when the bindings are mis-used."""
276 pass
277
278 -class NotSimpleContentError (BindingError):
279 """Raised when an operation that requires simple content is
280 invoked on a complex type that does not have simple content."""
281 pass
282
283 -class NotComplexContentError (BindingError):
284 """Raised when an operation is attempted that requires a content
285 model, but the complex type has empty or simple content."""
286 pass
287
289 """Base class for exceptions that indicate a problem that the user probably can't fix."""
290 pass
291
293 """Raised when the code detects arguments to a public
294 operation."""
295
297 """Raised when the code detects an implementation problem."""
298
300 """Raised when a code branch is taken that has not yet been implemented."""
301