# Path: osprofiler/_utils.py
# def split(text, strip=True):
# def binary_encode(text, encoding="utf-8"):
# def binary_decode(data, encoding="utf-8"):
# def generate_hmac(data, hmac_key):
# def signed_pack(data, hmac_key):
# def signed_unpack(data, hmac_data, hmac_keys):
# def itersubclasses(cls, _seen=None):
# def import_modules_from_package(package):
# def shorten_id(span_id):


import datetime
import logging
from urllib import parse as urlparse
from osprofiler import _utils
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



LOG = logging.getLogger(__name__)


def get_driver(connection_string, *args, **kwargs):
    """Create driver's instance according to specified connection string"""
    # NOTE(ayelistratov) Backward compatibility with old Messaging notation
    # Remove after patching all OS services
    # NOTE(ishakhat) Raise exception when ParsedResult.scheme is empty
    if "://" not in connection_string:
        connection_string += "://"

    parsed_connection = urlparse.urlparse(connection_string)
    LOG.debug("String %s looks like a connection string, trying it.",
              connection_string)

    backend = parsed_connection.scheme
    # NOTE(toabctl): To be able to use the connection_string for as sqlalchemy
    # connection string, transform the backend to the correct driver
    # See https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls
    if backend in ["mysql", "mysql+pymysql", "mysql+mysqldb",
                   "postgresql", "postgresql+psycopg2"]:
        backend = "sqlalchemy"

# Path: osprofiler/_utils.py
# def split(text, strip=True):
# def binary_encode(text, encoding="utf-8"):
# def binary_decode(data, encoding="utf-8"):
# def generate_hmac(data, hmac_key):
# def signed_pack(data, hmac_key):
# def signed_unpack(data, hmac_data, hmac_keys):
# def itersubclasses(cls, _seen=None):
# def import_modules_from_package(package):
# def shorten_id(span_id):


# Path: osprofiler/drivers/base.py
import datetime
import logging
from urllib import parse as urlparse
from osprofiler import _utils

#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



LOG = logging.getLogger(__name__)


def get_driver(connection_string, *args, **kwargs):
    """Create driver's instance according to specified connection string"""
    # NOTE(ayelistratov) Backward compatibility with old Messaging notation
    # Remove after patching all OS services
    # NOTE(ishakhat) Raise exception when ParsedResult.scheme is empty
    if "://" not in connection_string:
        connection_string += "://"

    parsed_connection = urlparse.urlparse(connection_string)
    LOG.debug("String %s looks like a connection string, trying it.",
              connection_string)

    backend = parsed_connection.scheme
    # NOTE(toabctl): To be able to use the connection_string for as sqlalchemy
    # connection string, transform the backend to the correct driver
    # See https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls
    if backend in ["mysql", "mysql+pymysql", "mysql+mysqldb",
                   "postgresql", "postgresql+psycopg2"]:
        backend = "sqlalchemy"

    for driver in _utils.itersubclasses(Driver):