# Path: restkit/contrib/wsgi_proxy.py
# class Proxy(object):
#     """A proxy wich redirect the request to SERVER_NAME:SERVER_PORT
#     and send HTTP_HOST header"""
# 
#     def __init__(self, manager=None, allowed_methods=ALLOWED_METHODS,
#             strip_script_name=True,  **kwargs):
#         self.allowed_methods = allowed_methods
#         self.strip_script_name = strip_script_name
#         self.client = Client(**kwargs)
# 
#     def extract_uri(self, environ):
#         port = None
#         scheme = environ['wsgi.url_scheme']
#         if 'SERVER_NAME' in environ:
#             host = environ['SERVER_NAME']
#         else:
#             host = environ['HTTP_HOST']
#         if ':' in host:
#             host, port = host.split(':')
# 
#         if not port:
#             if 'SERVER_PORT' in environ:
#                 port = environ['SERVER_PORT']
#             else:
#                 port = scheme == 'https' and '443' or '80'
# 
#         uri = '%s://%s:%s' % (scheme, host, port)
#         return uri
# 
#     def __call__(self, environ, start_response):
#         method = environ['REQUEST_METHOD']
#         if method not in self.allowed_methods:
#             start_response('403 Forbidden', ())
#             return ['']
# 
#         if self.strip_script_name:
#             path_info = ''
#         else:
#             path_info = environ['SCRIPT_NAME']
#         path_info += environ['PATH_INFO']
# 
#         query_string = environ['QUERY_STRING']
#         if query_string:
#             path_info += '?' + query_string
# 
#         host_uri = self.extract_uri(environ)
#         uri = host_uri + path_info
# 
#         new_headers = {}
#         for k, v in environ.items():
#             if k.startswith('HTTP_'):
#                 k = k[5:].replace('_', '-').title()
#                 new_headers[k] = v
# 
# 
#         ctype = environ.get("CONTENT_TYPE")
#         if ctype and ctype is not None:
#             new_headers['Content-Type'] = ctype
# 
#         clen = environ.get('CONTENT_LENGTH')
#         te =  environ.get('transfer-encoding', '').lower()
#         if not clen and te != 'chunked':
#             new_headers['transfer-encoding'] = 'chunked'
#         elif clen:
#             new_headers['Content-Length'] = clen
# 
#         if new_headers.get('Content-Length', '0') == '-1':
#             raise ValueError(WEBOB_ERROR)
# 
#         response = self.client.request(uri, method, body=environ['wsgi.input'],
#                 headers=new_headers)
# 
#         if 'location' in response:
#             if self.strip_script_name:
#                 prefix_path = environ['SCRIPT_NAME']
# 
#             new_location = rewrite_location(host_uri, response.location,
#                     prefix_path=prefix_path)
# 
#             headers = []
#             for k, v in response.headerslist:
#                 if k.lower() == 'location':
#                     v = new_location
#                 headers.append((k, v))
#         else:
#             headers = response.headerslist
# 
#         start_response(response.status, headers)
# 
#         if method == "HEAD":
#             return StringIO()
# 
#         return response.tee()


import base64
import urlparse
import urllib
from StringIO import StringIO
    from webob import Request as BaseRequest
from .wsgi_proxy import Proxy
#!/usr/bin/env python
# -*- coding: utf-8 -
#
# This file is part of restkit released under the MIT license. 
# See the NOTICE for more information.


try:
except ImportError:
    raise ImportError('WebOb (http://pypi.python.org/pypi/WebOb) is required')


__doc__ = '''Subclasses of webob.Request who use restkit to get a
webob.Response via restkit.ext.wsgi_proxy.Proxy.

Example::


# Path: restkit/contrib/wsgi_proxy.py
# class Proxy(object):
#     """A proxy wich redirect the request to SERVER_NAME:SERVER_PORT
#     and send HTTP_HOST header"""
# 
#     def __init__(self, manager=None, allowed_methods=ALLOWED_METHODS,
#             strip_script_name=True,  **kwargs):
#         self.allowed_methods = allowed_methods
#         self.strip_script_name = strip_script_name
#         self.client = Client(**kwargs)
# 
#     def extract_uri(self, environ):
#         port = None
#         scheme = environ['wsgi.url_scheme']
#         if 'SERVER_NAME' in environ:
#             host = environ['SERVER_NAME']
#         else:
#             host = environ['HTTP_HOST']
#         if ':' in host:
#             host, port = host.split(':')
# 
#         if not port:
#             if 'SERVER_PORT' in environ:
#                 port = environ['SERVER_PORT']
#             else:
#                 port = scheme == 'https' and '443' or '80'
# 
#         uri = '%s://%s:%s' % (scheme, host, port)
#         return uri
# 
#     def __call__(self, environ, start_response):
#         method = environ['REQUEST_METHOD']
#         if method not in self.allowed_methods:
#             start_response('403 Forbidden', ())
#             return ['']
# 
#         if self.strip_script_name:
#             path_info = ''
#         else:
#             path_info = environ['SCRIPT_NAME']
#         path_info += environ['PATH_INFO']
# 
#         query_string = environ['QUERY_STRING']
#         if query_string:
#             path_info += '?' + query_string
# 
#         host_uri = self.extract_uri(environ)
#         uri = host_uri + path_info
# 
#         new_headers = {}
#         for k, v in environ.items():
#             if k.startswith('HTTP_'):
#                 k = k[5:].replace('_', '-').title()
#                 new_headers[k] = v
# 
# 
#         ctype = environ.get("CONTENT_TYPE")
#         if ctype and ctype is not None:
#             new_headers['Content-Type'] = ctype
# 
#         clen = environ.get('CONTENT_LENGTH')
#         te =  environ.get('transfer-encoding', '').lower()
#         if not clen and te != 'chunked':
#             new_headers['transfer-encoding'] = 'chunked'
#         elif clen:
#             new_headers['Content-Length'] = clen
# 
#         if new_headers.get('Content-Length', '0') == '-1':
#             raise ValueError(WEBOB_ERROR)
# 
#         response = self.client.request(uri, method, body=environ['wsgi.input'],
#                 headers=new_headers)
# 
#         if 'location' in response:
#             if self.strip_script_name:
#                 prefix_path = environ['SCRIPT_NAME']
# 
#             new_location = rewrite_location(host_uri, response.location,
#                     prefix_path=prefix_path)
# 
#             headers = []
#             for k, v in response.headerslist:
#                 if k.lower() == 'location':
#                     v = new_location
#                 headers.append((k, v))
#         else:
#             headers = response.headerslist
# 
#         start_response(response.status, headers)
# 
#         if method == "HEAD":
#             return StringIO()
# 
#         return response.tee()


# Path: restkit/contrib/webob_api.py
import base64
import urlparse
import urllib
from StringIO import StringIO
    from webob import Request as BaseRequest
from .wsgi_proxy import Proxy

#!/usr/bin/env python
# -*- coding: utf-8 -
#
# This file is part of restkit released under the MIT license. 
# See the NOTICE for more information.


try:
except ImportError:
    raise ImportError('WebOb (http://pypi.python.org/pypi/WebOb) is required')


__doc__ = '''Subclasses of webob.Request who use restkit to get a
webob.Response via restkit.ext.wsgi_proxy.Proxy.

Example::


    >>> req = Request.blank('http://pypi.python.org/pypi/restkit')