# Path: opentracing_instrumentation/client_hooks/_dbapi2.py
# class ContextManagerConnectionWrapper(ConnectionWrapper):
#     """
#     Extends ConnectionWrapper by implementing `__enter__` and `__exit__`
#     methods of the context manager API, for connections that can be used
#     in as context managers to control the transactions, e.g.
# 
#     .. code-block:: python
# 
#         with MySQLdb.connect(...) as cursor:
#             cursor.execute(...)
#     """
# 
#     def __init__(self, connection, module_name, connect_params,
#                  cursor_wrapper):
#         super(ContextManagerConnectionWrapper, self).__init__(
#             connection=connection,
#             module_name=module_name,
#             connect_params=connect_params,
#             cursor_wrapper=cursor_wrapper
#         )
# 
#     def __getattr__(self, name):
#         # Tip suggested here:
#         # https://gist.github.com/mjallday/3d4c92e7e6805af1e024.
#         if name == '_sqla_unwrap':
#             return self.__wrapped__
#         return super(ContextManagerConnectionWrapper, self).__getattr__(name)
# 
#     def __enter__(self):
#         with func_span('%s:begin_transaction' % self._module_name):
#             cursor = self.__wrapped__.__enter__()
# 
#         return CursorWrapper(cursor=cursor,
#                              module_name=self._module_name,
#                              connect_params=self._connect_params)
# 
#     def __exit__(self, exc, value, tb):
#         outcome = _COMMIT if exc is None else _ROLLBACK
#         with db_span(sql_statement=outcome, module_name=self._module_name):
#             return self.__wrapped__.__exit__(exc, value, tb)
# 
# Path: opentracing_instrumentation/client_hooks/_dbapi2.py
# class ConnectionFactory(object):
#     """
#     Wraps connect_func of the DB API v2 module by creating a wrapper object
#     for the actual connection.
#     """
# 
#     def __init__(self, connect_func, module_name, conn_wrapper_ctor=None,
#                  cursor_wrapper=CursorWrapper):
#         self._connect_func = connect_func
#         self._module_name = module_name
#         if hasattr(connect_func, '__name__'):
#             self._connect_func_name = '%s:%s' % (module_name,
#                                                  connect_func.__name__)
#         else:
#             self._connect_func_name = '%s:%s' % (module_name, connect_func)
#         self._wrapper_ctor = conn_wrapper_ctor \
#             if conn_wrapper_ctor is not None else ConnectionWrapper
#         self._cursor_wrapper = cursor_wrapper
# 
#     def __call__(self, *args, **kwargs):
#         safe_kwargs = kwargs
#         if 'passwd' in kwargs or 'password' in kwargs or 'conv' in kwargs:
#             safe_kwargs = dict(kwargs)
#             if 'passwd' in safe_kwargs:
#                 del safe_kwargs['passwd']
#             if 'password' in safe_kwargs:
#                 del safe_kwargs['password']
#             if 'conv' in safe_kwargs:  # don't log conversion functions
#                 del safe_kwargs['conv']
#         connect_params = (args, safe_kwargs) if args or safe_kwargs else None
#         tags = {ext_tags.SPAN_KIND: ext_tags.SPAN_KIND_RPC_CLIENT}
#         with func_span(self._connect_func_name, tags=tags):
#             return self._wrapper_ctor(
#                 connection=self._connect_func(*args, **kwargs),
#                 module_name=self._module_name,
#                 connect_params=connect_params,
#                 cursor_wrapper=self._cursor_wrapper)
# 
# Path: opentracing_instrumentation/client_hooks/_patcher.py
# class Patcher(object):
# 
#     def __init__(self):
#         self.patches_installed = False
# 
#     @property
#     def applicable(self):
#         raise NotImplementedError
# 
#     def install_patches(self):
#         if self.patches_installed:
#             return
# 
#         if self.applicable:
#             self._install_patches()
#         self.patches_installed = True
# 
#     def reset_patches(self):
#         if self.applicable:
#             self._reset_patches()
#         self.patches_installed = False
# 
#     def _install_patches(self):
#         raise NotImplementedError
# 
#     def _reset_patches(self):
#         raise NotImplementedError
# 
#     @classmethod
#     def configure_hook_module(cls, context):
#         def set_patcher(custom_patcher):
#             context['patcher'] = custom_patcher
# 
#         def install_patches():
#             context['patcher'].install_patches()
# 
#         def reset_patches():
#             context['patcher'].reset_patches()
# 
#         context['patcher'] = cls()
#         context['set_patcher'] = set_patcher
#         context['install_patches'] = install_patches
#         context['reset_patches'] = reset_patches


from ._dbapi2 import ContextManagerConnectionWrapper as ConnectionWrapper
from ._dbapi2 import ConnectionFactory
from ._patcher import Patcher
    import MySQLdb
# Copyright (c) 2015,2019 Uber Technologies, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# 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.

from __future__ import absolute_import

# Try to save the original entry points
try:
except ImportError:
    pass
else:
    _MySQLdb_connect = MySQLdb.connect



