# 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
    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'))


def reads_base64(nb, as_version=NBFORMAT_VERSION):
    """
    Read a notebook from base64.
    """
    try:

# 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

    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'))


def reads_base64(nb, as_version=NBFORMAT_VERSION):
    """
    Read a notebook from base64.
    """
    try:

        return reads(b64decode(nb).decode('utf-8'), as_version=as_version)