# Path: impala/error.py
# class HttpError(RPCError):
#     """An error containing an http response code"""
#     def __init__(self, code, message, body, http_headers):
#         self.code = code
#         self.message = message
#         self.body = body
#         self.http_headers = http_headers
# 
#     def __str__(self):
#         # Don't try to print the body as we don't know what format it is.
#         return "HTTP code {}: {}".format(self.code, self.message)
# 
# Path: impala/util.py
# def get_logger_and_init_null(logger_name):
#     logger = logging.getLogger(logger_name)
#     logger.addHandler(NullHandler())
#     return logger
# 
# Path: impala/util.py
# def get_all_matching_cookies(cookie_names, path, resp_headers):
#     if 'Set-Cookie' not in resp_headers:
#         return None
# 
#     cookies = http_cookies.SimpleCookie()
#     try:
#         cookies.load(resp_headers['Set-Cookie'])
#     except:
#         return None
# 
#     matching_cookies = []
#     for cn in cookie_names:
#         if cn in cookies:
#             c = cookies[cn]
#             if c and cookie_matches_path(c, path):
#                 matching_cookies.append(c)
#     return matching_cookies
# 
# def get_cookie_expiry(c):
#     if 'max-age' in c and c['max-age']:
#         try:
#             max_age_sec = int(c['max-age'])
#             return datetime.datetime.now() + datetime.timedelta(seconds=max_age_sec)
#         except:
#             pass
#     # TODO: implement support for 'expires' cookie attribute as well.
#     return None
# 
# Path: impala/_thrift_gen/ImpalaService/ImpalaHiveServer2Service.py
# class Iface(impala._thrift_gen.TCLIService.TCLIService.Iface):
# class Client(impala._thrift_gen.TCLIService.TCLIService.Client, Iface):
# class Processor(impala._thrift_gen.TCLIService.TCLIService.Processor, Iface, TProcessor):
# class GetExecSummary_args(object):
# class GetExecSummary_result(object):
# class GetRuntimeProfile_args(object):
# class GetRuntimeProfile_result(object):
#     def GetExecSummary(self, req):
#     def GetRuntimeProfile(self, req):
#     def __init__(self, iprot, oprot=None):
#     def GetExecSummary(self, req):
#     def send_GetExecSummary(self, req):
#     def recv_GetExecSummary(self):
#     def GetRuntimeProfile(self, req):
#     def send_GetRuntimeProfile(self, req):
#     def recv_GetRuntimeProfile(self):
#     def __init__(self, handler):
#     def process(self, iprot, oprot):
#     def process_GetExecSummary(self, seqid, iprot, oprot):
#     def process_GetRuntimeProfile(self, seqid, iprot, oprot):
#     def __init__(self, req=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, success=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, req=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, success=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]


import base64
import datetime
import getpass
import os
import os.path
import warnings
import six
import ssl
import sys
            import kerberos
from collections import namedtuple
from io import BytesIO
from six.moves import urllib, http_client
from impala.error import HttpError
from impala.util import get_logger_and_init_null
from impala.util import get_all_matching_cookies, get_cookie_expiry
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import (
    TBufferedTransport, TTransportException, TTransportBase)
from impala._thrift_gen.ImpalaService import ImpalaHiveServer2Service
        from thrift.transport.TSSLSocket import TSSLSocket
    from thrift_sasl import TSaslClientTransport
    from impala.sasl_compat import PureSASLClient
# limitations under the License.

# This package's main goal in the past was to clean up references to thrift, because
# we were using thriftpy2 for Py3. This is no longer necessary since upgrading to
# Thrift 0.11.0, as Thrift supports Python 3 since 0.10.0. Now there are only some
# leftover utility classes and functions.

# pylint: disable=wrong-import-position

from __future__ import absolute_import





# Declare namedtuple for Cookie with named fields - cookie and expiry_time
Cookie = namedtuple('Cookie', ['cookie', 'expiry_time'])

log = get_logger_and_init_null(__name__)


# pylint: disable=import-error,unused-import
# import Apache Thrift code

# import HS2 codegen objects
ThriftClient = ImpalaHiveServer2Service.Client


# ImpalaHttpClient is copied from Impala Shell.
# The implementations should be kept in sync as much as possible.

