本文整理汇总了Python中mysql.connector.constants.ClientFlag.get_default方法的典型用法代码示例。如果您正苦于以下问题:Python ClientFlag.get_default方法的具体用法?Python ClientFlag.get_default怎么用?Python ClientFlag.get_default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.connector.constants.ClientFlag
的用法示例。
在下文中一共展示了ClientFlag.get_default方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_changeuser
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def test_make_changeuser(self):
"""Make a change user MySQL packet"""
exp = {
'allset':
b'\x11\x68\x61\x6d\x00\x14\x3a\x07'
b'\x66\xba\xba\x01\xce\xbe\x55\xe6\x29\x88\xaa\xae'
b'\xdb\x00\xb3\x4d\x91\x5b\x74\x65\x73\x74\x00\x08'
b'\x00',
'nopass':
b'\x11\x68\x61\x6d\x00\x00\x74\x65'
b'\x73\x74\x00\x08\x00',
}
kwargs = {
'seed': None,
'username': 'ham',
'password': 'spam',
'database': 'test',
'charset': 8,
'client_flags': ClientFlag.get_default()
}
self.assertRaises(errors.ProgrammingError,
self._protocol.make_change_user, **kwargs)
kwargs['seed'] = SEED
res = self._protocol.make_change_user(**kwargs)
self.assertEqual(exp['allset'], res)
kwargs['password'] = None
res = self._protocol.make_change_user(**kwargs)
self.assertEqual(exp['nopass'], res)
示例2: test_make_changeuser
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def test_make_changeuser(self):
"""Make a change user MySQL packet"""
exp = {
"allset": bytearray(
b"\x11\x68\x61\x6d\x00\x14\x3a\x07"
b"\x66\xba\xba\x01\xce\xbe\x55\xe6\x29\x88\xaa\xae"
b"\xdb\x00\xb3\x4d\x91\x5b\x74\x65\x73\x74\x00\x08"
b"\x00"
),
"nopass": bytearray(b"\x11\x68\x61\x6d\x00\x00\x74\x65" b"\x73\x74\x00\x08\x00"),
}
kwargs = {
"handshake": None,
"username": "ham",
"password": "spam",
"database": "test",
"charset": 8,
"client_flags": ClientFlag.get_default(),
}
self.assertRaises(errors.ProgrammingError, self._protocol.make_change_user, **kwargs)
kwargs["handshake"] = {"auth_data": SEED}
self.assertRaises(errors.ProgrammingError, self._protocol.make_change_user, **kwargs)
kwargs["handshake"] = {"auth_data": SEED, "auth_plugin": "mysql_native_password"}
res = self._protocol.make_change_user(**kwargs)
self.assertEqual(exp["allset"], res)
kwargs["password"] = None
res = self._protocol.make_change_user(**kwargs)
self.assertEqual(exp["nopass"], res)
示例3: test_make_auth
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def test_make_auth(self):
"""Make a MySQL authentication packet"""
exp = {
'allset':
b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce'
b'\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'
b'\x5b\x74\x65\x73\x74\x00',
'nopass':
b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x68\x61\x6d\x00\x00\x74\x65\x73\x74\x00',
'nouser':
b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x14\x3a\x07\x66\xba\xba\x01\xce'
b'\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'
b'\x5b\x74\x65\x73\x74\x00',
'nodb':
b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce'
b'\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'
b'\x5b\x00',
}
flags = ClientFlag.get_default()
kwargs = {
'seed': None,
'username': 'ham',
'password': 'spam',
'database': 'test',
'charset': 33,
'client_flags': flags}
self.assertRaises(errors.ProgrammingError,
self._protocol.make_auth, **kwargs)
kwargs['seed'] = SEED
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['allset'], res)
kwargs['password'] = None
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['nopass'], res)
kwargs['password'] = 'spam'
kwargs['database'] = None
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['nodb'], res)
kwargs['username'] = None
kwargs['database'] = 'test'
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['nouser'], res)
示例4: setUp
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def setUp(self):
self.config = tests.get_mysql_config()
connect_args = [
"host", "user", "password", "database",
"port", "unix_socket", "client_flags"
]
self.connect_kwargs = {}
for key, value in self.config.items():
if key in connect_args:
self.connect_kwargs[key] = value
if 'client_flags' not in self.connect_kwargs:
self.connect_kwargs['client_flags'] = ClientFlag.get_default()
示例5: create_connect_args
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def create_connect_args(self, url):
opts = url.translate_connect_args(username='user')
opts.update(url.query)
util.coerce_kw_type(opts, 'buffered', bool)
util.coerce_kw_type(opts, 'raise_on_warnings', bool)
opts['buffered'] = True
opts['raise_on_warnings'] = True
# FOUND_ROWS must be set in ClientFlag to enable
# supports_sane_rowcount.
if self.dbapi is not None:
try:
from mysql.connector.constants import ClientFlag
client_flags = opts.get('client_flags', ClientFlag.get_default())
client_flags |= ClientFlag.FOUND_ROWS
opts['client_flags'] = client_flags
except:
pass
return [[], opts]
示例6: create_connect_args
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def create_connect_args(self, url):
opts = url.translate_connect_args(username="user")
opts.update(url.query)
util.coerce_kw_type(opts, "allow_local_infile", bool)
util.coerce_kw_type(opts, "autocommit", bool)
util.coerce_kw_type(opts, "buffered", bool)
util.coerce_kw_type(opts, "compress", bool)
util.coerce_kw_type(opts, "connection_timeout", int)
util.coerce_kw_type(opts, "connect_timeout", int)
util.coerce_kw_type(opts, "consume_results", bool)
util.coerce_kw_type(opts, "force_ipv6", bool)
util.coerce_kw_type(opts, "get_warnings", bool)
util.coerce_kw_type(opts, "pool_reset_session", bool)
util.coerce_kw_type(opts, "pool_size", int)
util.coerce_kw_type(opts, "raise_on_warnings", bool)
util.coerce_kw_type(opts, "raw", bool)
util.coerce_kw_type(opts, "ssl_verify_cert", bool)
util.coerce_kw_type(opts, "use_pure", bool)
util.coerce_kw_type(opts, "use_unicode", bool)
# unfortunately, MySQL/connector python refuses to release a
# cursor without reading fully, so non-buffered isn't an option
opts.setdefault("buffered", True)
# FOUND_ROWS must be set in ClientFlag to enable
# supports_sane_rowcount.
if self.dbapi is not None:
try:
from mysql.connector.constants import ClientFlag
client_flags = opts.get(
"client_flags", ClientFlag.get_default()
)
client_flags |= ClientFlag.FOUND_ROWS
opts["client_flags"] = client_flags
except Exception:
pass
return [[], opts]
示例7: __init__
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def __init__(self, *args, **kwargs):
self._protocol = None
self._socket = None
self._handshake = None
self._server_version = None
self.converter = None
self._converter_class = MySQLConverter
self._client_flags = ClientFlag.get_default()
self._charset_id = 33
self._sql_mode = None
self._time_zone = None
self._autocommit = False
self._user = ""
self._password = ""
self._database = ""
self._host = "127.0.0.1"
self._port = 3306
self._unix_socket = None
self._client_host = ""
self._client_port = 0
self._ssl = {}
self._force_ipv6 = False
self._use_unicode = True
self._get_warnings = False
self._raise_on_warnings = False
self._connection_timeout = None
self._buffered = False
self._unread_result = False
self._have_next_result = False
self._raw = False
self._in_transaction = False
self._prepared_statements = None
if len(kwargs) > 0:
self.connect(**kwargs)
示例8: create_connect_args
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def create_connect_args(self, url):
opts = url.translate_connect_args(username='user')
opts.update(url.query)
util.coerce_kw_type(opts, 'buffered', bool)
util.coerce_kw_type(opts, 'raise_on_warnings', bool)
# unfortunately, MySQL/connector python refuses to release a
# cursor without reading fully, so non-buffered isn't an option
opts.setdefault('buffered', True)
# FOUND_ROWS must be set in ClientFlag to enable
# supports_sane_rowcount.
if self.dbapi is not None:
try:
from mysql.connector.constants import ClientFlag
client_flags = opts.get('client_flags', ClientFlag.get_default())
client_flags |= ClientFlag.FOUND_ROWS
opts['client_flags'] = client_flags
except:
pass
return [[], opts]
示例9: test_make_changeuser
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def test_make_changeuser(self):
"""Make a change user MySQL packet"""
exp = {
'allset': bytearray(
b'\x11ham\x00\x143\xaa_'
b'\x92\\d\x94Z\xb2\xf8;U\x8a\x0c\xfb'
b'\x8a\xfc\xa7\xd0\xe3test\x00\x08'
b'\x00'),
'nopass': bytearray(
b'\x11\x68\x61\x6d\x00\x00\x74\x65'
b'\x73\x74\x00\x08\x00'),
}
kwargs = {
'handshake': None,
'username': 'ham',
'password': 'spam',
'database': 'test',
'charset': 8,
'client_flags': ClientFlag.get_default()
}
self.assertRaises(errors.ProgrammingError,
self._protocol.make_change_user, **kwargs)
kwargs['handshake'] = {'auth_data': SEED}
self.assertRaises(errors.ProgrammingError,
self._protocol.make_change_user, **kwargs)
kwargs['handshake'] = {
'auth_data': SEED,
'auth_plugin': 'mysql_native_password'
}
res = self._protocol.make_change_user(**kwargs)
self.assertEqual(exp['allset'], res)
kwargs['password'] = None
res = self._protocol.make_change_user(**kwargs)
self.assertEqual(exp['nopass'], res)
示例10: test_make_auth
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def test_make_auth(self):
"""Make a MySQL authentication packet"""
exp = {
"allset": bytearray(
b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce"
b"\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91"
b"\x5b\x74\x65\x73\x74\x00"
),
"nopass": bytearray(
b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x68\x61\x6d\x00\x00\x74\x65\x73\x74\x00"
),
"nouser": bytearray(
b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x14\x3a\x07\x66\xba\xba\x01\xce"
b"\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91"
b"\x5b\x74\x65\x73\x74\x00"
),
"nodb": bytearray(
b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce"
b"\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91"
b"\x5b\x00"
),
}
flags = ClientFlag.get_default()
kwargs = {
"handshake": None,
"username": "ham",
"password": "spam",
"database": "test",
"charset": 33,
"client_flags": flags,
}
self.assertRaises(errors.ProgrammingError, self._protocol.make_auth, **kwargs)
kwargs["handshake"] = {"auth_data": SEED}
self.assertRaises(errors.ProgrammingError, self._protocol.make_auth, **kwargs)
kwargs["handshake"] = {"auth_data": SEED, "auth_plugin": "mysql_native_password"}
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp["allset"], res)
kwargs["password"] = None
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp["nopass"], res)
kwargs["password"] = "spam"
kwargs["database"] = None
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp["nodb"], res)
kwargs["username"] = None
kwargs["database"] = "test"
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp["nouser"], res)
示例11: test_make_auth
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def test_make_auth(self):
"""Make a MySQL authentication packet"""
exp = {
'allset': bytearray(
b'\x0d\xa2\x03\x00\x00\x00\[email protected]!'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
b'\x00\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
b'\xfb\x8a\xfc\xa7\xd0\xe3test\x00'),
'nopass': bytearray(
b'\x0d\xa2\x03\x00\x00\x00\[email protected]!'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
b'\x00\x00test\x00'),
'nouser': bytearray(
b'\x0d\xa2\x03\x00\x00\x00\[email protected]!'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
b'\xfb\x8a\xfc\xa7\xd0\xe3test\x00'),
'nodb': bytearray(
b'\x0d\xa2\x03\x00\x00\x00\[email protected]!'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
b'\x00\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
b'\xfb\x8a\xfc\xa7\xd0\xe3\x00'),
}
flags = ClientFlag.get_default()
kwargs = {
'handshake': None,
'username': 'ham',
'password': 'spam',
'database': 'test',
'charset': 33,
'client_flags': flags
}
self.assertRaises(errors.ProgrammingError,
self._protocol.make_auth, **kwargs)
kwargs['handshake'] = {'auth_data': SEED}
self.assertRaises(errors.ProgrammingError,
self._protocol.make_auth, **kwargs)
kwargs['handshake'] = {
'auth_data': SEED,
'auth_plugin': 'mysql_native_password'
}
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['allset'], res)
kwargs['password'] = None
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['nopass'], res)
kwargs['password'] = 'spam'
kwargs['database'] = None
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['nodb'], res)
kwargs['username'] = None
kwargs['database'] = 'test'
res = self._protocol.make_auth(**kwargs)
self.assertEqual(exp['nouser'], res)
示例12: config
# 需要导入模块: from mysql.connector.constants import ClientFlag [as 别名]
# 或者: from mysql.connector.constants.ClientFlag import get_default [as 别名]
def config(self, *args, **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
try:
if config["compress"]:
self.set_client_flags([ClientFlag.COMPRESS])
except KeyError:
pass # Missing compress 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]
# Set converter class
try:
self.set_converter_class(config["converter_class"])
except KeyError:
pass # Using default converter class
except TypeError:
raise AttributeError("Converter class should be a subclass " "of conversion.MySQLConverterBase.")
# 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():
#.........这里部分代码省略.........