Permalink
Browse files

Revert "Merging newproxy branch."

This reverts commit d466db7, reversing
changes made to 5773468.
  • Loading branch information...
admc committed Mar 31, 2010
1 parent b981834 commit 23e99cdc208f614db07170b68791788c61d54e31
View
@@ -31,7 +31,7 @@
Thanks for your interest and participation!
"""
-dependencies = ['webenv >= 0.6.1', 'httplib2']
+dependencies = []
two_four_dependencies = ['ctypes']
@@ -4,13 +4,13 @@
# hit a forward
from windmill.bin import admin_lib
-from windmill import server, authoring
+import windmill
import os, sys
-from webenv.applications.file_server import FileServerApplication
+from windmill.dep import wsgi_fileserver
def setup_module(module):
- authoring.setup_module(module)
- application = FileServerApplication(os.path.dirname(__file__))
- server.add_namespace('windmill-unittests', application)
+ windmill.authoring.setup_module(module)
+ application = wsgi_fileserver.WSGIFileServerApplication(root_path=os.path.dirname(__file__), mount_point='/windmill-unittests/')
+ windmill.server.wsgi.add_namespace('windmill-unittests', application)
from windmill.authoring import teardown_module
@@ -11,7 +11,7 @@
<fieldset>
<p>Submit a POST search to Drupal.org</p>
<p><input type="text" name="search_theme_form"></p>
-<p><input type="submit" value="Search" name="op"></p>
+<p><input type="submit" value="Submit" name="op"></p>
<input type="hidden" value="search_theme_form" id="edit-search-theme-form" name="form_id"/>
</fieldset>
</form>
@@ -1,8 +1,9 @@
# Generated by the windmill services transformer
from windmill.authoring import WindmillTestClient
-from time import sleep
+
def test_foreign_open():
client = WindmillTestClient(__name__)
+
client.open(url=u'http://www.asdf.com')
client.waits.forPageLoad(timeout=u'2000')
client.asserts.assertJS(js=u"windmill.testWin().document.title == 'asdf'")
@@ -14,17 +14,16 @@
from windmill.bin import admin_lib
import windmill
-from windmill import authoring, server
import os, sys
from windmill.dep import functest
from time import sleep
-from webenv.applications.file_server import FileServerApplication
+from windmill.dep import wsgi_fileserver
def setup_module(module):
- authoring.setup_module(module)
+ windmill.authoring.setup_module(module)
- application = FileServerApplication(os.path.dirname(__file__))
- server.add_namespace('windmill-unittests', application)
+ application = wsgi_fileserver.WSGIFileServerApplication(root_path=os.path.abspath(os.path.dirname(__file__)), mount_point='/windmill-unittests/')
+ windmill.server.wsgi.add_namespace('windmill-unittests', application)
from windmill.authoring import teardown_module
View
@@ -14,8 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
-
+import bin, browser, server, conf, tools, sys
if not sys.version.startswith('2.4'):
from urlparse import urlparse
else:
@@ -49,6 +48,3 @@ def get_test_url(url):
else:
test_url = url.geturl().replace(url.netloc, url.netloc+'/windmill-serv/start.html')
return test_url
-
-# Backwards compat, I hate this import!
-from windmill import authoring, server
@@ -21,7 +21,6 @@
from windmill.dep import json
import os, sys, re
from time import sleep
-from windmill import tools
logger = logging.getLogger(__name__)
@@ -140,7 +139,7 @@ def __init__(self, suite_name, assertions=None, browser_debugging=None, method_p
"""Assign all available attributes to instance so they are easily introspected"""
if method_proxy is None:
- method_proxy = tools.make_jsonrpc_client()
+ method_proxy = windmill.tools.make_jsonrpc_client()
self._method_proxy = method_proxy
@@ -17,15 +17,14 @@
import os
import sys
import windmill
-from windmill import server, tools
from windmill.dep import json
import tempfile
if not sys.version.startswith('2.4'):
from urlparse import urlparse
else:
# python 2.4
- from tools.urlparse_25 import urlparse
+ from windmill.tools.urlparse_25 import urlparse
def get_save_url(suite_name, extension):
@@ -35,9 +34,11 @@ def get_save_url(suite_name, extension):
def create_saves_path():
directory = tempfile.mkdtemp(suffix='.windmill-saves')
# Mount the fileserver application for tests
- from webenv.applications.file_server import FileServerApplication
- application = FileServerApplication(os.path.dirname(__file__))
- server.add_namespace('windmill-unittests', application)
+ from windmill.dep import wsgi_fileserver
+ WSGIFileServerApplication = wsgi_fileserver.WSGIFileServerApplication
+ application = WSGIFileServerApplication(root_path=os.path.abspath(directory), mount_point='/windmill-saves/')
+ from windmill.server import wsgi
+ wsgi.add_namespace('windmill-saves', application)
windmill.settings['SAVES_PATH'] = directory
windmill.teardown_directories.append(directory)
@@ -15,7 +15,6 @@
# limitations under the License.
import windmill
-from windmill import conf, server
import logging
from time import sleep
import os, sys
@@ -87,7 +86,7 @@ def setup_servers(console_level=logging.INFO):
if len(logging.getLogger().handlers) > 0:
console_handler = logging.getLogger().handlers[0]
console_handler.setLevel(console_level)
- httpd = server.make_server()
+ httpd = windmill.server.wsgi.make_windmill_server()
return httpd
def run_threaded(console_level=logging.INFO):
@@ -122,7 +121,7 @@ def configure_global_settings(logging_on=True):
else:
local_settings = None
- windmill.settings = conf.configure_settings(localSettings=local_settings)
+ windmill.settings = windmill.conf.configure_settings(localSettings=local_settings)
if 'controllers' not in windmill.settings:
windmill.settings['controllers'] = []
@@ -24,10 +24,8 @@
logger = logging.getLogger(__name__)
-from windmill import tools, browser, server
-
-jsonrpc_client = tools.make_jsonrpc_client()
-xmlrpc_client = tools.make_xmlrpc_client()
+jsonrpc_client = windmill.tools.make_jsonrpc_client()
+xmlrpc_client = windmill.tools.make_xmlrpc_client()
from StringIO import StringIO
test_stream_object = StringIO()
@@ -43,7 +41,7 @@ def clear_queue():
def start_firefox():
"""Start the Firefox web browser configured for windmill"""
- controller = browser.get_firefox_controller()
+ controller = windmill.browser.get_firefox_controller()
controller.start()
#print 'Started '+str(controller.command)
logger.info(str(controller.command))
@@ -52,21 +50,21 @@ def start_firefox():
def start_ie():
"""Start the Internet Explorer web browser configured for windmill"""
- controller = browser.get_ie_controller()
+ controller = windmill.browser.get_ie_controller()
controller.start()
windmill.settings['controllers'].append(controller)
return controller
def start_safari():
"""Start the Safari web browser configured for windmill"""
- controller = browser.get_safari_controller()
+ controller = windmill.browser.get_safari_controller()
controller.start()
windmill.settings['controllers'].append(controller)
return controller
def start_chrome():
"""Start the Crhome web browser configured for windmill"""
- controller = browser.get_chrome_controller()
+ controller = windmill.browser.get_chrome_controller()
controller.start()
windmill.settings['controllers'].append(controller)
return controller
@@ -146,9 +144,11 @@ def run_js_tests(js_dir, test_filter=None, phase=None):
import windmill
windmill.js_framework_active = True
js_dir = os.path.abspath(os.path.expanduser(js_dir))
- from webenv.applications.file_server import FileServerApplication
- application = FileServerApplication(os.path.abspath(js_dir))
- server.add_namespace('windmill-jstests', application)
+ from windmill.dep import wsgi_fileserver
+ WSGIFileServerApplication = wsgi_fileserver.WSGIFileServerApplication
+ application = WSGIFileServerApplication(root_path=os.path.abspath(js_dir), mount_point='/windmill-jstest/')
+ from windmill.server import wsgi
+ wsgi.add_namespace('windmill-jstest', application)
# Build list of files and send to IDE
base_url = windmill.settings['TEST_URL']+'/windmill-jstest'
@@ -172,9 +172,11 @@ def parse_files(x, directory, files):
def load_extensions_dir(dirname):
"""Mount the directory and send all javascript file links to the IDE in order to execute those test urls under the jsUnit framework"""
# Mount the fileserver application for tests
- from webenv.applications.file_server import FileServerApplication
- application = FileServerApplication(os.path.abspath(dirname))
- server.add_namespace('windmill-extensions', application)
+ from windmill.dep import wsgi_fileserver
+ WSGIFileServerApplication = wsgi_fileserver.WSGIFileServerApplication
+ application = WSGIFileServerApplication(root_path=os.path.abspath(dirname), mount_point='/windmill-extentions/')
+ from windmill.server import wsgi
+ wsgi.add_namespace('windmill-extentions', application)
# Build list of files and send to IDE
base_url = windmill.settings['TEST_URL']+'/windmill-extentions'
View
@@ -13,6 +13,9 @@
import _simplesettings as simplesettings
import _mozrunner as mozrunner
+import _wsgi_fileserver as wsgi_fileserver
+import _wsgi_jsonrpc as wsgi_jsonrpc
+import _wsgi_xmlrpc as wsgi_xmlrpc
import _functest as functest
import sys
@@ -0,0 +1,147 @@
+# Copyright (c) 2006-2007 Open Source Applications Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from urlparse import urlparse
+import os, sys
+import logging
+import urllib
+
+logger = logging.getLogger(__name__)
+
+# Content type sources taken from http://en.wikipedia.org/wiki/MIME_type
+content_type_table = {'js': 'application/x-javascript', 'html': 'text/html; charset=utf-8',
+ 'fallback':'text/plain; charset=utf-8', 'ogg': 'application/ogg',
+ 'xhtml':'text/html; charset=utf-8', 'rm':'audio/vnd.rn-realaudio',
+ 'swf':'application/x-shockwave-flash', 'mp3': 'audio/mpeg', 'wma':'audio/x-ms-wma',
+ 'ra':'audio/vnd.rn-realaudio', 'wav':'audio/x-wav', 'gif':'image/gif', 'jpeg':'image/jpeg',
+ 'jpg':'image/jpeg', 'png':'image/png', 'tiff':'image/tiff', 'css':'text/css; charset=utf-8',
+ 'mpeg':'video/mpeg', 'mp4':'video/mp4', 'qt':'video/quicktime', 'mov':'video/quicktime',
+ 'wmv':'video/x-ms-wmv', 'atom':'application/atom+xml; charset=utf-8',
+ 'xslt':'application/xslt+xml', 'svg':'image/svg+xml', 'mathml':'application/mathml+xml',
+ 'rss':'application/rss+xml; charset=utf-8',
+ 'ics':'text/calendar; charset=utf-8 '}
+
+def reconstruct_url(environ):
+ # From WSGI spec, PEP 333
+ from urllib import quote
+ url = environ['wsgi.url_scheme']+'://'
+ if environ.get('HTTP_HOST'): url += environ['HTTP_HOST']
+ else:
+ url += environ['SERVER_NAME']
+ if environ['wsgi.url_scheme'] == 'https':
+ if environ['SERVER_PORT'] != '443':
+ url += ':' + environ['SERVER_PORT']
+ else:
+ if environ['SERVER_PORT'] != '80':
+ url += ':' + environ['SERVER_PORT']
+ url += quote(environ.get('SCRIPT_NAME',''))
+ url += quote(environ.get('PATH_INFO','')).replace(url.replace(':', '%3A'), '')
+ if environ.get('QUERY_STRING'):
+ url += '?' + environ['QUERY_STRING']
+ environ['reconstructed_url'] = url
+ return url
+
+class FileResponse(object):
+ readsize = 1024
+ def __init__(self, f, filename):
+ self.size = os.path.getsize(filename)
+ self.f = f
+ def __iter__(self):
+ output = '\n'
+ while len(output) is not 0:
+ output = self.f.read(self.readsize)
+ yield output
+
+class WSGIFileServerApplication(object):
+ """Application to serve out windmill provided"""
+
+ def __init__(self, root_path, mount_point=None):
+ self.path = os.path.abspath(os.path.expanduser(root_path))
+ self.mount_point = mount_point
+
+ def handler(self, environ, start_response):
+ """Application to serve out windmill provided"""
+ url = urlparse(reconstruct_url(environ))
+
+ if self.mount_point is not None:
+ #split_url = url.path.split(self.mount_point, 1)
+ split_url = url[2].split(self.mount_point, 1)
+ serve_file = split_url[1]
+ else:
+ #serve_file = url.path
+ serve_file = url[2]
+
+ serve_file = urllib.unquote(serve_file).replace('/', os.path.sep)
+
+ def do_get():
+ if serve_file.endswith('/') or os.path.isdir(os.path.join(self.path, serve_file)):
+ if os.path.isdir(os.path.join(self.path, serve_file)):
+ start_response('200 OK', [('Cache-Control','no-cache'), ('Pragma','no-cache'),
+ ('Content-Type', 'text/html; charset=utf-8')])
+ return [ '<html>' +
+ '<br>'.join( ['<a href="%s/%s">%s</a>' % (serve_file.replace(filename, ''), filename, filename)
+ for filename in os.listdir(os.path.join(self.path, serve_file))])
+ + '</html>' ]
+ else:
+ logger.error('failed to list directory %s/%s' % (self.path, serve_file))
+ start_response('404 Not found', [('Content-Type', 'text/plain')])
+ return ['404 Not Found']
+
+ try:
+ if os.name == 'nt' or sys.platform == 'cygwin':
+ f = open(os.path.join(self.path, serve_file), 'rb')
+ else:
+ f = open(os.path.join(self.path, serve_file), 'r')
+ logger.debug('opened file %s' % serve_file)
+ except IOError:
+ logger.error('failed to open file %s/%s' % (self.path, serve_file))
+ start_response('404 Not found', [('Content-Type', 'text/plain')])
+ return ['404 Not Found']
+
+ response = FileResponse(f, os.path.join(self.path, serve_file))
+ start_response('200 OK', [('Cache-Control','no-cache'), ('Pragma','no-cache'),
+ ('Content-Length', str(response.size),),
+ ('Content-Type', self.guess_content_type(environ['PATH_INFO']))])
+ return response
+
+ def do_put():
+ #Write file
+ try:
+ f = open(os.path.join(self.path, serve_file), 'w')
+ logger.debug('opened file for writing %s' % serve_file)
+ except:
+ logger.error('failed to open file for writiing %s/%s' % (self.path, serve_file))
+ start_response('403 Forbidden', [('Content-Type', 'text/plain')])
+ return ['403 Forbidden']
+
+ f.write(environ['wsgi.input'].read())
+
+ def do_mkcollection():
+ pass
+
+ http_method_map = {'GET':do_get, 'PUT':do_put, 'MKCOLLECTION':do_mkcollection}
+ return http_method_map[environ['REQUEST_METHOD']]()
+
+
+ def guess_content_type(self, path_info):
+ """Make a best guess at the content type"""
+ extention_split = path_info.split('.')
+
+ if content_type_table.has_key(extention_split[-1]):
+ return content_type_table[extention_split[-1]]
+ else:
+ return content_type_table['fallback']
+
+ def __call__(self, environ, start_response):
+ return self.handler(environ, start_response)
Oops, something went wrong.

0 comments on commit 23e99cd

Please sign in to comment.