# Path: pgcontents/api_utils.py
# def api_path_join(*paths):
#     """
#     Join API-style paths.
#     """
#     return posixpath.join(*paths).strip('/')
# 
# Path: pgcontents/crypto.py
# class FernetEncryption(object):
#     """
#     Notebook encryption using cryptography.fernet for symmetric-key encryption.
# 
#     Parameters
#     ----------
#     fernet : cryptography.fernet.Fernet
#        The Fernet object to use for encryption.
# 
#     Methods
#     -------
#     encrypt : callable[bytes -> bytes]
#     decrypt : callable[bytes -> bytes]
# 
#     Notes
#     -----
#     ``cryptography.fernet.MultiFernet`` can be used instead of a vanilla
#     ``Fernet`` to allow zero-downtime key rotation.
# 
#     See Also
#     --------
#     :func:`pgcontents.utils.sync.reencrypt_user`
#     """
#     __slots__ = ('_fernet',)
# 
#     def __init__(self, fernet):
#         self._fernet = fernet
# 
#     def encrypt(self, s):
#         return self._fernet.encrypt(s)
# 
#     def decrypt(self, s):
#         try:
#             return self._fernet.decrypt(s)
#         except Exception as e:
#             raise CorruptedFile(e)
# 
#     def __copy__(self, memo):
#         # Any value that appears in an IPython/Jupyter Config object needs to
#         # be deepcopy-able. Cryptography's Fernet objects aren't deepcopy-able,
#         # so we copy our underlying state to a new FernetEncryption object.
#         return FernetEncryption(self._fernet)
# 
#     def __deepcopy__(self, memo):
#         # Any value that appears in an IPython/Jupyter Config object needs to
#         # be deepcopy-able. Cryptography's Fernet objects aren't deepcopy-able,
#         # so we copy our underlying state to a new FernetEncryption object.
#         return FernetEncryption(self._fernet)
# 
# Path: pgcontents/schema.py

# 
# Path: pgcontents/utils/ipycompat.py

# 
# Path: pgcontents/utils/migrate.py
# def upgrade(db_url, revision):
#     """
#     Upgrade the given database to revision.
#     """
#     with temp_alembic_ini(ALEMBIC_DIR_LOCATION, db_url) as alembic_ini:
#         subprocess.check_call(
#             ['alembic', '-c', alembic_ini, 'upgrade', revision]
#         )


from contextlib import contextmanager
from cryptography.fernet import Fernet
from getpass import getuser
from itertools import starmap
from unicodedata import normalize
from IPython.utils import py3compat
from nose.tools import nottest
from sqlalchemy import create_engine
from tornado.web import HTTPError
from ..api_utils import api_path_join
from ..crypto import FernetEncryption
from ..schema import metadata
from ..utils.ipycompat import (
    new_code_cell,
    new_markdown_cell,
    new_notebook,
    new_raw_cell,
)
from ..utils.migrate import upgrade
import os
import posixpath
    """Normalize unicode strings"""
    return normalize('NFC', py3compat.cast_unicode(s))


@contextmanager
def assertRaisesHTTPError(testcase, status, msg=None):
    msg = msg or "Should have raised HTTPError(%i)" % status
    try:
        yield
    except HTTPError as e:
        testcase.assertEqual(e.status_code, status)
    else:
        testcase.fail(msg)


_tables = (
    'pgcontents.remote_checkpoints',
    'pgcontents.files',
    'pgcontents.directories',
    'pgcontents.users',
)
unexpected_tables = set(metadata.tables) - set(_tables)
if unexpected_tables:
    raise Exception("Unexpected tables in metadata: %s" % unexpected_tables)


@nottest
def clear_test_db():
    engine = create_engine(TEST_DB_URL)
    with engine.connect() as conn:

# Path: pgcontents/api_utils.py
# def api_path_join(*paths):
#     """
#     Join API-style paths.
#     """
#     return posixpath.join(*paths).strip('/')
# 
# Path: pgcontents/crypto.py
# class FernetEncryption(object):
#     """
#     Notebook encryption using cryptography.fernet for symmetric-key encryption.
# 
#     Parameters
#     ----------
#     fernet : cryptography.fernet.Fernet
#        The Fernet object to use for encryption.
# 
#     Methods
#     -------
#     encrypt : callable[bytes -> bytes]
#     decrypt : callable[bytes -> bytes]
# 
#     Notes
#     -----
#     ``cryptography.fernet.MultiFernet`` can be used instead of a vanilla
#     ``Fernet`` to allow zero-downtime key rotation.
# 
#     See Also
#     --------
#     :func:`pgcontents.utils.sync.reencrypt_user`
#     """
#     __slots__ = ('_fernet',)
# 
#     def __init__(self, fernet):
#         self._fernet = fernet
# 
#     def encrypt(self, s):
#         return self._fernet.encrypt(s)
# 
#     def decrypt(self, s):
#         try:
#             return self._fernet.decrypt(s)
#         except Exception as e:
#             raise CorruptedFile(e)
# 
#     def __copy__(self, memo):
#         # Any value that appears in an IPython/Jupyter Config object needs to
#         # be deepcopy-able. Cryptography's Fernet objects aren't deepcopy-able,
#         # so we copy our underlying state to a new FernetEncryption object.
#         return FernetEncryption(self._fernet)
# 
#     def __deepcopy__(self, memo):
#         # Any value that appears in an IPython/Jupyter Config object needs to
#         # be deepcopy-able. Cryptography's Fernet objects aren't deepcopy-able,
#         # so we copy our underlying state to a new FernetEncryption object.
#         return FernetEncryption(self._fernet)
# 
# Path: pgcontents/schema.py

# 
# Path: pgcontents/utils/ipycompat.py

# 
# Path: pgcontents/utils/migrate.py
# def upgrade(db_url, revision):
#     """
#     Upgrade the given database to revision.
#     """
#     with temp_alembic_ini(ALEMBIC_DIR_LOCATION, db_url) as alembic_ini:
#         subprocess.check_call(
#             ['alembic', '-c', alembic_ini, 'upgrade', revision]
#         )


# Path: pgcontents/tests/utils.py
from contextlib import contextmanager
from cryptography.fernet import Fernet
from getpass import getuser
from itertools import starmap
from unicodedata import normalize
from IPython.utils import py3compat
from nose.tools import nottest
from sqlalchemy import create_engine
from tornado.web import HTTPError
from ..api_utils import api_path_join
from ..crypto import FernetEncryption
from ..schema import metadata
from ..utils.ipycompat import (
    new_code_cell,
    new_markdown_cell,
    new_notebook,
    new_raw_cell,
)
from ..utils.migrate import upgrade
import os
import posixpath

    """Normalize unicode strings"""
    return normalize('NFC', py3compat.cast_unicode(s))


@contextmanager
def assertRaisesHTTPError(testcase, status, msg=None):
    msg = msg or "Should have raised HTTPError(%i)" % status
    try:
        yield
    except HTTPError as e:
        testcase.assertEqual(e.status_code, status)
    else:
        testcase.fail(msg)


_tables = (
    'pgcontents.remote_checkpoints',
    'pgcontents.files',
    'pgcontents.directories',
    'pgcontents.users',
)
unexpected_tables = set(metadata.tables) - set(_tables)
if unexpected_tables:
    raise Exception("Unexpected tables in metadata: %s" % unexpected_tables)


@nottest
def clear_test_db():
    engine = create_engine(TEST_DB_URL)
    with engine.connect() as conn:

        for table in map(metadata.tables.__getitem__, _tables):