def cmd_process_info(self): """Gets the process list from the MySQL Server (Unsupported) """ raise errors.NotSupportedError( "Not implemented. Use a cursor to get processlist information.")
def to_postgres(value): try: adapter = TYPE_MAP[type(value)] except KeyError: raise errors.NotSupportedError('Cannot cast %s to postgres type' % type(value)) return adapter(value)
def do_auth(self, username=None, password=None, database=None, client_flags=0, charset=33): """Authenticate with the MySQL server """ if client_flags & ClientFlag.SSL: pkt = self._pkt_make_auth_ssl(username=username, password=password, database=database, charset=charset, client_flags=client_flags) self.conn.send(pkt,self.next_pktnr) self.conn.switch_to_ssl() pkt = self._pkt_make_auth(username=username, password=password, database=database, charset=charset, client_flags=client_flags) self.conn.send(pkt,self.next_pktnr) buf = self.conn.recv() if buf[4] == '\xfe': raise errors.NotSupportedError( "Authentication with old (insecure) passwords "\ "is not supported: "\ "http://dev.mysql.com/doc/refman/5.1/en/password-hashing.html") try: if not (client_flags & ClientFlag.CONNECT_WITH_DB) and database: self.cmd_init_db(database) except: raise return True
def cmd_process_info(self): """Get the process list of the MySQL Server This method is a placeholder to notify that the PROCESS_INFO command is not supported by raising the NotSupportedError. The command "SHOW PROCESSLIST" should be send using the cmd_query()-method or using the INFORMATION_SCHEMA database. Raises NotSupportedError exception """ raise errors.NotSupportedError( "Not implemented. Use SHOW PROCESSLIST or INFORMATION_SCHEMA")
def switch_to_ssl(self): try: self.sock = ssl.wrap_socket(self.sock, keyfile=self._ssl_key, certfile=self._ssl_cert, ca_certs=self._ssl_ca, cert_reqs=ssl.CERT_REQUIRED, do_handshake_on_connect=False, ssl_version=ssl.PROTOCOL_TLSv1) self.sock.do_handshake() except NameError: raise errors.NotSupportedError( "Python installation has no SSL support") except ssl.SSLError, e: raise errors.InterfaceError("SSL error: %s" % e)
def connect(self, database=None, user='', password='', host='127.0.0.1', port=3306, unix_socket=None, use_unicode=True, charset='utf8', collation=None, autocommit=False, time_zone=None, sql_mode=None, get_warnings=False, raise_on_warnings=False, connection_timeout=None, client_flags=0, buffered=False, raw=False, ssl_ca=None, ssl_cert=None, ssl_key=None, passwd=None, db=None, connect_timeout=None, dsn=None): if db and not database: database = db if passwd and not password: password = passwd if connect_timeout and not connection_timeout: connection_timeout = connect_timeout if dsn is not None: errors.NotSupportedError("Data source name is not supported") self._server_host = host self._server_port = port self._unix_socket = unix_socket if database is not None: self._database = str(database).strip() else: self._database = None self._username = user self.set_warnings(get_warnings,raise_on_warnings) self.connection_timeout = connection_timeout self.buffered = buffered self.raw = raw self.use_unicode = use_unicode self.set_client_flags(client_flags) self._charset = constants.CharacterSet.get_charset_info(charset)[0] if user or password: self.set_login(user, password) self.disconnect() self._open_connection(username=self._username, password=password, database=self._database, client_flags=self.client_flags, charset=charset, ssl=(ssl_ca, ssl_cert, ssl_key)) self._post_connection(time_zone=time_zone, sql_mode=sql_mode, collation=collation)
def switch_to_ssl(self, ca, cert, key): """Switch the socket to use SSL""" if not self.sock: raise errors.InterfaceError(errno=2048) try: self.sock = ssl.wrap_socket(self.sock, keyfile=key, certfile=cert, ca_certs=ca, cert_reqs=ssl.CERT_NONE, do_handshake_on_connect=False, ssl_version=ssl.PROTOCOL_TLSv1) self.sock.do_handshake() except NameError: raise errors.NotSupportedError( "Python installation has no SSL support") except ssl.SSLError, err: raise errors.InterfaceError("SSL error: %s" % err)
def _do_auth(self, username=None, password=None, database=None, client_flags=0, charset=33, ssl_options=None): """Authenticate with the MySQL server """ if client_flags & ClientFlag.SSL and ssl_options: packet = self._protocol.make_auth_ssl(charset=charset, client_flags=client_flags) self._socket.send(packet) self._socket.switch_to_ssl(**ssl_options) packet = self._protocol.make_auth(seed=self._handshake['scramble'], username=username, password=password, database=database, charset=charset, client_flags=client_flags) self._socket.send(packet) packet = self._socket.recv() if packet[4] == '\xfe': raise errors.NotSupportedError( "Authentication with old (insecure) passwords "\ "is not supported. For more information, lookup "\ "Password Hashing in the latest MySQL manual") elif packet[4] == '\xff': raise errors.get_exception(packet) try: if (not (client_flags & ClientFlag.CONNECT_WITH_DB) and database): self.cmd_init_db(database) except: raise return True
def process_request(self, req, resp): # allow methods if not req.method in cnf.ALLOW_METHODS: raise errors.NotSupportedError(method=req.method, url=req.url)
def config(self, **kwargs): """Configure the MySQL Connection This method allows you to configure the MySQLConnection instance. Raises on errors. """ config = kwargs.copy() if 'dsn' in config: raise errors.NotSupportedError("Data source name is not supported") # Configure how we handle MySQL warnings try: self.get_warnings = config['get_warnings'] del config['get_warnings'] except KeyError: pass # Leave what was set or default try: self.raise_on_warnings = config['raise_on_warnings'] del config['raise_on_warnings'] except KeyError: pass # Leave what was set or default # Configure client flags try: default = ClientFlag.get_default() self.set_client_flags(config['client_flags'] or default) del config['client_flags'] except KeyError: pass # Missing client_flags-argument is OK # Configure character set and collation if ('charset' in config or 'collation' in config): try: charset = config['charset'] del config['charset'] except KeyError: charset = None try: collation = config['collation'] del config['collation'] except KeyError: collation = None self._charset_id = CharacterSet.get_charset_info( charset, collation)[0] # Compatible configuration with other drivers compat_map = [ # (<other driver argument>,<translates to>) ('db', 'database'), ('passwd', 'password'), ('connect_timeout', 'connection_timeout'), ] for compat, translate in compat_map: try: if translate not in config: config[translate] = config[compat] del config[compat] except KeyError: pass # Missing compat argument is OK # Configure login information if ('user' in config or 'password' in config): try: user = config['user'] del config['user'] except KeyError: user = self._user try: password = config['password'] del config['password'] except KeyError: password = self._password self.set_login(user, password) # Check network locations try: self._port = int(config['port']) del config['port'] except KeyError: pass # Missing port argument is OK except ValueError: raise errors.InterfaceError( "TCP/IP port number should be an integer") # Other configuration set_ssl_flag = False for key, value in config.items(): try: DEFAULT_CONFIGURATION[key] except KeyError: raise AttributeError("Unsupported argument '%s'" % key) # SSL Configuration if key == 'ssl_verify_cert': set_ssl_flag = True self._ssl.update({'verify_cert': value}) elif key.startswith('ssl_') and value: set_ssl_flag = True self._ssl.update({key.replace('ssl_', ''): value}) else: attribute = '_' + key try: setattr(self, attribute, value.strip()) except AttributeError: setattr(self, attribute, value) if set_ssl_flag: if 'verify_cert' not in self._ssl: self._ssl['verify_cert'] = \ DEFAULT_CONFIGURATION['ssl_verify_cert'] required_keys = set(['ca', 'cert', 'key']) diff = list(required_keys - set(self._ssl.keys())) if diff: missing_attrs = ["ssl_" + val for val in diff] raise AttributeError("Missing SSL argument(s): %s" % (', '.join(missing_attrs))) self.set_client_flags([ClientFlag.SSL])