1
2
3
4
5
6
7 try:
8 from webob import Request as BaseRequest
9 except ImportError:
10 raise ImportError('WebOb (http://pypi.python.org/pypi/WebOb) is required')
11 from StringIO import StringIO
12 from restkit.contrib.wsgi_proxy import Proxy
13 import urlparse
14 import urllib
15
16 __doc__ = '''Subclasses of webob.Request who use restkit to get a
17 webob.Response via restkit.ext.wsgi_proxy.Proxy.
18
19 Example::
20
21 >>> req = Request.blank('http://pypi.python.org/pypi/restkit')
22 >>> resp = req.get_response()
23 >>> print resp #doctest: +ELLIPSIS
24 200 OK
25 Date: ...
26 Transfer-Encoding: chunked
27 Content-Type: text/html; charset=utf-8
28 Server: Apache/2...
29 <BLANKLINE>
30 <?xml version="1.0" encoding="UTF-8"?>
31 ...
32
33
34 '''
35
36 PROXY = Proxy(allowed_methods=['GET', 'POST', 'HEAD', 'DELETE', 'PUT', 'PURGE'])
37
41 - def __get__(self, instance, klass):
42 if not instance:
43 return self
44 instance.method = self.name.upper()
45 def req(*args, **kwargs):
46 return instance.get_response(*args, **kwargs)
47 return req
48
49
51 get = Method('get')
52 post = Method('post')
53 put = Method('put')
54 head = Method('head')
55 delete = Method('delete')
71
72 __call__ = get_response
73
75 path = url_or_path.lstrip('/')
76 if '?' in path:
77 path, self.query_string = path.split('?', 1)
78 if path.startswith('http'):
79 url = path
80 else:
81 self.path_info = '/'+path
82 url = self.url
83 self.scheme, self.host, self.path_info = urlparse.urlparse(url)[0:3]
84