當前位置: 首頁>>代碼示例>>Python>>正文


Python util.string_types方法代碼示例

本文整理匯總了Python中sqlalchemy.util.string_types方法的典型用法代碼示例。如果您正苦於以下問題:Python util.string_types方法的具體用法?Python util.string_types怎麽用?Python util.string_types使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.util的用法示例。


在下文中一共展示了util.string_types方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: emits_warning_on

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def emits_warning_on(db, *warnings):
    """Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().
    """
    spec = db_spec(db)

    @decorator
    def decorate(fn, *args, **kw):
        if isinstance(db, util.string_types):
            if not spec(config._current):
                return fn(*args, **kw)
            else:
                wrapped = emits_warning(*warnings)(fn)
                return wrapped(*args, **kw)
        else:
            if not _is_excluded(*db):
                return fn(*args, **kw)
            else:
                wrapped = emits_warning(*warnings)(fn)
                return wrapped(*args, **kw)
    return decorate 
開發者ID:gltn,項目名稱:stdm,代碼行數:26,代碼來源:assertions.py

示例2: expect_warnings_on

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def expect_warnings_on(db, *messages, **kw):
    """Context manager which expects one or more warnings on specific
    dialects.

    The expect version **asserts** that the warnings were in fact seen.

    """
    spec = db_spec(db)

    if isinstance(db, util.string_types) and not spec(config._current):
        yield
    else:
        with expect_warnings(*messages, **kw):
            yield 
開發者ID:jpush,項目名稱:jbox,代碼行數:16,代碼來源:assertions.py

示例3: as_predicate

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def as_predicate(cls, predicate, description=None):
        if isinstance(predicate, compound):
            return cls.as_predicate(predicate.enabled_for_config, description)
        elif isinstance(predicate, Predicate):
            if description and predicate.description is None:
                predicate.description = description
            return predicate
        elif isinstance(predicate, (list, set)):
            return OrPredicate(
                [cls.as_predicate(pred) for pred in predicate], description
            )
        elif isinstance(predicate, tuple):
            return SpecPredicate(*predicate)
        elif isinstance(predicate, sqla_util.string_types):
            tokens = re.match(
                r"([\+\w]+)\s*(?:(>=|==|!=|<=|<|>)\s*([\d\.]+))?", predicate
            )
            if not tokens:
                raise ValueError(
                    "Couldn't locate DB name in predicate: %r" % predicate
                )
            db = tokens.group(1)
            op = tokens.group(2)
            spec = (
                tuple(int(d) for d in tokens.group(3).split("."))
                if tokens.group(3)
                else None
            )

            return SpecPredicate(db, op, spec, description=description)
        elif callable(predicate):
            return LambdaPredicate(predicate, description)
        else:
            assert False, "unknown predicate type: %s" % predicate 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:36,代碼來源:exclusions.py

示例4: test_native_datetime

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def test_native_datetime(self):
        dbapi = testing.db.dialect.dbapi
        connect_args = {
            "detect_types": dbapi.PARSE_DECLTYPES | dbapi.PARSE_COLNAMES
        }
        engine = engines.testing_engine(
            options={"connect_args": connect_args, "native_datetime": True}
        )
        t = Table(
            "datetest",
            MetaData(),
            Column("id", Integer, primary_key=True),
            Column("d1", Date),
            Column("d2", sqltypes.TIMESTAMP),
        )
        t.create(engine)
        try:
            with engine.begin() as conn:
                conn.execute(
                    t.insert(),
                    {
                        "d1": datetime.date(2010, 5, 10),
                        "d2": datetime.datetime(2010, 5, 10, 12, 15, 25),
                    },
                )
                row = conn.execute(t.select()).first()
                eq_(
                    row,
                    (
                        1,
                        datetime.date(2010, 5, 10),
                        datetime.datetime(2010, 5, 10, 12, 15, 25),
                    ),
                )
                r = conn.execute(func.current_date()).scalar()
                assert isinstance(r, util.string_types)
        finally:
            t.drop(engine)
            engine.dispose() 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:41,代碼來源:test_sqlite.py

示例5: test_output_type_handler

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def test_output_type_handler(self):
        with self.engine.connect() as conn:
            for stmt, exp, kw in [
                ("SELECT 0.1 FROM DUAL", decimal.Decimal("0.1"), {}),
                ("SELECT CAST(15 AS INTEGER) FROM DUAL", 15, {}),
                (
                    "SELECT CAST(15 AS NUMERIC(3, 1)) FROM DUAL",
                    decimal.Decimal("15"),
                    {},
                ),
                (
                    "SELECT CAST(0.1 AS NUMERIC(5, 2)) FROM DUAL",
                    decimal.Decimal("0.1"),
                    {},
                ),
                (
                    "SELECT :num FROM DUAL",
                    decimal.Decimal("2.5"),
                    {"num": decimal.Decimal("2.5")},
                ),
                (
                    text(
                        "SELECT CAST(28.532 AS NUMERIC(5, 3)) "
                        "AS val FROM DUAL"
                    ).columns(val=Numeric(5, 3, asdecimal=True)),
                    decimal.Decimal("28.532"),
                    {},
                ),
            ]:
                if isinstance(stmt, util.string_types):
                    test_exp = conn.exec_driver_sql(stmt, kw).scalar()
                else:
                    test_exp = conn.scalar(stmt, **kw)
                eq_(test_exp, exp)
                assert type(test_exp) is type(exp) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:37,代碼來源:test_types.py

