Allow %loadpy to load remote URLs that don't end in .py #1161

Merged
merged 5 commits into from Dec 16, 2011

Projects

None yet

2 participants

@fperez
IPython member

Will also fix same encoding bug we found for notebooks next.

@takluyver takluyver commented on an outdated diff Dec 15, 2011
IPython/core/magic.py
@@ -2151,7 +2151,11 @@ def magic_loadpy(self, arg_s):
%loadpy http://www.example.com/myscript.py
"""
arg_s = unquote_filename(arg_s)
- if not arg_s.endswith('.py'):
+ if not arg_s.startswith(('http://', 'https://')) \
+ and not arg_s.endswith('.py'):
+ # Local files must be .py; for remote URLs it's possible that the
+ # fetch URL doesn't have a .py in it (many servers have an opaque
+ # URL, such as scipy-central.org).
raise ValueError('%%load only works with .py files: %s' % arg_s)
if arg_s.startswith('http'):
@takluyver
takluyver Dec 15, 2011

Don't forget to change this one as well (same issue with local files like 'httpx.py')

@fperez
IPython member

Reviewed by @takluyver and @minrk on IRC in addition to what's here, merging now.

@fperez fperez closed this Dec 16, 2011
@fperez fperez merged commit 3deb45e into master Dec 16, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment