# Path: treq/response.py
# class _Response(proxyForInterface(IResponse)):
#     def content(self):
#         return content(self.original)
# 
#     def json(self, *args, **kwargs):
#         return json_content(self.original, *args, **kwargs)
# 
#     def text(self, *args, **kwargs):
#         return text_content(self.original, *args, **kwargs)
# 
#     def history(self):
#         if not hasattr(self, "previousResponse"):
#             raise NotImplementedError(
#                 "Twisted < 13.1.0 does not support response history.")
# 
#         response = self
#         history = []
# 
#         while response.previousResponse is not None:
#             history.append(_Response(response.previousResponse))
#             response = response.previousResponse
# 
#         history.reverse()
#         return history


import mimetypes
import uuid
from io import BytesIO
from StringIO import StringIO
from os import path
from urlparse import urlparse, urlunparse
from urllib import urlencode
from twisted.internet.interfaces import IProtocol
from twisted.internet.defer import Deferred
from twisted.python.components import proxyForInterface
from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer, IResponse
from twisted.web.client import (
    FileBodyProducer,
    RedirectAgent,
    ContentDecoderAgent,
    GzipDecoder
)
from twisted.python.components import registerAdapter
from treq._utils import default_reactor
from treq.auth import add_auth
from treq import multipart
from treq.response import _Response

        if kwargs.get('allow_redirects', True):
            wrapped_agent = RedirectAgent(wrapped_agent)

        wrapped_agent = ContentDecoderAgent(wrapped_agent,
                                            [('gzip', GzipDecoder)])

        auth = kwargs.get('auth')
        if auth:
            wrapped_agent = add_auth(wrapped_agent, auth)

        d = wrapped_agent.request(
            method, url, headers=headers,
            bodyProducer=bodyProducer)

        timeout = kwargs.get('timeout')
        if timeout:
            delayedCall = default_reactor(kwargs.get('reactor')).callLater(
                timeout, d.cancel)

            def gotResult(result):
                if delayedCall.active():
                    delayedCall.cancel()
                return result

            d.addBoth(gotResult)

        if not kwargs.get('unbuffered', False):
            d.addCallback(_BufferedResponse)


# Path: treq/response.py
# class _Response(proxyForInterface(IResponse)):
#     def content(self):
#         return content(self.original)
# 
#     def json(self, *args, **kwargs):
#         return json_content(self.original, *args, **kwargs)
# 
#     def text(self, *args, **kwargs):
#         return text_content(self.original, *args, **kwargs)
# 
#     def history(self):
#         if not hasattr(self, "previousResponse"):
#             raise NotImplementedError(
#                 "Twisted < 13.1.0 does not support response history.")
# 
#         response = self
#         history = []
# 
#         while response.previousResponse is not None:
#             history.append(_Response(response.previousResponse))
#             response = response.previousResponse
# 
#         history.reverse()
#         return history


# Path: treq/client.py
import mimetypes
import uuid
from io import BytesIO
from StringIO import StringIO
from os import path
from urlparse import urlparse, urlunparse
from urllib import urlencode
from twisted.internet.interfaces import IProtocol
from twisted.internet.defer import Deferred
from twisted.python.components import proxyForInterface
from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer, IResponse
from twisted.web.client import (
    FileBodyProducer,
    RedirectAgent,
    ContentDecoderAgent,
    GzipDecoder
)
from twisted.python.components import registerAdapter
from treq._utils import default_reactor
from treq.auth import add_auth
from treq import multipart
from treq.response import _Response


        if kwargs.get('allow_redirects', True):
            wrapped_agent = RedirectAgent(wrapped_agent)

        wrapped_agent = ContentDecoderAgent(wrapped_agent,
                                            [('gzip', GzipDecoder)])

        auth = kwargs.get('auth')
        if auth:
            wrapped_agent = add_auth(wrapped_agent, auth)

        d = wrapped_agent.request(
            method, url, headers=headers,
            bodyProducer=bodyProducer)

        timeout = kwargs.get('timeout')
        if timeout:
            delayedCall = default_reactor(kwargs.get('reactor')).callLater(
                timeout, d.cancel)

            def gotResult(result):
                if delayedCall.active():
                    delayedCall.cancel()
                return result

            d.addBoth(gotResult)

        if not kwargs.get('unbuffered', False):
            d.addCallback(_BufferedResponse)


        return d.addCallback(_Response)