def traverse(self, name, furtherPath): attr = getattr(self.context, name, _marker) if attr is not _marker: return attr if hasattr(self.context, '__getitem__'): try: return self.context[name] except KeyError: pass # Look for a sub-directory. target_path = traversal_path(self.context, name) for func, factory, setup in ((content_path, Directory, metadata_setup), ): path = isdir(func(target_path)) if path: node = factory(path) locate(node, self.context, name) setup(node) return node # Look for content or metadata. for func, factory, setup in ((content_path, Content, metadata_setup), (metadata_path, Metadata, metadata_setup)): path = exists(func(target_path)) if path: node = factory(path) locate(node, self.context, name) setup(node) return node raise TraversalError(self.context, name)