Skip to content

Commit

Permalink
docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
hadim committed Sep 1, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 58b3985 commit 4d311d9
Showing 2 changed files with 27 additions and 8 deletions.
22 changes: 20 additions & 2 deletions jupyter_server/files/handlers.py
Original file line number Diff line number Diff line change
@@ -100,6 +100,10 @@ async def get(self, path, include_body=True):


class ArchiveStream:
"""ArchiveStream is an abstraction layer to a Python archive allowing
to stream archive files.
"""

def __init__(self, handler):
self.handler = handler
self.position = 0
@@ -120,6 +124,9 @@ def flush(self):


def make_writer(handler, archive_format="zip"):
"""Given an handler object, create an `ArchiveStream` instance
and setup an archive file object using the specified archive format.
"""
fileobj = ArchiveStream(handler)

if archive_format == "zip":
@@ -139,6 +146,9 @@ def make_writer(handler, archive_format="zip"):


def make_reader(archive_path):
"""Return the appropriate archive file instance given
the extension's path of `archive_path`.
"""

archive_format = "".join(archive_path.suffixes)[1:]

@@ -156,6 +166,11 @@ def make_reader(archive_path):


class DirectoryHandler(JupyterHandler):
"""Download a directory. Since a folder can't be directly downloaded,
it is first archived with or without compression before being downloaded from the client.
The archive format (zip, tar.gz, etc) can be configured within the request.
"""

@web.authenticated
async def get(self, archive_path, include_body=False):

@@ -192,8 +207,6 @@ async def get(self, archive_path, include_body=False):
)
self.flush_cb.start()

# self.archive_and_download(archive_path, archive_format, archive_token)

args = (archive_path, archive_format, archive_token)
await ioloop.IOLoop.current().run_in_executor(
None, self.archive_and_download, *args
@@ -229,6 +242,11 @@ def on_connection_close(self):


class ExtractDirectoryHandler(JupyterHandler):
"""Extract the content of an archive on the server side. Given an archive on
the server side, this class allows to request extracting the content of the archive.
The archive format is detected from the extension of the archive.
"""

@web.authenticated
async def get(self, archive_path, include_body=False):

13 changes: 7 additions & 6 deletions jupyter_server/services/contents/manager.py
Original file line number Diff line number Diff line change
@@ -178,11 +178,12 @@ def _default_checkpoints_kwargs(self):
klass=RequestHandler,
allow_none=True,
config=True,
help="""handler class to use when serving raw directory requests.
help="""Handler class to use when serving raw directory requests.
TODO: complete
This handler allows to archive a folder on the server side before
downloading it from the client.
Access to these files should be Authenticated.
Access to these directories should be Authenticated.
""",
)

@@ -197,11 +198,11 @@ def _default_checkpoints_kwargs(self):
klass=RequestHandler,
allow_none=True,
config=True,
help="""handler class to use when serving raw directory requests.
help=""""Handler class to use when serving raw directory requests.
TODO: complete
This handler allows to extract the content of a folder on the server side.
Access to these files should be Authenticated.
Access to these directories should be Authenticated.
""",
)

0 comments on commit 4d311d9

Please sign in to comment.