# Path: pgcontents/error.py
# class CorruptedFile(Exception):
#     pass
# 
# class PathOutsideRoot(Exception):
#     pass
# 
# Path: pgcontents/utils/ipycompat.py



from base64 import (
    b64decode,
    b64encode,
)
from datetime import datetime
from functools import wraps
from tornado.web import HTTPError
from .error import CorruptedFile, PathOutsideRoot
from .utils.ipycompat import reads, writes
import mimetypes
import posixpath
            )
        )
    if fmt == 'text':
        # Unicode -> bytes -> base64-encoded bytes.
        return b64encode(content.encode('utf8'))
    else:
        return content.encode('ascii')


def prefix_dirs(path):
    """
    Return an iterable of all prefix directories of path, descending from root.
    """
    _dirname = posixpath.dirname
    path = path.strip('/')
    out = []
    while path != '':
        path = _dirname(path)
        out.append(path)
    return reversed(out)


def outside_root_to_404(fn):
    """
    Decorator for converting PathOutsideRoot errors to 404s.
    """
    @wraps(fn)
    def wrapped(*args, **kwargs):
        try:
            return fn(*args, **kwargs)

# Path: pgcontents/error.py
# class CorruptedFile(Exception):
#     pass
# 
# class PathOutsideRoot(Exception):
#     pass
# 
# Path: pgcontents/utils/ipycompat.py



# Path: pgcontents/api_utils.py
from base64 import (
    b64decode,
    b64encode,
)
from datetime import datetime
from functools import wraps
from tornado.web import HTTPError
from .error import CorruptedFile, PathOutsideRoot
from .utils.ipycompat import reads, writes
import mimetypes
import posixpath

            )
        )
    if fmt == 'text':
        # Unicode -> bytes -> base64-encoded bytes.
        return b64encode(content.encode('utf8'))
    else:
        return content.encode('ascii')


def prefix_dirs(path):
    """
    Return an iterable of all prefix directories of path, descending from root.
    """
    _dirname = posixpath.dirname
    path = path.strip('/')
    out = []
    while path != '':
        path = _dirname(path)
        out.append(path)
    return reversed(out)


def outside_root_to_404(fn):
    """
    Decorator for converting PathOutsideRoot errors to 404s.
    """
    @wraps(fn)
    def wrapped(*args, **kwargs):
        try:
            return fn(*args, **kwargs)

        except PathOutsideRoot as e: