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


Python util.py3k方法代码示例

本文整理汇总了Python中sqlalchemy.util.py3k方法的典型用法代码示例。如果您正苦于以下问题:Python util.py3k方法的具体用法?Python util.py3k怎么用?Python util.py3k使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.util的用法示例。


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

示例1: _expect_warnings

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def _expect_warnings(exc_cls, messages, regex=True, assert_=True,
                     py2konly=False):

    if regex:
        filters = [re.compile(msg, re.I | re.S) for msg in messages]
    else:
        filters = messages

    seen = set(filters)

    real_warn = warnings.warn

    def our_warn(msg, *arg, **kw):
        if isinstance(msg, exc_cls):
            exception = msg
            msg = str(exception)
        elif arg:
            exception = arg[0]
        else:
            exception = None
        if not exception or not issubclass(exception, exc_cls):
            return real_warn(msg, *arg, **kw)

        if not filters:
            return

        for filter_ in filters:
            if (regex and filter_.match(msg)) or \
                    (not regex and filter_ == msg):
                seen.discard(filter_)
                break
        else:
            real_warn(msg, *arg, **kw)

    with mock.patch("warnings.warn", our_warn):
        yield

    if assert_ and (not py2konly or not compat.py3k):
        assert not seen, "Warnings were not seen: %s" % \
            ", ".join("%r" % (s.pattern if regex else s) for s in seen) 
开发者ID:yfauser,项目名称:planespotter,代码行数:42,代码来源:assertions.py

示例2: _expect_warnings

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def _expect_warnings(exc_cls, messages, regex=True, assert_=True,
                     py2konly=False):

    if regex:
        filters = [re.compile(msg, re.I | re.S) for msg in messages]
    else:
        filters = messages

    seen = set(filters)

    real_warn = warnings.warn

    def our_warn(msg, exception, *arg, **kw):
        if not issubclass(exception, exc_cls):
            return real_warn(msg, exception, *arg, **kw)

        if not filters:
            return

        for filter_ in filters:
            if (regex and filter_.match(msg)) or \
                    (not regex and filter_ == msg):
                seen.discard(filter_)
                break
        else:
            real_warn(msg, exception, *arg, **kw)

    with mock.patch("warnings.warn", our_warn):
        yield

    if assert_ and (not py2konly or not compat.py3k):
        assert not seen, "Warnings were not seen: %s" % \
            ", ".join("%r" % (s.pattern if regex else s) for s in seen) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:35,代码来源:assertions.py

