Introduce dynamic scope_path regexps
Instead of relying on scope_path's being "one slash deep", we should
instead allow for either:
1. scope_paths that have a pre-defined depth
2. scope_paths that can be arbitrarily deep
We achieve 1 by setting an entities scope_logic to another logic
module. We then recursively call getScopeDepth until we get to the
topmost entity (that is, an unscoped entity).
A little different is the solution to 2, since some entities can have
an arbitrarily deep scope (such as Documents), we need to have some
way of signaling this to getScopePattern. A clean solution is to
return None, rather than a number. If None is returned, the
SCOPE_PATH_ARG_PATTERN is returned as regexp instead, which will
match an arbitrarily deeply nested scope.
The solution for 2 requires that we return None somewhere in the
scope_logic chain, the most straight forward method to do so is to
override getScopeDepth anywhere such a scope is needed and make it
return None. A more elegant solution however, is to set the
scope_logic to that module in all entities that require it.
Patch by: Sverre Rabbelier
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Errors used in the YAML API, which is used by app developers."""
class Error(Exception):
"""Base datastore yaml error type."""
class ProtocolBufferParseError(Error):
"""Error in protocol buffer parsing"""
class EmptyConfigurationFile(Error):
"""Tried to load empty configuration file."""
class MultipleConfigurationFile(Error):
"""Tried to load configuration file with multiple objects."""
class UnexpectedAttribute(Error):
"""Raised when an unexpected attribute is encounted."""
class DuplicateAttribute(Error):
"""Generated when an attribute is assigned to twice."""
class ListenerConfigurationError(Error):
"""Generated when there is a parsing problem due to configuration."""
class IllegalEvent(Error):
"""Raised when an unexpected event type is received by listener."""
class InternalError(Error):
"""Raised when an internal implementation error is detected."""
class EventListenerError(Error):
"""Top level exception raised by YAML listener.
Any exception raised within the process of parsing a YAML file via an
EventListener is caught and wrapped in an EventListenerError. The causing
exception is maintained, but additional useful information is saved which
can be used for reporting useful information to users.
Attributes:
cause: The original exception which caused the EventListenerError.
"""
def __init__(self, cause):
"""Initialize event-listener error."""
if hasattr(cause, 'args') and cause.args:
Error.__init__(self, *cause.args)
else:
Error.__init__(self, str(cause))
self.cause = cause
class EventListenerYAMLError(EventListenerError):
"""Generated specifically for yaml.error.YAMLError."""
class EventError(EventListenerError):
"""Generated specifically when an error occurs in event handler.
Attributes:
cause: The original exception which caused the EventListenerError.
event: Event being handled when exception occured.
"""
def __init__(self, cause, event):
"""Initialize event-listener error."""
EventListenerError.__init__(self, cause)
self.event = event
def __str__(self):
return '%s\n%s' % (self.cause, self.event.start_mark)