App Engine Python SDK version 1.9.13
[gae.git] / python / google / appengine / api / yaml_errors.py
blob9afd3a991ae85c4d673daab1a3bc4cbeb4e6e402
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 """Errors used in the YAML API, which is used by app developers."""
26 class Error(Exception):
27 """Base datastore yaml error type."""
29 class ProtocolBufferParseError(Error):
30 """Error in protocol buffer parsing"""
33 class EmptyConfigurationFile(Error):
34 """Tried to load empty configuration file."""
37 class MultipleConfigurationFile(Error):
38 """Tried to load configuration file with multiple objects."""
41 class AmbiguousConfigurationFiles(Error):
42 """Both YAML and XML files exist for the same configuration information."""
45 class UnexpectedAttribute(Error):
46 """Raised when an unexpected attribute is encounted."""
49 class DuplicateAttribute(Error):
50 """Generated when an attribute is assigned to twice."""
53 class ListenerConfigurationError(Error):
54 """Generated when there is a parsing problem due to configuration."""
57 class IllegalEvent(Error):
58 """Raised when an unexpected event type is received by listener."""
61 class InternalError(Error):
62 """Raised when an internal implementation error is detected."""
65 class EventListenerError(Error):
66 """Top level exception raised by YAML listener.
68 Any exception raised within the process of parsing a YAML file via an
69 EventListener is caught and wrapped in an EventListenerError. The causing
70 exception is maintained, but additional useful information is saved which
71 can be used for reporting useful information to users.
73 Attributes:
74 cause: The original exception which caused the EventListenerError.
75 """
77 def __init__(self, cause):
78 """Initialize event-listener error."""
79 if hasattr(cause, 'args') and cause.args:
80 Error.__init__(self, *cause.args)
81 else:
84 Error.__init__(self, str(cause))
85 self.cause = cause
88 class EventListenerYAMLError(EventListenerError):
89 """Generated specifically for yaml.error.YAMLError."""
92 class EventError(EventListenerError):
93 """Generated specifically when an error occurs in event handler.
95 Attributes:
96 cause: The original exception which caused the EventListenerError.
97 event: Event being handled when exception occured.
98 """
100 def __init__(self, cause, event):
101 """Initialize event-listener error."""
102 EventListenerError.__init__(self, cause)
103 self.event = event
105 def __str__(self):
106 return '%s\n%s' % (self.cause, self.event.start_mark)