# Path: impala/error.py
# class HttpError(RPCError):
#     """An error containing an http response code"""
#     def __init__(self, code, message, body, http_headers):
#         self.code = code
#         self.message = message
#         self.body = body
#         self.http_headers = http_headers
# 
#     def __str__(self):
#         # Don't try to print the body as we don't know what format it is.
#         return "HTTP code {}: {}".format(self.code, self.message)
# 
# Path: impala/util.py
# def get_logger_and_init_null(logger_name):
#     logger = logging.getLogger(logger_name)
#     logger.addHandler(NullHandler())
#     return logger
# 
# Path: impala/util.py
# def get_all_matching_cookies(cookie_names, path, resp_headers):
#     if 'Set-Cookie' not in resp_headers:
#         return None
# 
#     cookies = http_cookies.SimpleCookie()
#     try:
#         cookies.load(resp_headers['Set-Cookie'])
#     except:
#         return None
# 
#     matching_cookies = []
#     for cn in cookie_names:
#         if cn in cookies:
#             c = cookies[cn]
#             if c and cookie_matches_path(c, path):
#                 matching_cookies.append(c)
#     return matching_cookies
# 
# def get_cookie_expiry(c):
#     if 'max-age' in c and c['max-age']:
#         try:
#             max_age_sec = int(c['max-age'])
#             return datetime.datetime.now() + datetime.timedelta(seconds=max_age_sec)
#         except:
#             pass
#     # TODO: implement support for 'expires' cookie attribute as well.
#     return None
# 
# Path: impala/_thrift_gen/ImpalaService/ImpalaHiveServer2Service.py
# class Iface(impala._thrift_gen.TCLIService.TCLIService.Iface):
# class Client(impala._thrift_gen.TCLIService.TCLIService.Client, Iface):
# class Processor(impala._thrift_gen.TCLIService.TCLIService.Processor, Iface, TProcessor):
# class GetExecSummary_args(object):
# class GetExecSummary_result(object):
# class GetRuntimeProfile_args(object):
# class GetRuntimeProfile_result(object):
#     def GetExecSummary(self, req):
#     def GetRuntimeProfile(self, req):
#     def __init__(self, iprot, oprot=None):
#     def GetExecSummary(self, req):
#     def send_GetExecSummary(self, req):
#     def recv_GetExecSummary(self):
#     def GetRuntimeProfile(self, req):
#     def send_GetRuntimeProfile(self, req):
#     def recv_GetRuntimeProfile(self):
#     def __init__(self, handler):
#     def process(self, iprot, oprot):
#     def process_GetExecSummary(self, seqid, iprot, oprot):
#     def process_GetRuntimeProfile(self, seqid, iprot, oprot):
#     def __init__(self, req=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, success=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, req=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, success=None,):
#     def read(self, iprot):
#     def write(self, oprot):
#     def validate(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]
#         L = ['%s=%r' % (key, value)
#              for key, value in self.__dict__.items()]


# Path: impala/_thrift_api.py
import base64
import datetime
import getpass
import os
import os.path
import warnings
import six
import ssl
import sys
            import kerberos
from collections import namedtuple
from io import BytesIO
from six.moves import urllib, http_client
from impala.error import HttpError
from impala.util import get_logger_and_init_null
from impala.util import get_all_matching_cookies, get_cookie_expiry
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import (
    TBufferedTransport, TTransportException, TTransportBase)
from impala._thrift_gen.ImpalaService import ImpalaHiveServer2Service
        from thrift.transport.TSSLSocket import TSSLSocket
    from thrift_sasl import TSaslClientTransport
    from impala.sasl_compat import PureSASLClient

# limitations under the License.

# This package's main goal in the past was to clean up references to thrift, because
# we were using thriftpy2 for Py3. This is no longer necessary since upgrading to
# Thrift 0.11.0, as Thrift supports Python 3 since 0.10.0. Now there are only some
# leftover utility classes and functions.

# pylint: disable=wrong-import-position

from __future__ import absolute_import





# Declare namedtuple for Cookie with named fields - cookie and expiry_time
Cookie = namedtuple('Cookie', ['cookie', 'expiry_time'])

log = get_logger_and_init_null(__name__)


# pylint: disable=import-error,unused-import
# import Apache Thrift code

# import HS2 codegen objects
ThriftClient = ImpalaHiveServer2Service.Client


# ImpalaHttpClient is copied from Impala Shell.
# The implementations should be kept in sync as much as possible.

class ImpalaHttpClient(TTransportBase):