summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/visitors.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/visitors.py')
-rw-r--r--lib/sqlalchemy/sql/visitors.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py
index 91ded1130..8011aa109 100644
--- a/lib/sqlalchemy/sql/visitors.py
+++ b/lib/sqlalchemy/sql/visitors.py
@@ -32,18 +32,18 @@ __all__ = ['VisitableType', 'Visitable', 'ClauseVisitor',
'CloningVisitor', 'ReplacingCloningVisitor', 'iterate',
'iterate_depthfirst', 'traverse_using', 'traverse',
'cloned_traverse', 'replacement_traverse']
-
+
class VisitableType(type):
"""Metaclass which checks for a `__visit_name__` attribute and
applies `_compiler_dispatch` method to classes.
-
+
"""
-
+
def __init__(cls, clsname, bases, clsdict):
if cls.__name__ == 'Visitable' or not hasattr(cls, '__visit_name__'):
super(VisitableType, cls).__init__(clsname, bases, clsdict)
return
-
+
# set up an optimized visit dispatch function
# for use by the compiler
if '__visit_name__' in cls.__dict__:
@@ -57,13 +57,13 @@ class VisitableType(type):
return getattr(visitor, 'visit_%s' % self.__visit_name__)(self, **kw)
cls._compiler_dispatch = _compiler_dispatch
-
+
super(VisitableType, cls).__init__(clsname, bases, clsdict)
class Visitable(object):
"""Base class for visitable objects, applies the
``VisitableType`` metaclass.
-
+
"""
__metaclass__ = VisitableType
@@ -71,27 +71,27 @@ class Visitable(object):
class ClauseVisitor(object):
"""Base class for visitor objects which can traverse using
the traverse() function.
-
+
"""
-
+
__traverse_options__ = {}
-
+
def traverse_single(self, obj, **kw):
for v in self._visitor_iterator:
meth = getattr(v, "visit_%s" % obj.__visit_name__, None)
if meth:
return meth(obj, **kw)
-
+
def iterate(self, obj):
"""traverse the given expression structure, returning an iterator of all elements."""
return iterate(obj, self.__traverse_options__)
-
+
def traverse(self, obj):
"""traverse and visit the given expression structure."""
return traverse(obj, self.__traverse_options__, self._visitor_dict)
-
+
@util.memoized_property
def _visitor_dict(self):
visitors = {}
@@ -100,11 +100,11 @@ class ClauseVisitor(object):
if name.startswith('visit_'):
visitors[name[6:]] = getattr(self, name)
return visitors
-
+
@property
def _visitor_iterator(self):
"""iterate through this visitor and each 'chained' visitor."""
-
+
v = self
while v:
yield v
@@ -112,9 +112,9 @@ class ClauseVisitor(object):
def chain(self, visitor):
"""'chain' an additional ClauseVisitor onto this ClauseVisitor.
-
+
the chained visitor will receive all visit events after this one.
-
+
"""
tail = list(self._visitor_iterator)[-1]
tail._next = visitor
@@ -123,7 +123,7 @@ class ClauseVisitor(object):
class CloningVisitor(ClauseVisitor):
"""Base class for visitor objects which can traverse using
the cloned_traverse() function.
-
+
"""
def copy_and_process(self, list_):
@@ -139,12 +139,12 @@ class CloningVisitor(ClauseVisitor):
class ReplacingCloningVisitor(CloningVisitor):
"""Base class for visitor objects which can traverse using
the replacement_traverse() function.
-
+
"""
def replace(self, elem):
"""receive pre-copied elements during a cloning traversal.
-
+
If the method returns a new element, the element is used
instead of creating a simple copy of the element. Traversal
will halt on the newly returned element if it is re-encountered.
@@ -163,9 +163,9 @@ class ReplacingCloningVisitor(CloningVisitor):
def iterate(obj, opts):
"""traverse the given expression structure, returning an iterator.
-
+
traversal is configured to be breadth-first.
-
+
"""
stack = deque([obj])
while stack:
@@ -176,9 +176,9 @@ def iterate(obj, opts):
def iterate_depthfirst(obj, opts):
"""traverse the given expression structure, returning an iterator.
-
+
traversal is configured to be depth-first.
-
+
"""
stack = deque([obj])
traversal = deque()
@@ -197,7 +197,7 @@ def traverse_using(iterator, obj, visitors):
if meth:
meth(target)
return obj
-
+
def traverse(obj, opts, visitors):
"""traverse and visit the given expression structure using the default iterator."""
@@ -210,7 +210,7 @@ def traverse_depthfirst(obj, opts, visitors):
def cloned_traverse(obj, opts, visitors):
"""clone the given expression structure, allowing modifications by visitors."""
-
+
cloned = util.column_dict()
def clone(element):
@@ -237,7 +237,7 @@ def cloned_traverse(obj, opts, visitors):
def replacement_traverse(obj, opts, replace):
"""clone the given expression structure, allowing element replacement by a given replacement function."""
-
+
cloned = util.column_dict()
stop_on = util.column_set(opts.get('stop_on', []))