示例6: test_query_returned_as_text

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def test_query_returned_as_text(self, connection):
        engine = testing.db
        self._fixture_data(engine)
        data_table = self.tables.data_table
        result = connection.execute(
            select([data_table.c.data["k1"].astext])
        ).first()
        if engine.dialect.returns_unicode_strings:
            assert isinstance(result[0], util.text_type)
        else:
            assert isinstance(result[0], util.string_types) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:13,代碼來源:test_types.py

示例7: create_connect_args

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def create_connect_args(self, url):
        dialect_opts = dict(url.query)
        for opt in ('use_ansi', 'auto_setinputsizes', 'auto_convert_lobs',
                    'threaded', 'allow_twophase'):
            if opt in dialect_opts:
                util.coerce_kw_type(dialect_opts, opt, bool)
                setattr(self, opt, dialect_opts[opt])

        database = url.database
        service_name = dialect_opts.get('service_name', None)
        if database or service_name:
            # if we have a database, then we have a remote host
            port = url.port
            if port:
                port = int(port)
            else:
                port = 1521

            if database and service_name:
                raise exc.InvalidRequestError(
                    '"service_name" option shouldn\'t '
                    'be used with a "database" part of the url')
            if database:
                makedsn_kwargs = {'sid': database}
            if service_name:
                makedsn_kwargs = {'service_name': service_name}

            dsn = self.dbapi.makedsn(url.host, port, **makedsn_kwargs)
        else:
            # we have a local tnsname
            dsn = url.host

        opts = dict(
            user=url.username,
            password=url.password,
            dsn=dsn,
            threaded=self.threaded,
            twophase=self.allow_twophase,
        )

        if util.py2k:
            if self._cx_oracle_with_unicode:
                for k, v in opts.items():
                    if isinstance(v, str):
                        opts[k] = unicode(v)
            else:
                for k, v in opts.items():
                    if isinstance(v, unicode):
                        opts[k] = str(v)

        if 'mode' in url.query:
            opts['mode'] = url.query['mode']
            if isinstance(opts['mode'], util.string_types):
                mode = opts['mode'].upper()
                if mode == 'SYSDBA':
                    opts['mode'] = self.dbapi.SYSDBA
                elif mode == 'SYSOPER':
                    opts['mode'] = self.dbapi.SYSOPER
                else:
                    util.coerce_kw_type(opts, 'mode', int)
        return ([], opts) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:63,代碼來源:cx_oracle.py

示例8: create_connect_args

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def create_connect_args(self, url):
        dialect_opts = dict(url.query)

        for opt in ('use_ansi', 'auto_setinputsizes', 'auto_convert_lobs',
                    'threaded', 'allow_twophase'):
            if opt in dialect_opts:
                util.coerce_kw_type(dialect_opts, opt, bool)
                setattr(self, opt, dialect_opts[opt])

        database = url.database
        service_name = dialect_opts.get('service_name', None)
        if database or service_name:
            # if we have a database, then we have a remote host
            port = url.port
            if port:
                port = int(port)
            else:
                port = 1521

            if database and service_name:
                raise exc.InvalidRequestError(
                    '"service_name" option shouldn\'t '
                    'be used with a "database" part of the url')
            if database:
                makedsn_kwargs = {'sid': database}
            if service_name:
                makedsn_kwargs = {'service_name': service_name}

            dsn = self.dbapi.makedsn(url.host, port, **makedsn_kwargs)
        else:
            # we have a local tnsname
            dsn = url.host

        opts = dict(
            threaded=self.threaded,
        )

        if dsn is not None:
            opts['dsn'] = dsn
        if url.password is not None:
            opts['password'] = url.password
        if url.username is not None:
            opts['user'] = url.username

        if 'mode' in url.query:
            opts['mode'] = url.query['mode']
            if isinstance(opts['mode'], util.string_types):
                mode = opts['mode'].upper()
                if mode == 'SYSDBA':
                    opts['mode'] = self.dbapi.SYSDBA
                elif mode == 'SYSOPER':
                    opts['mode'] = self.dbapi.SYSOPER
                else:
                    util.coerce_kw_type(opts, 'mode', int)
        return ([], opts) 
開發者ID:yfauser,項目名稱:planespotter,代碼行數:57,代碼來源:cx_oracle.py

