# Path: opentracing_instrumentation/client_hooks/urllib2.py
# def install_patches():
#     def build_handler(base_type, base_cls=None):
#             def do_open(self, req, conn):
#         def __init__(self, request):
#         def add_header(self, key, value):
#         def method(self):
#         def full_url(self):
#         def _headers(self):
#         def host_port(self):
#     def install_for_module(module, do_open_base=None):
#             def http_open(self, req):
#             def https_open(self, req):
#         class DerivedHandler(base_type):
#     class Urllib2RequestWrapper(AbstractRequestWrapper):
#         class TracedHTTPHandler(httpBase):
#         class TracedHTTPSHandler(httpsBase):
# 
# Path: opentracing_instrumentation/config.py
# CONFIG = _Config()
# 
# 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)


from future import standard_library
from tornado.httputil import HTTPHeaders
from opentracing_instrumentation.client_hooks import urllib2 as urllib2_hooks
from opentracing_instrumentation.config import CONFIG
from opentracing_instrumentation.request_context import span_in_context
import mock
import pytest
import six
    import urllib2
import urllib.request
standard_library.install_aliases()

if six.PY2:



@pytest.yield_fixture
def install_hooks(request):
    urllibver = request.getfixturevalue('urllibver')

    if urllibver == 'urllib2':
        if six.PY3:
            yield None
            return
        module = urllib2
    else:
        module = urllib.request

    old_opener = module._opener
    old_callee_headers = CONFIG.callee_name_headers
    old_endpoint_headers = CONFIG.callee_endpoint_headers

    urllib2_hooks.install_patches.__original_func()
    CONFIG.callee_name_headers = ['Remote-Loc']
    CONFIG.callee_endpoint_headers = ['Remote-Op']

    yield module

    module.install_opener(old_opener)
    CONFIG.callee_name_headers = old_callee_headers

# Path: opentracing_instrumentation/client_hooks/urllib2.py
# def install_patches():
#     def build_handler(base_type, base_cls=None):
#             def do_open(self, req, conn):
#         def __init__(self, request):
#         def add_header(self, key, value):
#         def method(self):
#         def full_url(self):
#         def _headers(self):
#         def host_port(self):
#     def install_for_module(module, do_open_base=None):
#             def http_open(self, req):
#             def https_open(self, req):
#         class DerivedHandler(base_type):
#     class Urllib2RequestWrapper(AbstractRequestWrapper):
#         class TracedHTTPHandler(httpBase):
#         class TracedHTTPSHandler(httpsBase):
# 
# Path: opentracing_instrumentation/config.py
# CONFIG = _Config()
# 
# 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_sync_client_hooks.py
from future import standard_library
from tornado.httputil import HTTPHeaders
from opentracing_instrumentation.client_hooks import urllib2 as urllib2_hooks
from opentracing_instrumentation.config import CONFIG
from opentracing_instrumentation.request_context import span_in_context
import mock
import pytest
import six
    import urllib2
import urllib.request

standard_library.install_aliases()

if six.PY2:



@pytest.yield_fixture
def install_hooks(request):
    urllibver = request.getfixturevalue('urllibver')

    if urllibver == 'urllib2':
        if six.PY3:
            yield None
            return
        module = urllib2
    else:
        module = urllib.request

    old_opener = module._opener
    old_callee_headers = CONFIG.callee_name_headers
    old_endpoint_headers = CONFIG.callee_endpoint_headers

    urllib2_hooks.install_patches.__original_func()
    CONFIG.callee_name_headers = ['Remote-Loc']
    CONFIG.callee_endpoint_headers = ['Remote-Op']

    yield module

    module.install_opener(old_opener)
    CONFIG.callee_name_headers = old_callee_headers

    CONFIG.callee_endpoint_headers = old_endpoint_headers