def _escape(s):
    e = s
    e = e.replace('\\', '\\\\')
    e = e.replace('\n', '\\n')
    e = e.replace('\r', '\\r')
    e = e.replace("'", "\\'")
    e = e.replace('"', '\\"')
    log.debug('%s => %s', s, e)
    return e class Error(Exception):
    pass class Warning(Exception):
    pass class InterfaceError(Error):
    pass class DatabaseError(Error):
    pass class InternalError(DatabaseError):
    pass class OperationalError(DatabaseError):
    pass class ProgrammingError(DatabaseError):
    pass class IntegrityError(DatabaseError):
    pass class DataError(DatabaseError):
    pass class NotSupportedError(DatabaseError):
    pass
import datetime
import re
import six
from six import reraise
from impala.util import _escape
from impala.error import (  # pylint: disable=unused-import
    Error, Warning, InterfaceError, DatabaseError, InternalError,
    OperationalError, ProgrammingError, IntegrityError, DataError,
    NotSupportedError)
        from thrift_sasl import TSaslClientTransport
# Copyright 2014 Cloudera Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

from __future__ import absolute_import




class Connection(object):
    # PEP 249
    # Connection objects are associated with a TCLIService.Client thrift
    # service
    # it's instantiated with an alive TCLIService.Client

    def close(self):
        # PEP 249
        raise NotImplementedError

    def commit(self):
        # PEP 249
        raise NotImplementedError

    def rollback(self):
        # PEP 249
        raise NotImplementedError

    def cursor(self, user=None, configuration=None, convert_types=True):
        # PEP 249
        raise NotImplementedError

    def reconnect(self):
        raise NotImplementedError

    def kerberized(self):
        # pylint: disable=protected-access
        # returns bool whether underlying service is kerberized or not
        if isinstance(self.service._iprot.trans, TSaslClientTransport):
            if self.service._iprot.trans.mechanism == 'GSSAPI':
                return True
        return False

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close()
        if exc_type is not None:
            reraise(exc_type, exc_val, exc_tb)

    # optional DB API addition to make the errors attributes of Connection
    Error = Error
    Warning = Warning

    InterfaceError = InterfaceError