示例9: create_connect_args

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def create_connect_args(self, url):
        dialect_opts = dict(url.query)
        for opt in ('use_ansi', 'auto_setinputsizes', 'auto_convert_lobs',
                    'threaded', 'allow_twophase'):
            if opt in dialect_opts:
                util.coerce_kw_type(dialect_opts, opt, bool)
                setattr(self, opt, dialect_opts[opt])

        if url.database:
            # if we have a database, then we have a remote host
            port = url.port
            if port:
                port = int(port)
            else:
                port = 1521
            dsn = self.dbapi.makedsn(url.host, port, url.database)
        else:
            # we have a local tnsname
            dsn = url.host

        opts = dict(
            user=url.username,
            password=url.password,
            dsn=dsn,
            threaded=self.threaded,
            twophase=self.allow_twophase,
        )

        if util.py2k:
            if self._cx_oracle_with_unicode:
                for k, v in opts.items():
                    if isinstance(v, str):
                        opts[k] = unicode(v)
            else:
                for k, v in opts.items():
                    if isinstance(v, unicode):
                        opts[k] = str(v)

        if 'mode' in url.query:
            opts['mode'] = url.query['mode']
            if isinstance(opts['mode'], util.string_types):
                mode = opts['mode'].upper()
                if mode == 'SYSDBA':
                    opts['mode'] = self.dbapi.SYSDBA
                elif mode == 'SYSOPER':
                    opts['mode'] = self.dbapi.SYSOPER
                else:
                    util.coerce_kw_type(opts, 'mode', int)
        return ([], opts) 
開發者ID:gltn,項目名稱:stdm,代碼行數:51,代碼來源:cx_oracle.py

示例10: create_connect_args

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def create_connect_args(self, url):
        dialect_opts = dict(url.query)
        for opt in ('use_ansi', 'auto_setinputsizes', 'auto_convert_lobs',
                    'threaded', 'allow_twophase'):
            if opt in dialect_opts:
                util.coerce_kw_type(dialect_opts, opt, bool)
                setattr(self, opt, dialect_opts[opt])

        if url.database:
            # if we have a database, then we have a remote host
            port = url.port
            if port:
                port = int(port)
            else:
                port = 1521
            dsn = self.dbapi.makedsn(url.host, port, url.database)
        else:
            # we have a local tnsname
            dsn = url.host

        opts = dict(
            user=url.username,
            password=url.password,
            dsn=dsn,
            threaded=self.threaded,
            twophase=self.allow_twophase,
            )

        if util.py2k:
            if self._cx_oracle_with_unicode:
                for k, v in opts.items():
                    if isinstance(v, str):
                        opts[k] = unicode(v)
            else:
                for k, v in opts.items():
                    if isinstance(v, unicode):
                        opts[k] = str(v)

        if 'mode' in url.query:
            opts['mode'] = url.query['mode']
            if isinstance(opts['mode'], util.string_types):
                mode = opts['mode'].upper()
                if mode == 'SYSDBA':
                    opts['mode'] = self.dbapi.SYSDBA
                elif mode == 'SYSOPER':
                    opts['mode'] = self.dbapi.SYSOPER
                else:
                    util.coerce_kw_type(opts, 'mode', int)
        return ([], opts) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:51,代碼來源:cx_oracle.py

示例11: assert_compile

# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import string_types [as 別名]
def assert_compile(self, clause, result, params=None,
                        checkparams=None, dialect=None,
                        checkpositional=None,
                        use_default_dialect=False,
                        allow_dialect_select=False,
                        literal_binds=False):
        if use_default_dialect:
            dialect = default.DefaultDialect()
        elif allow_dialect_select:
            dialect = None
        else:
            if dialect is None:
                dialect = getattr(self, '__dialect__', None)

            if dialect is None:
                dialect = config.db.dialect
            elif dialect == 'default':
                dialect = default.DefaultDialect()
            elif isinstance(dialect, util.string_types):
                dialect = url.URL(dialect).get_dialect()()


        kw = {}
        compile_kwargs = {}

        if params is not None:
            kw['column_keys'] = list(params)

        if literal_binds:
            compile_kwargs['literal_binds'] = True

        if isinstance(clause, orm.Query):
            context = clause._compile_context()
            context.statement.use_labels = True
            clause = context.statement

        if compile_kwargs:
            kw['compile_kwargs'] = compile_kwargs

        c = clause.compile(dialect=dialect, **kw)

        param_str = repr(getattr(c, 'params', {}))

        if util.py3k:
            param_str = param_str.encode('utf-8').decode('ascii', 'ignore')
            print(("\nSQL String:\n" + util.text_type(c) + param_str).encode('utf-8'))
        else:
            print("\nSQL String:\n" + util.text_type(c).encode('utf-8') + param_str)


        cc = re.sub(r'[\n\t]', '', util.text_type(c))

        eq_(cc, result, "%r != %r on dialect %r" % (cc, result, dialect))

        if checkparams is not None:
            eq_(c.construct_params(params), checkparams)
        if checkpositional is not None:
            p = c.construct_params(params)
            eq_(tuple([p[x] for x in c.positiontup]), checkpositional) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:61,代碼來源:assertions.py


注:本文中的sqlalchemy.util.string_types方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。