# Path: opentracing_instrumentation/client_hooks/requests.py
# class RequestsPatcher(Patcher):
#     class RequestWrapper(AbstractRequestWrapper):
#     def set_response_handler_hook(self, response_handler_hook):
#     def _install_patches(self):
#     def _reset_patches(self):
#     def _get_send_wrapper(self):
#         def send_wrapper(http_adapter, request, **kwargs):
#         def __init__(self, request):
#         def add_header(self, key, value):
#         def method(self):
#         def full_url(self):
#         def _headers(self):
#         def host_port(self):
# 
# Path: opentracing_instrumentation/request_context.py
# def span_in_context(span):
#     """
#     Create a context manager that stores the given span in the thread-local
#     request context. This function should only be used in single-threaded
#     applications like Flask / uWSGI.
# 
#     ## Usage example in WSGI middleware:
# 
#     .. code-block:: python
#         from opentracing_instrumentation.http_server import WSGIRequestWrapper
#         from opentracing_instrumentation.http_server import before_request
#         from opentracing_instrumentation import request_context
# 
#         def create_wsgi_tracing_middleware(other_wsgi):
# 
#             def wsgi_tracing_middleware(environ, start_response):
#                 request = WSGIRequestWrapper.from_wsgi_environ(environ)
#                 span = before_request(request=request, tracer=tracer)
# 
#                 # Wrapper around the real start_response object to log
#                 # additional information to opentracing Span
#                 def start_response_wrapper(status, response_headers,
#                                            exc_info=None):
#                     if exc_info is not None:
#                         span.log(event='exception', payload=exc_info)
#                     span.finish()
# 
#                     return start_response(status, response_headers)
# 
#                 with request_context.span_in_context(span):
#                     return other_wsgi(environ, start_response_wrapper)
# 
#             return wsgi_tracing_middleware
# 
#     :param span: OpenTracing Span
#     :return:
#         Return context manager that wraps the request context.
#     """
# 
#     # Return a no-op Scope if None was specified.
#     if span is None:
#         return opentracing.Scope(None, None)
# 
#     return opentracing.tracer.scope_manager.activate(span, False)


import threading
import mock
import pytest
import requests
import tornado.httpserver
import tornado.ioloop
import tornado.web
    import asyncio
from opentracing_instrumentation.client_hooks.requests import patcher
from opentracing_instrumentation.request_context import span_in_context
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.



try:
    asyncio_available = True
except ImportError:
    asyncio_available = False


@pytest.fixture(name='response_handler_hook')
def patch_requests(hook):
    if hook:
        # using regular method instead of mock.Mock() to be sure
        # that it works as expected with Python 2.7
        def response_handler_hook(response, span):
            response_handler_hook.called_with = response, span
        response_handler_hook.called_with = None
    else:
        response_handler_hook = None

    patcher.install_patches()
    patcher.set_response_handler_hook(response_handler_hook)
    try:
        yield response_handler_hook
    finally:

# Path: opentracing_instrumentation/client_hooks/requests.py
# class RequestsPatcher(Patcher):
#     class RequestWrapper(AbstractRequestWrapper):
#     def set_response_handler_hook(self, response_handler_hook):
#     def _install_patches(self):
#     def _reset_patches(self):
#     def _get_send_wrapper(self):
#         def send_wrapper(http_adapter, request, **kwargs):
#         def __init__(self, request):
#         def add_header(self, key, value):
#         def method(self):
#         def full_url(self):
#         def _headers(self):
#         def host_port(self):
# 
# Path: opentracing_instrumentation/request_context.py
# def span_in_context(span):
#     """
#     Create a context manager that stores the given span in the thread-local
#     request context. This function should only be used in single-threaded
#     applications like Flask / uWSGI.
# 
#     ## Usage example in WSGI middleware:
# 
#     .. code-block:: python
#         from opentracing_instrumentation.http_server import WSGIRequestWrapper
#         from opentracing_instrumentation.http_server import before_request
#         from opentracing_instrumentation import request_context
# 
#         def create_wsgi_tracing_middleware(other_wsgi):
# 
#             def wsgi_tracing_middleware(environ, start_response):
#                 request = WSGIRequestWrapper.from_wsgi_environ(environ)
#                 span = before_request(request=request, tracer=tracer)
# 
#                 # Wrapper around the real start_response object to log
#                 # additional information to opentracing Span
#                 def start_response_wrapper(status, response_headers,
#                                            exc_info=None):
#                     if exc_info is not None:
#                         span.log(event='exception', payload=exc_info)
#                     span.finish()
# 
#                     return start_response(status, response_headers)
# 
#                 with request_context.span_in_context(span):
#                     return other_wsgi(environ, start_response_wrapper)
# 
#             return wsgi_tracing_middleware
# 
#     :param span: OpenTracing Span
#     :return:
#         Return context manager that wraps the request context.
#     """
# 
#     # Return a no-op Scope if None was specified.
#     if span is None:
#         return opentracing.Scope(None, None)
# 
#     return opentracing.tracer.scope_manager.activate(span, False)


# Path: tests/opentracing_instrumentation/test_requests.py
import threading
import mock
import pytest
import requests
import tornado.httpserver
import tornado.ioloop
import tornado.web
    import asyncio
from opentracing_instrumentation.client_hooks.requests import patcher
from opentracing_instrumentation.request_context import span_in_context

# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.



try:
    asyncio_available = True
except ImportError:
    asyncio_available = False


@pytest.fixture(name='response_handler_hook')
def patch_requests(hook):
    if hook:
        # using regular method instead of mock.Mock() to be sure
        # that it works as expected with Python 2.7
        def response_handler_hook(response, span):
            response_handler_hook.called_with = response, span
        response_handler_hook.called_with = None
    else:
        response_handler_hook = None

    patcher.install_patches()
    patcher.set_response_handler_hook(response_handler_hook)
    try:
        yield response_handler_hook
    finally:

        patcher.reset_patches()