IPython Documentation

Table Of Contents

Previous topic

Module: html.services.contents.handlers

Next topic

Module: html.services.kernels.handlers

This Page

Note

This documentation is for a development version of IPython. There may be significant differences from the latest stable release.

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.

name is also unicode, and refers to a specfic target:

  • unicode, not url-escaped
  • must not contain ‘/’
  • It refers to an individual filename
  • It may refer to a directory name, in the case of listing or creating directories.
check_and_sign(nb, name='', path='')

Check for trusted cells, and sign the notebook.

Called as a part of saving notebooks.

Parameters:

nb : dict

The notebook object (in nbformat.current format)

name : string

The filename of the notebook (for logging)

path : string

The notebook’s directory (for logging)

copy(from_name, to_name=None, path='')

Copy an existing file and return its new model.

If to_name not specified, increment from_name-Copy#.ext.

copy_from can be a full path to a file, or just a base name. If a base name, path is used.

create_checkpoint(name, path='')

Create a checkpoint of the current state of a file

Returns a checkpoint_id for the new checkpoint.

create_file(model=None, path='', ext='.ipynb')

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

delete(name, path='')

Delete file or directory by name and path.

delete_checkpoint(checkpoint_id, name, path='')

delete a checkpoint for a file

exists(name, path='')

Does a file or directory exist at the given name and path?

Like os.path.exists

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 target exists.

file_exists(name, path='')

Does a file exist at the given name and 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_kernel_path(name, path='', model=None)

Return the path to start kernel in

get_model(name, path='', content=True)

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

increment_filename(filename, path='')

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.

list_checkpoints(name, path='')

Return a list of checkpoints for a given file

mark_trusted_cells(nb, name='', path='')

Mark cells as trusted if the notebook signature matches.

Called as a part of loading notebooks.

Parameters:

nb : dict

The notebook object (in nbformat.current format)

name : string

The filename of the notebook (for logging)

path : string

The notebook’s directory (for logging)

path_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.

restore_checkpoint(checkpoint_id, name, path='')

Restore a file from one of its checkpoints

save(model, name, path='')

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

should_list(name)

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

trust_notebook(name, path='')

Explicitly trust a notebook

Parameters:

name : string

The filename of the notebook

path : string

The notebook’s directory

update(model, name, path='')

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

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