示例3: _assert_unorderable_types

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def _assert_unorderable_types(self, callable_):
        if util.py36:
            assert_raises_message(
                TypeError, "not supported between instances of", callable_
            )
        elif util.py3k:
            assert_raises_message(TypeError, "unorderable types", callable_)
        else:
            assert_raises_message(
                TypeError, "cannot compare sets using cmp()", callable_
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:13,代码来源:test_utils.py

示例4: test_tzname

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def test_tzname(self, td, expected):
        if expected == "UTC" and util.py3k and not util.py36:
            expected += "+00:00"
        eq_(timezone(td).tzname(None), expected) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:6,代码来源:test_utils.py

示例5: test_result_large_param

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def test_result_large_param(self):
        import random

        largeparam = "".join(chr(random.randint(52, 85)) for i in range(5000))

        self.eng.echo = "debug"
        result = exec_sql(self.eng, "SELECT ?", (largeparam,))

        row = result.first()

        eq_(
            self.buf.buffer[1].message,
            "[raw sql] ('%s ... (4702 characters truncated) ... %s',)"
            % (largeparam[0:149], largeparam[-149:]),
        )

        if util.py3k:
            eq_(
                self.buf.buffer[3].message,
                "Row ('%s ... (4702 characters truncated) ... %s',)"
                % (largeparam[0:149], largeparam[-149:]),
            )
        else:
            eq_(
                self.buf.buffer[3].message,
                "Row (u'%s ... (4703 characters truncated) ... %s',)"
                % (largeparam[0:148], largeparam[-149:]),
            )

        if util.py3k:
            eq_(
                repr(row),
                "('%s ... (4702 characters truncated) ... %s',)"
                % (largeparam[0:149], largeparam[-149:]),
            )
        else:
            eq_(
                repr(row),
                "(u'%s ... (4703 characters truncated) ... %s',)"
                % (largeparam[0:148], largeparam[-149:]),
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:43,代码来源:test_logging.py

示例6: test_array_of_enums

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def test_array_of_enums(self, array_cls, enum_cls, connection):
        tbl = Table(
            "enum_table",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column(
                "enum_col",
                array_cls(enum_cls("foo", "bar", "baz", name="an_enum")),
            ),
        )

        if util.py3k:
            from enum import Enum

            class MyEnum(Enum):
                a = "aaa"
                b = "bbb"
                c = "ccc"

            tbl.append_column(
                Column("pyenum_col", array_cls(enum_cls(MyEnum)),),
            )

        self.metadata.create_all(connection)

        connection.execute(
            tbl.insert(), [{"enum_col": ["foo"]}, {"enum_col": ["foo", "bar"]}]
        )

        sel = select([tbl.c.enum_col]).order_by(tbl.c.id)
        eq_(
            connection.execute(sel).fetchall(), [(["foo"],), (["foo", "bar"],)]
        )

        if util.py3k:
            connection.execute(tbl.insert(), {"pyenum_col": [MyEnum.a]})
            sel = select([tbl.c.pyenum_col]).order_by(tbl.c.id.desc())
            eq_(connection.scalar(sel), [MyEnum.a]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:40,代码来源:test_types.py

示例7: test_unicode_warnings_typelevel_native_unicode

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def test_unicode_warnings_typelevel_native_unicode(self):

        unicodedata = self.data
        u = Unicode()
        dialect = default.DefaultDialect()
        dialect.supports_unicode_binds = True
        uni = u.dialect_impl(dialect).bind_processor(dialect)
        if util.py3k:
            assert_raises(exc.SAWarning, uni, b"x")
            assert isinstance(uni(unicodedata), str)
        else:
            assert_raises(exc.SAWarning, uni, "x")
            assert isinstance(uni(unicodedata), unicode)  # noqa 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:15,代码来源:test_types.py

示例8: test_savepoint_release_fails_ctxmanager

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def test_savepoint_release_fails_ctxmanager(self, local_connection):
        connection = local_connection
        connection.begin()

        savepoint = [None]

        def go():

            with connection.begin_nested() as sp:
                savepoint[0] = sp
                # force the "commit" of the savepoint that occurs
                # when the "with" block fails, e.g.
                # the RELEASE, to fail, because the savepoint is already
                # released.
                connection.dialect.do_release_savepoint(
                    connection, sp._savepoint
                )

        # prior to SQLAlchemy 1.4, the above release would fail
        # and then the savepoint would try to rollback, and that failed
        # also, causing a long exception chain that under Python 2
        # was particularly hard to diagnose, leading to issue
        # #2696 which eventually impacted Openstack, and we
        # had to add warnings that show what the "context" for an
        # exception was.   The SQL for the exception was
        # ROLLBACK TO SAVEPOINT, and up the exception chain would be
        # the RELEASE failing.
        #
        # now, when the savepoint "commit" fails, it sets itself as
        # inactive.   so it does not try to rollback and it cleans
        # itself out appropriately.
        #

        exc_ = assert_raises_message(
            exc.DBAPIError, r".*SQL\:.*RELEASE SAVEPOINT", go
        )
        savepoint = savepoint[0]
        assert not savepoint.is_active

        if util.py3k:
            # driver error
            assert exc_.__cause__

            # and that's it, no other context
            assert not exc_.__cause__.__context__ 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:47,代码来源:test_transaction.py

示例9: test_legacy_pickle_loads

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [as 别名]
def test_legacy_pickle_loads(self):
        # due to an inconsistency between pickle and copy, we have to change
        # MutableList to implement a __reduce_ex__ method.   Which means we
        # have to make sure all the old pickle formats are still
        # deserializable since these can be used for persistence. these pickles
        # were all generated using a MutableList that has only __getstate__ and
        # __setstate__.

        # f1 = Foo(data=[1, 2])
        # pickles = [
        #    dumps(f1.data)
        #    for loads, dumps in picklers()
        # ]
        # print(repr(pickles))
        # return

        if util.py3k:
            pickles = [
                b"\x80\x04\x95<\x00\x00\x00\x00\x00\x00\x00\x8c\x16"
                b"sqlalchemy.ext.mutable\x94\x8c\x0bMutableList\x94\x93\x94)"
                b"\x81\x94(K\x01K\x02e]\x94(K\x01K\x02eb.",
                b"ccopy_reg\n_reconstructor\np0\n(csqlalchemy.ext.mutable\n"
                b"MutableList\np1\nc__builtin__\nlist\np2\n(lp3\nI1\naI2\n"
                b"atp4\nRp5\n(lp6\nI1\naI2\nab.",
                b"ccopy_reg\n_reconstructor\nq\x00(csqlalchemy.ext.mutable\n"
                b"MutableList\nq\x01c__builtin__\nlist\nq\x02]q\x03(K\x01K"
                b"\x02etq\x04Rq\x05]q\x06(K\x01K\x02eb.",
                b"\x80\x02csqlalchemy.ext.mutable\nMutableList\nq\x00)\x81q"
                b"\x01(K\x01K\x02e]q\x02(K\x01K\x02eb.",
                b"\x80\x03csqlalchemy.ext.mutable\nMutableList\nq\x00)\x81q"
                b"\x01(K\x01K\x02e]q\x02(K\x01K\x02eb.",
                b"\x80\x04\x95<\x00\x00\x00\x00\x00\x00\x00\x8c\x16"
                b"sqlalchemy.ext.mutable\x94\x8c\x0bMutableList\x94\x93\x94)"
                b"\x81\x94(K\x01K\x02e]\x94(K\x01K\x02eb.",
            ]
        else:
            pickles = [
                "\x80\x02csqlalchemy.ext.mutable\nMutableList\nq\x00]q\x01"
                "(K\x01K\x02e\x85q\x02Rq\x03.",
                "\x80\x02csqlalchemy.ext.mutable\nMutableList"
                "\nq\x00]q\x01(K\x01K\x02e\x85q\x02Rq\x03.",
                "csqlalchemy.ext.mutable\nMutableList\np0\n"
                "((lp1\nI1\naI2\natp2\nRp3\n.",
                "csqlalchemy.ext.mutable\nMutableList\nq\x00(]"
                "q\x01(K\x01K\x02etq\x02Rq\x03.",
                "\x80\x02csqlalchemy.ext.mutable\nMutableList"
                "\nq\x01]q\x02(K\x01K\x02e\x85Rq\x03.",
                "\x80\x02csqlalchemy.ext.mutable\nMutableList\n"
                "q\x01]q\x02(K\x01K\x02e\x85Rq\x03.",
                "csqlalchemy.ext.mutable\nMutableList\np1\n"
                "((lp2\nI1\naI2\natRp3\n.",
                "csqlalchemy.ext.mutable\nMutableList\nq\x01"
                "(]q\x02(K\x01K\x02etRq\x03.",
            ]

        for pickle_ in pickles:
            obj = pickle.loads(pickle_)
            eq_(obj, [1, 2])
            assert isinstance(obj, MutableList) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:61,代码来源:test_mutable.py

示例10: assert_compile

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import py3k [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.py3k方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。