Skip to content

Commit

Permalink
adding google drive rewrite provider for jupyter#427
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Jul 29, 2015
1 parent 404771b commit 4680ad1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nbviewer/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
for prov in ['url', 'github', 'gist']]

default_rewrites = ['nbviewer.providers.{}'.format(prov)
for prov in ['gist', 'github', 'dropbox', 'url']]
for prov in ['gist', 'github', 'dropbox', 'googledrive',
'url']]


def provider_handlers(providers=None):
Expand Down
1 change: 1 addition & 0 deletions nbviewer/providers/googledrive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .handlers import uri_rewrites
14 changes: 14 additions & 0 deletions nbviewer/providers/googledrive/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#-----------------------------------------------------------------------------
# Copyright (C) 2015 The Jupyter Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

def uri_rewrites(rewrites=[]):
return rewrites + [
(r'^http(s?)://drive\.google\.com/file/d/([^/]*).*$',
u'/url{0}/googledrive.com/host/{1}'),
(r'^http(s?)://drive\.google\.com/open\?id=([^&#]*).*$',
u'/url{0}/googledrive.com/host/{1}')
]
5 changes: 5 additions & 0 deletions nbviewer/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def test_transform_ipynb_uri():
u'/urls/dl.dropbox.com/s/zip/baz.qux'),
( u'https://www.dropbox.com/sh/mhviow274da2wly/CZKwRRcA0k/nested/furthernested/User%2520Interface.ipynb?dl=1',
u'/urls/dl.dropbox.com/sh/mhviow274da2wly/CZKwRRcA0k/nested/furthernested/User%2520Interface.ipynb'),
# Google Drive URLS
(u'http://drive.google.com/file/d/0B7d519FxJIqPYktaTVg1TTV1WDA/view?usp=sharing',
'/url/googledrive.com/host/0B7d519FxJIqPYktaTVg1TTV1WDA'),
(u'https://drive.google.com/open?id=0B7d519FxJIqPcEVOZXYzdGxBdzQ',
u'/url/googledrive.com/host/0B7d519FxJIqPYktaTVg1TTV1WDA'),
# URL
('https://example.org/ipynb',
u'/urls/example.org/ipynb'),
Expand Down

0 comments on commit 4680ad1

Please sign in to comment.