@classmethod<EOL><INDENT>def discover(cls, path, depth="<STR_LIT:0>"):<DEDENT>
<EOL>attributes = _get_attributes_from_path(path)<EOL>try:<EOL><INDENT>if len(attributes) == <NUM_LIT:3>:<EOL><INDENT>item = attributes.pop()<EOL>path = "<STR_LIT:/>".join(attributes)<EOL>collection = cls(path, _is_principal(path))<EOL>yield collection.get(item)<EOL>return<EOL><DEDENT>collection = cls(path, _is_principal(path))<EOL><DEDENT>except api.exceptions.DoesNotExist:<EOL><INDENT>return<EOL><DEDENT>yield collection<EOL>if depth == "<STR_LIT:0>":<EOL><INDENT>return<EOL><DEDENT>if len(attributes) == <NUM_LIT:0>:<EOL><INDENT>yield cls(posixpath.join(path, cls.user), principal=True)<EOL><DEDENT>elif len(attributes) == <NUM_LIT:1>:<EOL><INDENT>for journal in cls.etesync.list():<EOL><INDENT>if journal.collection.TYPE in (api.AddressBook.TYPE, api.Calendar.TYPE, api.TaskList.TYPE):<EOL><INDENT>yield cls(posixpath.join(path, journal.uid), principal=False)<EOL><DEDENT><DEDENT><DEDENT>elif len(attributes) == <NUM_LIT:2>:<EOL><INDENT>for item in collection.list():<EOL><INDENT>yield collection.get(item)<EOL><DEDENT><DEDENT>elif len(attributes) > <NUM_LIT:2>:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>
Discover a list of collections under the given ``path``.

        If ``depth`` is "0", only the actual object under ``path`` is
        returned.

        If ``depth`` is anything but "0", it is considered as "1" and direct
        children are included in the result.

        The ``path`` is relative.

        The root collection "/" must always exist.