def __init__(self, *args, **kwargs):
        """

        Create a connection to the database. It is strongly recommended
        that you only use keyword parameters. Consult the MySQL C API
        documentation for more information.

        host
          string, host to connect
          
        user
          string, user to connect as

        passwd
          string, password to use

        db
          string, database to use

        port
          integer, TCP/IP port to connect to

        unix_socket
          string, location of unix_socket to use

        conv
          conversion dictionary, see MySQLdb.converters

        connect_timeout
          number of seconds to wait before the connection attempt
          fails.

        compress
          if set, compression is enabled

        named_pipe
          if set, a named pipe is used to connect (Windows only)

        init_command
          command which is run once the connection is created

        read_default_file
          file from which default client values are read

        read_default_group
          configuration group to use from the default file

        cursorclass
          class object, used to create cursors (keyword only)

        use_unicode
          If True, text-like columns are returned as unicode objects
          using the connection's character set.  Otherwise, text-like
          columns are returned as strings.  columns are returned as
          normal strings. Unicode objects will always be encoded to
          the connection's character set regardless of this setting.

        charset
          If supplied, the connection character set will be changed
          to this character set (MySQL-4.1 and newer). This implies
          use_unicode=True.

        sql_mode
          If supplied, the session SQL mode will be changed to this
          setting (MySQL-4.1 and newer). For more details and legal
          values, see the MySQL documentation.
          
        client_flag
          integer, flags to use or 0
          (see MySQL docs or constants/CLIENTS.py)

        ssl
          dictionary or mapping, contains SSL connection parameters;
          see the MySQL documentation for more details
          (mysql_ssl_set()).  If this is set, and the client does not
          support SSL, NotSupportedError will be raised.

        local_infile
          integer, non-zero enables LOAD LOCAL INFILE; zero disables
    
        There are a number of undocumented, non-standard methods. See the
        documentation for the MySQL C API for some hints on what they do.

        """
        from MySQLdb.constants import CLIENT, FIELD_TYPE
        from MySQLdb.converters import conversions
        from weakref import proxy, WeakValueDictionary
        
        import types

        kwargs2 = kwargs.copy()
        
        if 'conv' in kwargs:
            conv = kwargs['conv']
        else:
            conv = conversions

        conv2 = {}
        for k, v in conv.items():
            if isinstance(k, int) and isinstance(v, list):
                conv2[k] = v[:]
            else:
                conv2[k] = v
        kwargs2['conv'] = conv2

        cursorclass = kwargs2.pop('cursorclass', self.default_cursor)
        charset = kwargs2.pop('charset', '')

        if charset:
            use_unicode = True
        else:
            use_unicode = False
            
        use_unicode = kwargs2.pop('use_unicode', use_unicode)
        sql_mode = kwargs2.pop('sql_mode', '')

        client_flag = kwargs.get('client_flag', 0)
        client_version = tuple([ numeric_part(n) for n in _mysql.get_client_info().split('.')[:2] ])
        if client_version >= (4, 1):
            client_flag |= CLIENT.MULTI_STATEMENTS
        if client_version >= (5, 0):
            client_flag |= CLIENT.MULTI_RESULTS
            
        kwargs2['client_flag'] = client_flag

        super(Connection, self).__init__(*args, **kwargs2)
        self.cursorclass = cursorclass
        self.encoders = dict([ (k, v) for k, v in conv.items()
                               if type(k) is not int ])
        
        self._server_version = tuple([ numeric_part(n) for n in self.get_server_info().split('.')[:2] ])

        db = proxy(self)
        def _get_string_literal():
            def string_literal(obj, dummy=None):
                return db.string_literal(obj)
            return string_literal

        def _get_unicode_literal():
            def unicode_literal(u, dummy=None):
                return db.literal(u.encode(unicode_literal.charset))
            return unicode_literal

        def _get_string_decoder():
            def string_decoder(s):
                return s.decode(string_decoder.charset)
            return string_decoder
        
        string_literal = _get_string_literal()
        self.unicode_literal = unicode_literal = _get_unicode_literal()
        self.string_decoder = string_decoder = _get_string_decoder()
        if not charset:
            charset = self.character_set_name()
        self.set_character_set(charset)

        if sql_mode:
            self.set_sql_mode(sql_mode)

        if use_unicode:
            self.converter[FIELD_TYPE.STRING].append((None, string_decoder))
            self.converter[FIELD_TYPE.VAR_STRING].append((None, string_decoder))
            self.converter[FIELD_TYPE.VARCHAR].append((None, string_decoder))
            self.converter[FIELD_TYPE.BLOB].append((None, string_decoder))

        self.encoders[types.StringType] = string_literal
        self.encoders[types.UnicodeType] = unicode_literal
        self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
        if self._transactional:
            # PEP-249 requires autocommit to be initially off
            self.autocommit(False)
        self.messages = []
