Mercurial > pydertron
changeset 14:16fe9c63aedb
Added HttpFileSystem
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 10 Sep 2009 14:27:28 -0700 |
parents | 6c55f09ff31d |
children | f30bd92e2216 |
files | pydertron.py test_pydertron.py |
diffstat | 2 files changed, 33 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/pydertron.py Thu Sep 10 14:07:13 2009 -0700 +++ b/pydertron.py Thu Sep 10 14:27:28 2009 -0700 @@ -1,4 +1,3 @@ -import os import sys import threading import traceback @@ -512,11 +511,35 @@ stderr.write("%s\n" % e.exc_info[1]) return retval +class HttpFileSystem(object): + def __init__(self, base_url): + self.base_url = base_url + + def find_module(self, curr_url, path): + import urlparse + + if path.startswith("."): + base_url = curr_url + else: + base_url = self.base_url + + url = "%s.js" % urlparse.urljoin(base_url, path) + if not url.startswith(self.base_url): + return None + return url + + def open(self, url): + import urllib + + return urllib.urlopen(url) + class SandboxedFileSystem(object): def __init__(self, root_dir): self.root_dir = root_dir def find_module(self, curr_script, path): + import os + if path.startswith("."): base_dir = os.path.dirname(curr_script) else:
--- a/test_pydertron.py Thu Sep 10 14:07:13 2009 -0700 +++ b/test_pydertron.py Thu Sep 10 14:27:28 2009 -0700 @@ -2,11 +2,11 @@ import sys import pydermonkey -from pydertron import JsSandbox, SandboxedFileSystem, jsexposed +from pydertron import JsSandbox, jsexposed +from pydertron import SandboxedFileSystem, HttpFileSystem -def run_test(name, libpath): - sandbox = JsSandbox(SandboxedFileSystem(libpath)) - +def run_test(name, fs): + sandbox = JsSandbox(fs) stats = {'pass': 0, 'fail': 0, 'info': 0} @jsexposed(name='print') @@ -45,8 +45,12 @@ totals = {'pass': 0, 'fail': 0} + BASE_URL = "http://interoperablejs.googlecode.com/svn/trunk/compliance/" + for libpath, name in dirs: - stats = run_test(name, libpath) + #fs = HttpFileSystem("%s%s/"% (BASE_URL, name)) + fs = SandboxedFileSystem(libpath) + stats = run_test(name, fs) totals['pass'] += stats['pass'] totals['fail'] += stats['fail']