# 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
    assert len(normalized), "Empty path in from_api_filename"
    return '/' + normalized


def to_api_path(db_path):
    """
    Convert database path into API-style path.
    """
    return db_path.strip('/')


def split_api_filepath(path):
    """
    Split an API file path into directory and name.
    """
    parts = path.rsplit('/', 1)
    if len(parts) == 1:
        name = parts[0]
        dirname = '/'
    else:
        name = parts[1]
        dirname = parts[0] + '/'

    return from_api_dirname(dirname), name


def writes_base64(nb, version=NBFORMAT_VERSION):
    """
    Write a notebook as base64.
    """

# 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

    assert len(normalized), "Empty path in from_api_filename"
    return '/' + normalized


def to_api_path(db_path):
    """
    Convert database path into API-style path.
    """
    return db_path.strip('/')


def split_api_filepath(path):
    """
    Split an API file path into directory and name.
    """
    parts = path.rsplit('/', 1)
    if len(parts) == 1:
        name = parts[0]
        dirname = '/'
    else:
        name = parts[1]
        dirname = parts[0] + '/'

    return from_api_dirname(dirname), name


def writes_base64(nb, version=NBFORMAT_VERSION):
    """
    Write a notebook as base64.
    """

    return b64encode(writes(nb, version=version).encode('utf-8'))