def __init__ ( self , * args , ** kwargs ) : from MySQLdb . constants import CLIENT , FIELD_TYPE from MySQLdb . converters import conversions from weakref import proxy , WeakValueDictionary import types kwargs2 = kwargs . copy ( ) if 'conv' in kwargs : conv = kwargs [ 'conv' ] else : conv = conversions conv2 = { } for k , v in conv . items ( ) : if isinstance ( k , int ) and isinstance ( v , list ) : conv2 [ k ] = v [ : ] else : conv2 [ k ] = v kwargs2 [ 'conv' ] = conv2 cursorclass = kwargs2 . pop ( 'cursorclass' , self . default_cursor ) charset = kwargs2 . pop ( 'charset' , '' ) if charset : use_unicode = True else : use_unicode = False use_unicode = kwargs2 . pop ( 'use_unicode' , use_unicode ) sql_mode = kwargs2 . pop ( 'sql_mode' , '' ) client_flag = kwargs . get ( 'client_flag' , 0 ) client_version = tuple ( [ numeric_part ( n ) for n in _mysql . get_client_info ( ) . split ( '.' ) [ : 2 ] ] ) if client_version >= ( 4 , 1 ) : client_flag |= CLIENT . MULTI_STATEMENTS if client_version >= ( 5 , 0 ) : client_flag |= CLIENT . MULTI_RESULTS kwargs2 [ 'client_flag' ] = client_flag super ( Connection , self ) . __init__ ( * args , ** kwargs2 ) self . cursorclass = cursorclass self . encoders = dict ( [ ( k , v ) for k , v in conv . items ( ) if type ( k ) is not int ] ) self . _server_version = tuple ( [ numeric_part ( n ) for n in self . get_server_info ( ) . split ( '.' ) [ : 2 ] ] ) db = proxy ( self ) def _get_string_literal ( ) : def string_literal ( obj , dummy = None ) : return db . string_literal ( obj ) return string_literal def _get_unicode_literal ( ) : def unicode_literal ( u , dummy = None ) : return db . literal ( u . encode ( unicode_literal . charset ) ) return unicode_literal def _get_string_decoder ( ) : def string_decoder ( s ) : return s . decode ( string_decoder . charset ) return string_decoder string_literal = _get_string_literal ( ) self . unicode_literal = unicode_literal = _get_unicode_literal ( ) self . string_decoder = string_decoder = _get_string_decoder ( ) if not charset : charset = self . character_set_name ( ) self . set_character_set ( charset ) if sql_mode : self . set_sql_mode ( sql_mode ) if use_unicode : self . converter [ FIELD_TYPE . STRING ] . append ( ( None , string_decoder ) ) self . converter [ FIELD_TYPE . VAR_STRING ] . append ( ( None , string_decoder ) ) self . converter [ FIELD_TYPE . VARCHAR ] . append ( ( None , string_decoder ) ) self . converter [ FIELD_TYPE . BLOB ] . append ( ( None , string_decoder ) ) self . encoders [ types . StringType ] = string_literal self . encoders [ types . UnicodeType ] = unicode_literal self . _transactional = self . server_capabilities & CLIENT . TRANSACTIONS if self . _transactional : self . autocommit ( False ) self . messages = [ ]
Create a connection to the database. It is strongly recommended
        that you only use keyword parameters. Consult the MySQL C API
        documentation for more information.

        host
          string, host to connect
          
        user
          string, user to connect as

        passwd
          string, password to use

        db
          string, database to use

        port
          integer, TCP/IP port to connect to

        unix_socket
          string, location of unix_socket to use

        conv
          conversion dictionary, see MySQLdb.converters

        connect_timeout
          number of seconds to wait before the connection attempt
          fails.

        compress
          if set, compression is enabled

        named_pipe
          if set, a named pipe is used to connect (Windows only)

        init_command
          command which is run once the connection is created

        read_default_file
          file from which default client values are read

        read_default_group
          configuration group to use from the default file

        cursorclass
          class object, used to create cursors (keyword only)

        use_unicode
          If True, text-like columns are returned as unicode objects
          using the connection's character set.  Otherwise, text-like
          columns are returned as strings.  columns are returned as
          normal strings. Unicode objects will always be encoded to
          the connection's character set regardless of this setting.

        charset
          If supplied, the connection character set will be changed
          to this character set (MySQL-4.1 and newer). This implies
          use_unicode=True.

        sql_mode
          If supplied, the session SQL mode will be changed to this
          setting (MySQL-4.1 and newer). For more details and legal
          values, see the MySQL documentation.
          
        client_flag
          integer, flags to use or 0
          (see MySQL docs or constants/CLIENTS.py)

        ssl
          dictionary or mapping, contains SSL connection parameters;
          see the MySQL documentation for more details
          (mysql_ssl_set()).  If this is set, and the client does not
          support SSL, NotSupportedError will be raised.

        local_infile
          integer, non-zero enables LOAD LOCAL INFILE; zero disables
    
        There are a number of undocumented, non-standard methods. See the
        documentation for the MySQL C API for some hints on what they do.