urlimport.py

Python script for importing modules/packages over the net.

status

sample usage

This will import BeautifulSoup, a python module for HTML/XML parsing (hope they don't mind):

>>> import urlimport
| | Url importing enabled. Add urls to sys.path.
| | This stuff is experimental, use at your own risk. Enjoy.

>>> urlimport.config(debug=2)
| |  debug=2

>>> import sys
>>> sys.path += ['http://www.crummy.com/software/BeautifulSoup/download/']
>>> import BeautifulSoup
    ...

>>> BeautifulSoup
<module 'BeautifulSoup' from 'http://www.crummy.com/software/BeautifulSoup/download/BeautifulSoup.py'>

bugs

  • /RecursionBug (fixed)

  • DOS-style files (\r\n) not working (fixed)

todo

  • /notes

  • 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

UrlImport (last edited 2007-01-10 22:31:32 by JureVrscaj)

Start a new wiki: ?
.on-wiki.net
instantly.