diff options
author | Ian Bicking <ian@ianbicking.org> | 2006-08-19 23:23:41 +0000 |
---|---|---|
committer | Ian Bicking <ian@ianbicking.org> | 2006-08-19 23:23:41 +0000 |
commit | 2a46c9920999443c37fae1d1c5fa6d7a8c048acf (patch) | |
tree | 0747fe666bba763f9984db38600f8a88f58d32a7 | |
parent | dbe6ff37a8ab18ed137b758f5c450a5c96f9c4c0 (diff) | |
download | paste-git-2a46c9920999443c37fae1d1c5fa6d7a8c048acf.tar.gz |
Removed Paste Deploy dependencies in many places
-rw-r--r-- | docs/news.txt | 11 | ||||
-rw-r--r-- | paste/cascade.py | 2 | ||||
-rw-r--r-- | paste/cgiapp.py | 37 | ||||
-rw-r--r-- | paste/cgitb_catcher.py | 8 | ||||
-rw-r--r-- | paste/debug/prints.py | 8 | ||||
-rw-r--r-- | paste/errordocument.py | 9 | ||||
-rw-r--r-- | paste/exceptions/errormiddleware.py | 4 | ||||
-rwxr-xr-x | paste/httpserver.py | 2 | ||||
-rw-r--r-- | paste/urlparser.py | 49 | ||||
-rw-r--r-- | setup.py | 4 |
10 files changed, 116 insertions, 18 deletions
diff --git a/docs/news.txt b/docs/news.txt index 5842f2b..a59bf8e 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -8,6 +8,17 @@ News * Added a Paste Deploy entry point for ``paste.auth.cookie`` +* Moved Paste Deploy dependencies out of top-level modules and into + Paste-Deploy-specific entry point functions. This should make Paste + more-or-less Paste Deploy independent. ``paste.urlparser`` and + ``paste.exceptions.errormiddleware`` still have some leftover bits. + +* Added another redirector type to ``paste.recursive``, + ``environ['paste.recursive.include_app_iter']`` which gives access + to the original app_iter (useful for tranfsering unserialized data + in internal WSGI requests, as in `WSGIRemote + <http://svn.pythonpaste.org/Paste/WSGIRemote/trunk>`_ + 0.9.7 ----- diff --git a/paste/cascade.py b/paste/cascade.py index 7c07b80..341b335 100644 --- a/paste/cascade.py +++ b/paste/cascade.py @@ -6,7 +6,6 @@ Cascades through several applications, so long as applications return ``404 Not Found``. """ import httpexceptions -from paste.deploy import converters __all__ = ['Cascade'] @@ -22,6 +21,7 @@ def make_cascade(loader, global_conf, catch='404', **local_conf): ... catch = 404 500 ... """ + from paste.deploy import converters catch = map(int, converters.aslist(catch)) apps = [] for name, value in local_conf.items(): diff --git a/paste/cgiapp.py b/paste/cgiapp.py index 9843e9a..39c563d 100644 --- a/paste/cgiapp.py +++ b/paste/cgiapp.py @@ -10,12 +10,15 @@ try: import select except ImportError: select = None -from paste.deploy import converters +import warnings __all__ = ['CGIError', 'CGIApplication'] class CGIError(Exception): - pass + """ + Raised when the CGI script can't be found or doesn't + act like a proper CGI script. + """ class CGIApplication(object): @@ -26,16 +29,23 @@ class CGIApplication(object): a path, then ``$PATH`` will be used. """ - def __init__(self, global_conf, + def __init__(self, script, + global_conf=None, path=None, include_os_environ=True, query_string=None): + if global_conf is not None: + raise NotImplemented( + "global_conf is no longer supported for CGIApplication " + "(use make_cgi_application)") + if isinstance(script, dict): + # Another sign of global_conf + raise NotImplemented( + "CGIApplication no longer takes a global_conf argument " + "(use make_cgi_application or remove that argument)") self.script_filename = script if path is None: - path = (global_conf.get('path') - or global_conf.get('PATH')) - if path is None: path = os.environ.get('PATH', '').split(':') self.path = converters.aslist(path, ':') if '?' in script: @@ -243,3 +253,18 @@ def proc_communicate(proc, stdin=None, stdout=None, stderr=None): proc.wait() +def make_cgi_application(global_conf, script, path=None, include_os_environ=None, + query_string=None): + """ + This object acts as a proxy to a CGI application. You pass in the + script path (``script``), an optional path to search for the + script (if the name isn't absolute) (``path``). If you don't give + a path, then ``$PATH`` will be used. + """ + if path is None: + path = global_conf.get('path') or global_conf.get('PATH') + from paste.deploy import converters + include_os_environ = converters.asbool(include_os_environ) + return CGIApplication( + script, path=path, include_os_environ=include_os_environ, + query_string=query_string) diff --git a/paste/cgitb_catcher.py b/paste/cgitb_catcher.py index 246adba..80bde5d 100644 --- a/paste/cgitb_catcher.py +++ b/paste/cgitb_catcher.py @@ -12,7 +12,6 @@ for more. import cgitb from cStringIO import StringIO import sys -from paste.deploy import converters class NoDefault: pass @@ -25,10 +24,15 @@ class CgitbMiddleware(object): logdir=None, context=5, format="html"): + # @@: global_conf should only be present in a seperate + # function for the entry point self.app = app if display is NoDefault: display = global_conf.get('debug') - self.display = converters.asbool(display) + if isinstance(display, basestring): + from paste.deploy import converters + display = converters.asbool(display) + self.display = display self.logdir = logdir self.context = int(context) self.format = format diff --git a/paste/debug/prints.py b/paste/debug/prints.py index c624669..c971895 100644 --- a/paste/debug/prints.py +++ b/paste/debug/prints.py @@ -23,7 +23,6 @@ import cgi from paste.util import threadedprint from paste import wsgilib from paste import response -from paste.deploy.converters import asbool _threadedprint_installed = False @@ -64,9 +63,14 @@ class PrintDebugMiddleware(object): def __init__(self, app, global_conf=None, force_content_type=False, print_wsgi_errors=True): + # @@: global_conf should be handled separately and only for + # the entry point self.app = app self.force_content_type = force_content_type - self.print_wsgi_errors = asbool(print_wsgi_errors) + if isinstance(print_wsgi_errors, basestring): + from paste.deploy.converters import asbool + print_wsgi_errors = asbool(print_wsgi_errors) + self.print_wsgi_errors = print_wsgi_errors def __call__(self, environ, start_response): global _threadedprint_installed diff --git a/paste/errordocument.py b/paste/errordocument.py index ca15b00..16b091c 100644 --- a/paste/errordocument.py +++ b/paste/errordocument.py @@ -14,7 +14,6 @@ from urllib import urlencode from urlparse import urlparse from paste.wsgilib import chained_app_iters from paste.recursive import ForwardRequestException, RecursiveMiddleware -from paste.deploy import converters def forward(app, codes): """ @@ -132,7 +131,13 @@ class StatusBasedForward: def __init__(self, app, mapper, global_conf=None, **params): if global_conf is None: global_conf = {} - self.debug = converters.asbool(global_conf.get('debug')) + # @@: global_conf shouldn't really come in here, only in a + # separate make_status_based_forward function + if global_conf: + from paste.deploy import converters + self.debug = converters.asbool(global_conf.get('debug', False)) + else: + self.debug = False self.application = app self.mapper = mapper self.global_conf = global_conf diff --git a/paste/exceptions/errormiddleware.py b/paste/exceptions/errormiddleware.py index 217f935..0f9c39d 100644 --- a/paste/exceptions/errormiddleware.py +++ b/paste/exceptions/errormiddleware.py @@ -14,7 +14,6 @@ except ImportError: from paste.exceptions import formatter, collector, reporter from paste import wsgilib from paste import request -from paste.deploy import converters __all__ = ['ErrorMiddleware', 'handle_exception'] @@ -90,10 +89,13 @@ class ErrorMiddleware(object): error_message=None, xmlhttp_key=None): self.application = application + # @@: global_conf should be handled elsewhere in a separate + # function for the entry point if global_conf is None: global_conf = {} if debug is NoDefault: debug = global_conf.get('debug') + from paste.deploy import converters self.debug_mode = converters.asbool(debug) if error_email is None: error_email = (global_conf.get('error_email') diff --git a/paste/httpserver.py b/paste/httpserver.py index 4fcf35e..29c5f0f 100755 --- a/paste/httpserver.py +++ b/paste/httpserver.py @@ -20,7 +20,6 @@ if pyOpenSSL is installed, it also provides SSL capabilities. import errno, socket, sys, threading, urlparse, Queue from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from SocketServer import ThreadingMixIn -from paste.deploy import converters __all__ = ['WSGIHandlerMixin','WSGIServer','WSGIHandler', 'serve'] __version__ = "0.5" @@ -547,6 +546,7 @@ def serve(application, host=None, port=None, handler=None, ssl_pem=None, Number of worker threads to create when ``use_threadpool`` is true. This can be a string or an integer value. """ + from paste.deploy import converters ssl_context = None if ssl_pem: assert SSL, "pyOpenSSL is not installed" diff --git a/paste/urlparser.py b/paste/urlparser.py index a404d31..a3ee7c0 100644 --- a/paste/urlparser.py +++ b/paste/urlparser.py @@ -13,7 +13,6 @@ import mimetypes import request import fileapp from paste.util import import_string -from paste.deploy import converters import httpexceptions from httpheaders import ETAG @@ -94,10 +93,21 @@ class URLParser(object): represents, thus any Python modules in this directory will be given names under this package. """ + if global_conf: + import warnings + warnings.warn( + 'The global_conf argument to URLParser is deprecated; ' + 'either pass in None or {}, or use make_url_parser', + DeprecationWarning) + else: + global_conf = {} if os.path.sep != '/': directory = directory.replace(os.path.sep, '/') self.directory = directory self.base_python_name = base_python_name + # This logic here should be deprecated since it is in + # make_url_parser + from paste.deploy import converters if index_names is NoDefault: index_names = global_conf.get( 'index_names', ('index', 'Index', 'main', 'Main')) @@ -573,3 +583,40 @@ def make_pkg_resources(global_conf, egg, resource_name=''): which is the path in the egg that this starts at. """ return PkgResourcesParser(egg, resource_name) + +def make_url_parser(global_conf, directory, base_python_name, + index_names=None, hide_extensions=None, + ignore_extensions=None, + **constructor_conf): + """ + Create a URLParser application that looks in ``directory``, which + should be the directory for the Python package named in + ``base_python_name``. ``index_names`` are used when viewing the + directory (like ``'index'`` for ``'index.html'``). + ``hide_extensions`` are extensions that are not viewable (like + ``'.pyc'``) and ``ignore_extensions`` are viewable but only if an + explicit extension is given. + """ + from paste.deploy import converters + if index_names is None: + index_names = global_conf.get( + 'index_names', ('index', 'Index', 'main', 'Main')) + index_names = converters.aslist(index_names) + + if hide_extensions is None: + hide_extensions = global_conf.get( + 'hide_extensions', ('.pyc', 'bak', 'py~')) + hide_extensions = converters.aslist(hide_extensions) + + if ignore_extensions is None: + ignore_extensions = global_conf.get( + 'ignore_extensions', ()) + ignore_extensions = converters.aslist(ignore_extensions) + # There's no real way to set constructors currently... + + return URLParser({}, directory, base_python_name, + index_names=index_names, + hide_extensions=hide_extensions, + ignore_extensions=ignore_extensions, + **constructor_conf) + @@ -138,10 +138,10 @@ For the latest changes see the `news file }, entry_points=""" [paste.app_factory] - cgi = paste.cgiapp:CGIApplication [subprocess] - pycgi = paste.pycgiwrapper:CGIWrapper + cgi = paste.cgiapp:make_cgi_application [subprocess] static = paste.urlparser:make_static pkg_resources = paste.urlparser:make_pkg_resources + urlparser = paste.urlparser:make_url_parser selenium_index = paste.debug.recorder.selenium_suite:make_selenium_index_app proxy = paste.proxy:make_proxy test = paste.debug.debugapp:make_test_app |