urlimport.py
Python script for importing modules/packages over the net.
download: urlimport.py
status
insecure, and definitely not suitable for production use (discussion on reddit)
- supports http, ftp and https (+client certificates [experimental])
- needs testing
- modules/packages successfully imported:
- twisted
IPython (I had to first create a ./IPython/UserConfig folder on the local machine)
- ...
- modules/packages successfully imported:
extensions
http://bzr.danigm.net/urlimport/changes - implements RSA signing and more (by Daniel Garcia-Moreno)
sample usage
This will import BeautifulSoup, a python module for HTML/XML parsing (hope they don't mind):
1 >>> import urlimport
2 | | Url importing enabled. Add urls to sys.path.
3 | | This stuff is experimental, use at your own risk. Enjoy.
4
5 >>> urlimport.config(debug=2)
6 | | debug=2
7
8 >>> import sys
9 >>> sys.path += ['http://www.crummy.com/software/BeautifulSoup/download/']
10 >>> import BeautifulSoup
11 ...
12
13 >>> BeautifulSoup
14 <module 'BeautifulSoup' from 'http://www.crummy.com/software/BeautifulSoup/download/BeautifulSoup.py'>
bugs
/RecursionBug (fixed)
DOS-style files (\r\n) not working (fixed)
todo
functionality:
ftp support
- security
https
ssl client certificate support
- module signatures
- use python2.5's hashlib
- sftp
- cheeseshop import?
- urlimport + zipimport
- source caching
- pyc import
implementation:
verbosity should be handled by debug(), not explicitly
(0.42b)
about
The reason why this works is covered here: PEP 302.
Basically, python supports what is called a path hook, which enables you to hook a specific path item to an import handler of your choice (an url importer in this case). The PEP mentioned also gives details on the importer protocol, a protocol which all importers must comply to (by defining find_module() and load_module(), among other details).
This task being even possible, not to mention the unexpected (even for python) simplicity, is for me another proof that python is _the one_ language (it rocks)
-- jv