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