def get(self, id, pk='id', deleted=False):
        try:
            if pk == 'id':
                id = int(id)
            if deleted:
                spec = {pk: id}
            else:
                spec = {pk: id, 'data': {'$exists': 1}}
            fields = {'_id': 0}
            row = self.db.docs.find_one(spec, fields)
        except Exception as e:
            raise DatabaseException(e)
        if row:
            return Document(**row)
        raise NotFoundError('%s %s not found' % (pk, id))
def _patternrootsanddirs(kindpats):
    """Returns roots and directories corresponding to each pattern.

    This calculates the roots and directories exactly matching the patterns and
    returns a tuple of (roots, dirs) for each. It does not return other
    directories which may also need to be considered, like the parent
    directories.
    """
    r = []
    d = []
    for kind, pat, source in kindpats:
        if kind == "glob":  # find the non-glob prefix
            root = []
            for p in pat.split("/"):
                if "[" in p or "{" in p or "*" in p or "?" in p:
                    break
                root.append(p)
            r.append("/".join(root))
        elif kind in ("relpath", "path"):
            if pat == ".":
                pat = ""
            r.append(pat)
        elif kind in ("rootfilesin",):
            if pat == ".":
                pat = ""
            d.append(pat)
        else:  # relglob, re, relre
            r.append("")
    return r, d