# Path: opentracing_instrumentation/client_hooks/_dbapi2.py
# class ContextManagerConnectionWrapper(ConnectionWrapper):
#     """
#     Extends ConnectionWrapper by implementing `__enter__` and `__exit__`
#     methods of the context manager API, for connections that can be used
#     in as context managers to control the transactions, e.g.
# 
#     .. code-block:: python
# 
#         with MySQLdb.connect(...) as cursor:
#             cursor.execute(...)
#     """
# 
#     def __init__(self, connection, module_name, connect_params,
#                  cursor_wrapper):
#         super(ContextManagerConnectionWrapper, self).__init__(
#             connection=connection,
#             module_name=module_name,
#             connect_params=connect_params,
#             cursor_wrapper=cursor_wrapper
#         )
# 
#     def __getattr__(self, name):
#         # Tip suggested here:
#         # https://gist.github.com/mjallday/3d4c92e7e6805af1e024.
#         if name == '_sqla_unwrap':
#             return self.__wrapped__
#         return super(ContextManagerConnectionWrapper, self).__getattr__(name)
# 
#     def __enter__(self):
#         with func_span('%s:begin_transaction' % self._module_name):
#             cursor = self.__wrapped__.__enter__()
# 
#         return CursorWrapper(cursor=cursor,
#                              module_name=self._module_name,
#                              connect_params=self._connect_params)
# 
#     def __exit__(self, exc, value, tb):
#         outcome = _COMMIT if exc is None else _ROLLBACK
#         with db_span(sql_statement=outcome, module_name=self._module_name):
#             return self.__wrapped__.__exit__(exc, value, tb)
# 
# Path: opentracing_instrumentation/client_hooks/_dbapi2.py
# class ConnectionFactory(object):
#     """
#     Wraps connect_func of the DB API v2 module by creating a wrapper object
#     for the actual connection.
#     """
# 
#     def __init__(self, connect_func, module_name, conn_wrapper_ctor=None,
#                  cursor_wrapper=CursorWrapper):
#         self._connect_func = connect_func
#         self._module_name = module_name
#         if hasattr(connect_func, '__name__'):
#             self._connect_func_name = '%s:%s' % (module_name,
#                                                  connect_func.__name__)
#         else:
#             self._connect_func_name = '%s:%s' % (module_name, connect_func)
#         self._wrapper_ctor = conn_wrapper_ctor \
#             if conn_wrapper_ctor is not None else ConnectionWrapper
#         self._cursor_wrapper = cursor_wrapper
# 
#     def __call__(self, *args, **kwargs):
#         safe_kwargs = kwargs
#         if 'passwd' in kwargs or 'password' in kwargs or 'conv' in kwargs:
#             safe_kwargs = dict(kwargs)
#             if 'passwd' in safe_kwargs:
#                 del safe_kwargs['passwd']
#             if 'password' in safe_kwargs:
#                 del safe_kwargs['password']
#             if 'conv' in safe_kwargs:  # don't log conversion functions
#                 del safe_kwargs['conv']
#         connect_params = (args, safe_kwargs) if args or safe_kwargs else None
#         tags = {ext_tags.SPAN_KIND: ext_tags.SPAN_KIND_RPC_CLIENT}
#         with func_span(self._connect_func_name, tags=tags):
#             return self._wrapper_ctor(
#                 connection=self._connect_func(*args, **kwargs),
#                 module_name=self._module_name,
#                 connect_params=connect_params,
#                 cursor_wrapper=self._cursor_wrapper)
# 
# Path: opentracing_instrumentation/client_hooks/_patcher.py
# class Patcher(object):
# 
#     def __init__(self):
#         self.patches_installed = False
# 
#     @property
#     def applicable(self):
#         raise NotImplementedError
# 
#     def install_patches(self):
#         if self.patches_installed:
#             return
# 
#         if self.applicable:
#             self._install_patches()
#         self.patches_installed = True
# 
#     def reset_patches(self):
#         if self.applicable:
#             self._reset_patches()
#         self.patches_installed = False
# 
#     def _install_patches(self):
#         raise NotImplementedError
# 
#     def _reset_patches(self):
#         raise NotImplementedError
# 
#     @classmethod
#     def configure_hook_module(cls, context):
#         def set_patcher(custom_patcher):
#             context['patcher'] = custom_patcher
# 
#         def install_patches():
#             context['patcher'].install_patches()
# 
#         def reset_patches():
#             context['patcher'].reset_patches()
# 
#         context['patcher'] = cls()
#         context['set_patcher'] = set_patcher
#         context['install_patches'] = install_patches
#         context['reset_patches'] = reset_patches


# Path: opentracing_instrumentation/client_hooks/mysqldb.py
from ._dbapi2 import ContextManagerConnectionWrapper as ConnectionWrapper
from ._dbapi2 import ConnectionFactory
from ._patcher import Patcher
    import MySQLdb

# Copyright (c) 2015,2019 Uber Technologies, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# 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.

from __future__ import absolute_import

# Try to save the original entry points
try:
except ImportError:
    pass
else:
    _MySQLdb_connect = MySQLdb.connect



class MySQLdbPatcher(Patcher):