(self, obj)
Visit an Object.
Visit an Object.
Visit an Object .
def visit(self, obj):
        """Visit an Object."""
        if not hasattr(self, 'visitors'):
            self._visit_context = {}
            self._visit_count = 0
        try:
            self._visit_count += 1
            stack = deque()
            stack.append((obj, None))
            last_result = None
            while stack:
                try:
                    last, visited = stack[-1]
                    if isinstance(last, types.GeneratorType):
                        stack.append((last.send(last_result), None))
                        last_result = None
                    elif isinstance(last, Visited):
                        stack.pop()
                        last_result = last.result
                    elif isinstance(last, Object):
                        if last in self._visit_context:
                            if self._visit_context[last] == self.visit_Object:
                                visitor = self.visit_RecursionError
                            else:
                                visitor = self.visit_Object
                        else:
                            method = 'visit_' + last.__class__.__name__
                            visitor = getattr(self, method, self.visit_Object)
                        self._visit_context[last] = visitor
                        stack.pop()
                        stack.append((visitor(last), last))
                    else:
                        method = 'visit_' + last.__class__.__name__
                        visitor = getattr(self, method, self.visit_Generic)
                        stack.pop()
                        stack.append((visitor(last), None))
                except StopIteration:
                    stack.pop()
                    if visited and visited in self._visit_context:
                        del self._visit_context[visited]
            return last_result
        finally:
            self._visit_count -= 1
            if self._visit_count <= 0:
                self._visit_context = {}
def visit ( self , obj ) : if not hasattr ( self , 'visitors' ) : self . _visit_context = { } self . _visit_count = 0 try : self . _visit_count += 1 stack = deque ( ) stack . append ( ( obj , None ) ) last_result = None while stack : try : last , visited = stack [ - 1 ] if isinstance ( last , types . GeneratorType ) : stack . append ( ( last . send ( last_result ) , None ) ) last_result = None elif isinstance ( last , Visited ) : stack . pop ( ) last_result = last . result elif isinstance ( last , Object ) : if last in self . _visit_context : if self . _visit_context [ last ] == self . visit_Object : visitor = self . visit_RecursionError else : visitor = self . visit_Object else : method = 'visit_' + last . __class__ . __name__ visitor = getattr ( self , method , self . visit_Object ) self . _visit_context [ last ] = visitor stack . pop ( ) stack . append ( ( visitor ( last ) , last ) ) else : method = 'visit_' + last . __class__ . __name__ visitor = getattr ( self , method , self . visit_Generic ) stack . pop ( ) stack . append ( ( visitor ( last ) , None ) ) except StopIteration : stack . pop ( ) if visited and visited in self . _visit_context : del self . _visit_context [ visited ] return last_result finally : self . _visit_count -= 1 if self . _visit_count <= 0 : self . _visit_context = { }