# Path: restkit/version.py

# 
# Path: restkit/contrib/webob_api.py
# class Request(BaseRequest):
#     get = Method('get')
#     post = Method('post')
#     put = Method('put')
#     head = Method('head')
#     delete = Method('delete')
#     
#     def get_response(self):
#         if self.content_length < 0:
#             self.content_length = 0
#         if self.method in ('DELETE', 'GET'):
#             self.body = ''
#         elif self.method == 'POST' and self.POST:
#             body = urllib.urlencode(self.POST.copy())
#             stream = StringIO(body)
#             stream.seek(0)
#             self.body_file = stream
#             self.content_length = stream.len
#             if 'form' not in self.content_type:
#                 self.content_type = 'application/x-www-form-urlencoded'
#         self.server_name = self.host
#         return BaseRequest.get_response(self, PROXY)
# 
#     __call__ = get_response
# 
#     def set_url(self, url):
# 
#         path = url.lstrip('/')
# 
#         if url.startswith("http://") or url.startswith("https://"):
#             u = urlparse.urlsplit(url)
#             if u.username is not None:
#                 password = u.password or ""
#                 encode = base64.b64encode("%s:%s" % (u.username, password))
#                 self.headers['Authorization'] = 'Basic %s' %  encode
# 
#             self.scheme = u.scheme,
#             self.host = u.netloc.split("@")[-1]
#             self.path_info = u.path or "/"
#             self.query_string = u.query
#             url = urlparse.urlunsplit((u.scheme, u.netloc.split("@")[-1], 
#                 u.path, u.query, u.fragment))
#         else:
#         
#             if '?' in path:
#                 path, self.query_string = path.split('?', 1)
#             self.path_info = '/' + path
#             
# 
#             url = self.url
#         self.scheme, self.host, self.path_info = urlparse.urlparse(url)[0:3]


from StringIO import StringIO
    from IPython.config.loader import Config
    from IPython.frontend.terminal.embed  import InteractiveShellEmbed
from webob import Response as BaseResponse
from restkit import __version__
from restkit.contrib.console import common_indent, json
from restkit.contrib.webob_api import Request as BaseRequest
import urlparse
    import webob
    import sys
    def get_response(self, *args, **kwargs):
        url = self.url
        stream = None
        for a in args:
            if isinstance(a, Stream):
                stream = a
                a.seek(0)
                continue
            elif isinstance(a, basestring):
                if a.startswith('http'):
                    url = a
                elif a.startswith('/'):
                    url = a

        self.set_url(url)

        if stream:
            self.body_file = stream
            self.content_length = stream.len
        if self.method == 'GET' and kwargs:
            for k, v in kwargs.items():
                self.GET[k] = v
        elif self.method == 'POST' and kwargs:
            for k, v in kwargs.items():
                self.GET[k] = v
        return BaseRequest.get_response(self)

    def __str__(self, skip_body=True):
        if self.content_length < 200 and skip_body:
            skip_body = False

# Path: restkit/version.py

# 
# Path: restkit/contrib/webob_api.py
# class Request(BaseRequest):
#     get = Method('get')
#     post = Method('post')
#     put = Method('put')
#     head = Method('head')
#     delete = Method('delete')
#     
#     def get_response(self):
#         if self.content_length < 0:
#             self.content_length = 0
#         if self.method in ('DELETE', 'GET'):
#             self.body = ''
#         elif self.method == 'POST' and self.POST:
#             body = urllib.urlencode(self.POST.copy())
#             stream = StringIO(body)
#             stream.seek(0)
#             self.body_file = stream
#             self.content_length = stream.len
#             if 'form' not in self.content_type:
#                 self.content_type = 'application/x-www-form-urlencoded'
#         self.server_name = self.host
#         return BaseRequest.get_response(self, PROXY)
# 
#     __call__ = get_response
# 
#     def set_url(self, url):
# 
#         path = url.lstrip('/')
# 
#         if url.startswith("http://") or url.startswith("https://"):
#             u = urlparse.urlsplit(url)
#             if u.username is not None:
#                 password = u.password or ""
#                 encode = base64.b64encode("%s:%s" % (u.username, password))
#                 self.headers['Authorization'] = 'Basic %s' %  encode
# 
#             self.scheme = u.scheme,
#             self.host = u.netloc.split("@")[-1]
#             self.path_info = u.path or "/"
#             self.query_string = u.query
#             url = urlparse.urlunsplit((u.scheme, u.netloc.split("@")[-1], 
#                 u.path, u.query, u.fragment))
#         else:
#         
#             if '?' in path:
#                 path, self.query_string = path.split('?', 1)
#             self.path_info = '/' + path
#             
# 
#             url = self.url
#         self.scheme, self.host, self.path_info = urlparse.urlparse(url)[0:3]


# Path: restkit/contrib/ipython_shell.py
from StringIO import StringIO
    from IPython.config.loader import Config
    from IPython.frontend.terminal.embed  import InteractiveShellEmbed
from webob import Response as BaseResponse
from restkit import __version__
from restkit.contrib.console import common_indent, json
from restkit.contrib.webob_api import Request as BaseRequest
import urlparse
    import webob
    import sys

    def get_response(self, *args, **kwargs):
        url = self.url
        stream = None
        for a in args:
            if isinstance(a, Stream):
                stream = a
                a.seek(0)
                continue
            elif isinstance(a, basestring):
                if a.startswith('http'):
                    url = a
                elif a.startswith('/'):
                    url = a

        self.set_url(url)

        if stream:
            self.body_file = stream
            self.content_length = stream.len
        if self.method == 'GET' and kwargs:
            for k, v in kwargs.items():
                self.GET[k] = v
        elif self.method == 'POST' and kwargs:
            for k, v in kwargs.items():
                self.GET[k] = v
        return BaseRequest.get_response(self)

    def __str__(self, skip_body=True):
        if self.content_length < 200 and skip_body:
            skip_body = False

        return BaseRequest.__str__(self, skip_body=skip_body)