def set_charset_collation(self, charset=None, collation=None):
        """Sets the character set and collation for the current connection

        This method sets the character set and collation to be used for
        the current connection. The charset argument can be either the
        name of a character set as a string, or the numerical equivalent
        as defined in constants.CharacterSet.

        When the collation is not given, the default will be looked up and
        used.

        For example, the following will set the collation for the latin1
        character set to latin1_general_ci:

           set_charset('latin1','latin1_general_ci')

        """
        if charset:
            if isinstance(charset, int):
                self._charset_id = charset
                (charset_name, collation_name) = CharacterSet.get_info(self._charset_id)
            elif isinstance(charset, str):
                (self._charset_id, charset_name, collation_name) = CharacterSet.get_charset_info(charset, collation)
            else:
                raise ValueError("charset should be either integer, string or None")
        elif collation:
            (self._charset_id, charset_name, collation_name) = CharacterSet.get_charset_info(collation=collation)

        self._execute_query("SET NAMES '{}' COLLATE '{}'".format(charset_name, collation_name))
        self.converter.set_charset(charset_name)
    def charset(self):
        """Returns the character set for current connection

        This property returns the character set name of the current connection.
        The server is queried when the connection is active. If not connected,
        the configured character set name is returned.

        Returns a string.
        """
        return CharacterSet.get_info(self._charset_id)[0]
 def set_converter_class(self, convclass):
     """
     Set the converter class to be used. This should be a class overloading
     methods and members of conversion.MySQLConverter.
     """
     if issubclass(convclass, MySQLConverterBase):
         charset_name = CharacterSet.get_info(self._charset_id)[0]
         self._converter_class = convclass
         self.converter = convclass(charset_name, self._use_unicode)
     else:
         raise TypeError("Converter class should be a subclass " "of conversion.MySQLConverterBase.")