# Path: riak/util.py
# def str_to_bytes(value, encoding='utf-8'):
#     if PY2 or value is None:
#         return value
#     elif isinstance(value, list):
#         return [str_to_bytes(elem) for elem in value]
#     else:
#         return value.encode(encoding)


import base64
from six import PY2
from riak.util import str_to_bytes
    from httplib import NotConnected, HTTPConnection
    from http.client import NotConnected, HTTPConnection
        # Forces the population of stats and resources before any
        # other requests are made.
        self.server_version

    def close(self):
        """
        Closes the underlying HTTP connection.
        """
        try:
            self._connection.close()
        except NotConnected:
            pass

    # These are set by the HttpTransport initializer
    _connection_class = HTTPConnection
    _node = None

    def _security_auth_headers(self, username, password, headers):
        """
        Add in the requisite HTTP Authentication Headers

        :param username: Riak Security Username
        :type str
        :param password: Riak Security Password
        :type str
        :param headers: Dictionary of headers
        :type dict
        """
        userColonPassword = username + ":" + password
        b64UserColonPassword = base64. \

# Path: riak/util.py
# def str_to_bytes(value, encoding='utf-8'):
#     if PY2 or value is None:
#         return value
#     elif isinstance(value, list):
#         return [str_to_bytes(elem) for elem in value]
#     else:
#         return value.encode(encoding)


# Path: riak/transports/http/connection.py
import base64
from six import PY2
from riak.util import str_to_bytes
    from httplib import NotConnected, HTTPConnection
    from http.client import NotConnected, HTTPConnection

        # Forces the population of stats and resources before any
        # other requests are made.
        self.server_version

    def close(self):
        """
        Closes the underlying HTTP connection.
        """
        try:
            self._connection.close()
        except NotConnected:
            pass

    # These are set by the HttpTransport initializer
    _connection_class = HTTPConnection
    _node = None

    def _security_auth_headers(self, username, password, headers):
        """
        Add in the requisite HTTP Authentication Headers

        :param username: Riak Security Username
        :type str
        :param password: Riak Security Password
        :type str
        :param headers: Dictionary of headers
        :type dict
        """
        userColonPassword = username + ":" + password
        b64UserColonPassword = base64. \

            b64encode(str_to_bytes(userColonPassword)).decode("ascii")