当前位置: 首页>>代码示例>>Python>>正文


Python constants.ClientFlag类代码示例

本文整理汇总了Python中mysql.connector.constants.ClientFlag的典型用法代码示例。如果您正苦于以下问题:Python ClientFlag类的具体用法?Python ClientFlag怎么用?Python ClientFlag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClientFlag类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_make_changeuser

    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)
开发者ID:allienson,项目名称:LP_trab_python,代码行数:30,代码来源:test_protocol.py

示例2: test_make_changeuser

    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)
开发者ID:David-Turbert,项目名称:mysql-connector-python,代码行数:31,代码来源:test_protocol.py

示例3: test_make_auth

    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)
开发者ID:allienson,项目名称:LP_trab_python,代码行数:59,代码来源:test_protocol.py

示例4: setUp

    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()
开发者ID:pk-codebox-evo,项目名称:mysql-connector-python,代码行数:14,代码来源:test_cext_api.py

示例5: create_connect_args

    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]
开发者ID:Amelandbor,项目名称:CouchPotato,代码行数:20,代码来源:mysqlconnector.py

示例6: create_connect_args

    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]
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:40,代码来源:mysqlconnector.py

示例7: __init__

    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)
开发者ID:hwangsyin,项目名称:cbrc-devteam-blog,代码行数:39,代码来源:connection.py

示例8: create_connect_args

    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]
开发者ID:estuans,项目名称:sqlalchemy,代码行数:23,代码来源:mysqlconnector.py

示例9: test_make_changeuser

    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)
开发者ID:mysql,项目名称:mysql-connector-python,代码行数:37,代码来源:test_protocol.py

示例10: test_make_auth

    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)
开发者ID:David-Turbert,项目名称:mysql-connector-python,代码行数:66,代码来源:test_protocol.py

示例11: test_make_auth

    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)
开发者ID:mysql,项目名称:mysql-connector-python,代码行数:64,代码来源:test_protocol.py

示例12: config

    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():
#.........这里部分代码省略.........
开发者ID:hwangsyin,项目名称:cbrc-devteam-blog,代码行数:101,代码来源:connection.py


注:本文中的mysql.connector.constants.ClientFlag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。