Warning

This documentation is for an old version of IPython. You can find docs for newer versions here.

Module: html.services.contents.manager

A base class for contents managers.

1 Class

class IPython.html.services.contents.manager.ContentsManager(**kwargs)

Bases: IPython.config.configurable.LoggingConfigurable

Base class for serving files and directories.

This serves any text or binary file, as well as directories, with special handling for JSON notebook documents.

Most APIs take a path argument, which is always an API-style unicode path, and always refers to a directory.

  • unicode, not url-escaped
  • ‘/’-separated
  • leading and trailing ‘/’ will be stripped
  • if unspecified, path defaults to ‘’, indicating the root path.
check_and_sign(nb, path='')

Check for trusted cells, and sign the notebook.

Called as a part of saving notebooks.

Parameters:

nb : dict

The notebook dict

path : string

The notebook’s path (for logging)

copy(from_path, to_path=None)

Copy an existing file and return its new model.

If to_path not specified, it will be the parent directory of from_path. If to_path is a directory, filename will increment from_path-Copy#.ext.

from_path must be a full path to a file.

create_checkpoint(path)

Create a checkpoint.

delete(path)

Delete a file/directory and any associated checkpoints.

delete_file(path)

Delete file or directory by path.

dir_exists(path)

Does the API-style path (directory) actually exist?

Like os.path.isdir

Override this method in subclasses.

Parameters:

path : string

The path to check

Returns:

exists : bool

Whether the path does indeed exist.

exists(path)

Does a file or directory exist at the given path?

Like os.path.exists

Parameters:

path : string

The relative path to the file’s directory (with ‘/’ as separator)

Returns:

exists : bool

Whether the target exists.

file_exists(path='')

Does a file exist at the given path?

Like os.path.isfile

Override this method in subclasses.

Parameters:

name : string

The name of the file you are checking.

path : string

The relative path to the file’s directory (with ‘/’ as separator)

Returns:

exists : bool

Whether the file exists.

get(path, content=True, type=None, format=None)

Get the model of a file or directory with or without content.

get_kernel_path(path, model=None)

Return the API path for the kernel

KernelManagers can turn this value into a filesystem path, or ignore it altogether.

The default value here will start kernels in the directory of the notebook server. FileContentsManager overrides this to use the directory containing the notebook.

increment_filename(filename, path='', insert='')

Increment a filename until it is unique.

Parameters:

filename : unicode

The name of a file, including extension

path : unicode

The API path of the target’s directory

Returns:

name : unicode

A filename that is unique, based on the input filename.

is_hidden(path)

Does the API style path correspond to a hidden directory or file?

Parameters:

path : string

The path to check. This is an API path (/ separated, relative to root dir).

Returns:

hidden : bool

Whether the path is hidden.

mark_trusted_cells(nb, path='')

Mark cells as trusted if the notebook signature matches.

Called as a part of loading notebooks.

Parameters:

nb : dict

The notebook object (in current nbformat)

path : string

The notebook’s path (for logging)

new(model=None, path='')

Create a new file or directory and return its model with no content.

To create a new untitled entity in a directory, use new_untitled.

new_untitled(path='', type='', ext='')

Create a new untitled file or directory in path

path must be a directory

File extension can be specified.

Use new to create files with a fully specified path (including filename).

rename(old_path, new_path)

Rename a file and any checkpoints associated with that file.

rename_file(old_path, new_path)

Rename a file.

restore_checkpoint(checkpoint_id, path)

Restore a checkpoint.

run_pre_save_hook(model, path, **kwargs)

Run the pre-save hook if defined, and log errors

save(model, path)

Save the file or directory and return the model with no content.

Save implementations should call self.run_pre_save_hook(model=model, path=path) prior to writing any data.

should_list(name)

Should this file/directory name be displayed in a listing?

trust_notebook(path)

Explicitly trust a notebook

Parameters:

path : string

The path of a notebook

update(model, path)

Update the file’s path

For use in PATCH requests, to enable renaming a file without re-uploading its contents. Only used for renaming at the moment.

validate_notebook_model(model)

Add failed-validation message to model