summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcce <devnull@localhost>2005-12-27 07:01:54 +0000
committercce <devnull@localhost>2005-12-27 07:01:54 +0000
commit5f6623a67f995758deffb9ddfdd71a7134b7c25f (patch)
tree12bd6d106ad97787a91d44f6a77b177b303cf02b
parent38546e3dc13ecee90dcd6a8537b9227561749c99 (diff)
downloadpaste-5f6623a67f995758deffb9ddfdd71a7134b7c25f.tar.gz
- wrappers are not the way to go, will be doing some changes
to httpheaders to include some of this functionality
-rw-r--r--paste/util/wrapper.py113
-rw-r--r--tests/test_util/test_util_wrapper.py32
2 files changed, 0 insertions, 145 deletions
diff --git a/paste/util/wrapper.py b/paste/util/wrapper.py
deleted file mode 100644
index e90e11a..0000000
--- a/paste/util/wrapper.py
+++ /dev/null
@@ -1,113 +0,0 @@
-# (c) 2005 Ian Bicking, Clark C. Evans and contributors
-# This module is part of the Python Paste Project and is released under
-# the MIT License: http://www.opensource.org/licenses/mit-license.php
-# Some of this code was funded by http://prometheusresearch.com
-"""
-Wrapper
-
-This module contains wrapper objects for WSGI ``environ`` and
-``response_headers`` objects.
-
-"""
-from paste import httpheaders
-from paste.response import replace_header, remove_header, header_value
-
-class EnvironWrapper(object):
- """
- Used to wrap the ``environ`` to provide handy property get/set
- methods for common HTTP headers and for other environment
- variables specified in the WSGI specification.
-
- wrapped = wrap(environ)
- wrapped.version -> environ.get('wsgi.version',None)
- wrapped.HTTP_HOST -> environ.get('HTTP_HOST',None)
- wrapped.REMOTE_USER -> environ.get('REMOTE_USER',None)
-
- """
- def __new__(cls, environ):
- assert dict == type(environ)
- assert "wsgi.version" in environ
- self = object.__new__(cls)
- self.environ = environ
- return self
-#
-# For each WSGI environment variable (and defined HTTP headers),
-# add the relevant get/set and attach the property to this class.
-#
-_proplist = [
- 'REQUEST_METHOD', 'SCRIPT_NAME', 'PATH_INFO', 'QUERY_STRING',
- 'CONTENT_TYPE', 'CONTENT_LENGTH', 'SERVER_NAME', 'SERVER_PORT',
- 'SERVER_PROTOCOL', 'HTTPS', 'SSL_PROTOCOL', 'REMOTE_USER',
- 'PATH_TRANSLATED', 'DOCUMENT_ROOT',
- # The 'wsgi.' is stripped for these
- 'wsgi.version', 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors',
- 'wsgi.multithread', 'wsgi.multiprocess', 'wsgi.run_once',
- 'wsgi.file_wrapper'
-]
-
-for name in dir(httpheaders):
- if name.startswith("HTTP_"):
- header = getattr(httpheaders,name)
- if header and 'response' != header.category:
- _proplist.append(name)
-
-for item in _proplist:
- key = item
- if "." in item:
- item = item.split(".")[1]
- def get(self,tmp=key):
- return self.environ.get(tmp,None)
- def set(self,val,tmp=key):
- dict.__setitem__(self.environ,tmp,val)
- setattr(EnvironWrapper, "GET_" + item, get)
- setattr(EnvironWrapper, "SET_" + item, set)
- setattr(EnvironWrapper, item, property(get,set))
-del _proplist
-
-class ResponseHeadersWrapper(object):
- """
- Used to wrap the ``response_headers`` to provide handy mechanism
- for dealing with the headers using properties.
-
- wrapped = wrap(response_headers)
- wrapped.HTTP_CONTENT_ENCODING = 'text/plain'
- etc.
-
- wrapped.sort()
- """
- def __new__(cls, response_headers):
- assert list == type(response_headers)
- self = object.__new__(cls)
- self.response_headers = response_headers
- return self
-
-for name in dir(httpheaders):
- if not name.startswith("HTTP_"):
- continue
- header = getattr(httpheaders,name)
- if 'request' == header.category or 'multi-entry' == header.style:
- continue
- name = name[5:]
- def get(self,tmp=str(header)):
- return header_value(self.response_headers,tmp)
- def set(self,val,tmp=str(header)):
- return replace_header(self.response_headers,tmp,val)
- setattr(ResponseHeadersWrapper, "GET_" + name, get)
- setattr(ResponseHeadersWrapper, "SET_" + name, set)
- setattr(ResponseHeadersWrapper, name, property(get,set))
-
-def wrap(obj):
- """
- Wraps a WSGI ``environ`` and ``result_headers`` with corresponding
- ``dict`` and ``list`` items that can be passed on up/down stream.
- """
- if isinstance(obj, dict):
- return EnvironWrapper(obj)
- if isinstance(obj, list):
- return ResponseHeadersWrapper(obj)
- assert False, ("The object being wrapped is neither a ``dict`` type "
- "(which corresponds to a WSGI ``environ``), nor is "
- "it a ``list`` type (which corresponds to WSGI "
- "``response_headers``.")
-
-__all__ = ['wrap','EnvironWrapper', 'ResponseHeadersWrapper']
diff --git a/tests/test_util/test_util_wrapper.py b/tests/test_util/test_util_wrapper.py
deleted file mode 100644
index 63c52fa..0000000
--- a/tests/test_util/test_util_wrapper.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# (c) 2005 Ian Bicking, Clark C. Evans and contributors
-# This module is part of the Python Paste Project and is released under
-# the MIT License: http://www.opensource.org/licenses/mit-license.php
-# Some of this code was funded by http://prometheusresearch.com
-
-from paste.util.wrapper import wrap
-
-def test_environ():
- environ = {'HTTP_VIA':'bing', 'wsgi.version': '1.0' }
- d = wrap(environ)
- assert 'bing' == d.GET_HTTP_VIA()
- d.SET_HTTP_HOST('womble')
- assert 'womble' == d.GET_HTTP_HOST()
- assert 'womble' == d.HTTP_HOST
- d.HTTP_HOST = 'different'
- assert 'different' == environ['HTTP_HOST']
- assert None == d.GET_REMOTE_USER()
- assert None == d.REMOTE_USER
- assert '1.0' == d.version
- assert None == d.multiprocess
-
-def test_response_headers():
- response_headers = []
- d = wrap(response_headers)
- assert None == d.CONTENT_TYPE
- d.CONTENT_TYPE = 'text/plain'
- assert response_headers == [('content-type','text/plain')]
- assert d.CONTENT_TYPE == 'text/plain'
- d.CONTENT_TYPE = 'text/html'
- assert response_headers == [('content-type','text/html')]
- assert d.CONTENT_TYPE == 'text/html'
- assert None == getattr(d,'SET_COOKIE',None) # multi-entity header