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


Python sys.py3kwarning方法代码示例

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


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

示例1: test_richcompare_crash

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_richcompare_crash(self):
        # gh-4613
        import operator as op

        # dummy class where __array__ throws exception
        class Foo(object):
            __array_priority__ = 1002

            def __array__(self, *args, **kwargs):
                raise Exception()

        rhs = Foo()
        lhs = np.array(1)
        for f in [op.lt, op.le, op.gt, op.ge]:
            if sys.version_info[0] >= 3:
                assert_raises(TypeError, f, lhs, rhs)
            elif not sys.py3kwarning:
                # With -3 switch in python 2, DeprecationWarning is raised
                # which we are not interested in
                f(lhs, rhs)
        assert_(not op.eq(lhs, rhs))
        assert_(op.ne(lhs, rhs)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_regression.py

示例2: test_main

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_main():
    # Check the doctest cases in doctest itself:
    test_support.run_doctest(doctest, verbosity=True)

    from test import test_doctest

    # Ignore all warnings about the use of class Tester in this module.
    deprecations = []
    if __debug__:
        deprecations.append(("class Tester is deprecated", DeprecationWarning))
    if sys.py3kwarning:
        deprecations += [("backquote not supported", SyntaxWarning),
                         ("execfile.. not supported", DeprecationWarning)]
    with test_support.check_warnings(*deprecations):
        # Check the doctest cases defined here:
        test_support.run_doctest(test_doctest, verbosity=True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_doctest.py

示例3: check_py3k_warnings

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def check_py3k_warnings(*filters, **kwargs):
    """Context manager to silence py3k warnings.

    Accept 2-tuples as positional arguments:
        ("message regexp", WarningCategory)

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default False)

    Without argument, it defaults to:
        check_py3k_warnings(("", DeprecationWarning), quiet=False)
    """
    if sys.py3kwarning:
        if not filters:
            filters = (("", DeprecationWarning),)
    else:
        # It should not raise any py3k warning
        filters = ()
    return _filterwarnings(filters, kwargs.get('quiet')) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:22,代码来源:test_support.py

示例4: test_int_dtypes

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_int_dtypes(self):
        #scramble types and do some mix and match testing
        deprecated_types = [
           'bool_', 'int_', 'intc', 'uint8', 'int8', 'uint64', 'int32', 'uint16',
           'intp', 'int64', 'uint32', 'int16'
            ]
        if sys.version_info[0] < 3 and sys.py3kwarning:
            import operator as op
            dt2 = 'bool_'
            for dt1 in deprecated_types:
                a = np.array([1,2,3], dtype=dt1)
                b = np.array([1,2,3], dtype=dt2)
                self.assert_deprecated(op.div, args=(a,b))
                dt2 = dt1 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_deprecations.py

示例5: test_decode

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_decode(self):
        if sys.version_info[0] >= 3:
            A = np.char.array([b'\\u03a3'])
            assert_(A.decode('unicode-escape')[0] == '\u03a3')
        else:
            with suppress_warnings() as sup:
                if sys.py3kwarning:
                    sup.filter(DeprecationWarning, "'hex_codec'")
                A = np.char.array(['736563726574206d657373616765'])
                assert_(A.decode('hex_codec')[0] == 'secret message') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_defchararray.py

示例6: test_blocked

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_blocked(self):
        # test alignments offsets for simd instructions
        # alignments for vz + 2 * (vs - 1) + 1
        for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]:
            for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt,
                                                            type='binary',
                                                            max_size=sz):
                exp1 = np.ones_like(inp1)
                inp1[...] = np.ones_like(inp1)
                inp2[...] = np.zeros_like(inp2)
                assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg)
                assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg)
                assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg)

                np.add(inp1, inp2, out=out)
                assert_almost_equal(out, exp1, err_msg=msg)

                inp2[...] += np.arange(inp2.size, dtype=dt) + 1
                assert_almost_equal(np.square(inp2),
                                    np.multiply(inp2, inp2),  err_msg=msg)
                # skip true divide for ints
                if dt != np.int32 or (sys.version_info.major < 3 and not sys.py3kwarning):
                    assert_almost_equal(np.reciprocal(inp2),
                                        np.divide(1, inp2),  err_msg=msg)

                inp1[...] = np.ones_like(inp1)
                np.add(inp1, 2, out=out)
                assert_almost_equal(out, exp1 + 2, err_msg=msg)
                inp2[...] = np.ones_like(inp2)
                np.add(2, inp2, out=out)
                assert_almost_equal(out, exp1 + 2, err_msg=msg) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:test_scalarmath.py

示例7: assertItemsEqual

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def assertItemsEqual(self, expected_seq, actual_seq, msg=None):
        """An unordered sequence specific comparison. It asserts that
        actual_seq and expected_seq have the same element counts.
        Equivalent to::

            self.assertEqual(Counter(iter(actual_seq)),
                             Counter(iter(expected_seq)))

        Asserts that each element has the same count in both sequences.
        Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.
        """
        first_seq, second_seq = list(actual_seq), list(expected_seq)
        with warnings.catch_warnings():
            if sys.py3kwarning:
                # Silence Py3k warning raised during the sorting
                for _msg in ["(code|dict|type) inequality comparisons",
                             "builtin_function_or_method order comparisons",
                             "comparing unequal types"]:
                    warnings.filterwarnings("ignore", _msg, DeprecationWarning)
            try:
                first = collections.Counter(first_seq)
                second = collections.Counter(second_seq)
            except TypeError:
                # Handle case with unhashable elements
                differences = _count_diff_all_purpose(first_seq, second_seq)
            else:
                if first == second:
                    return
                differences = _count_diff_hashable(first_seq, second_seq)

        if differences:
            standardMsg = 'Element counts were not equal:\n'
            lines = ['First has %d, Second has %d:  %r' % diff for diff in differences]
            diffMsg = '\n'.join(lines)
            standardMsg = self._truncateMessage(standardMsg, diffMsg)
            msg = self._formatMessage(msg, standardMsg)
            self.fail(msg) 
开发者ID:glmcdona,项目名称:meddle,代码行数:41,代码来源:case.py

示例8: _sorted

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def _sorted(iterable):
    with warnings.catch_warnings():
        if _sys.py3kwarning:
            warnings.filterwarnings("ignore", "comparing unequal types "
                                    "not supported", DeprecationWarning)
        return sorted(iterable) 
开发者ID:glmcdona,项目名称:meddle,代码行数:8,代码来源:pprint.py

示例9: warnpy3k

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def warnpy3k(message, category=None, stacklevel=1):
    """Issue a deprecation warning for Python 3.x related changes.

    Warnings are omitted unless Python is started with the -3 option.
    """
    if sys.py3kwarning:
        if category is None:
            category = DeprecationWarning
        warn(message, category, stacklevel+1) 
开发者ID:glmcdona,项目名称:meddle,代码行数:11,代码来源:warnings.py

示例10: initiate_send

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def initiate_send(self):
        while self.producer_fifo and self.connected:
            first = self.producer_fifo[0]
            # handle empty string/buffer or None entry
            if not first:
                del self.producer_fifo[0]
                if first is None:
                    self.handle_close()
                    return

            # handle classic producer behavior
            obs = self.ac_out_buffer_size
            try:
                with catch_warnings():
                    if py3kwarning:
                        filterwarnings("ignore", ".*buffer", DeprecationWarning)
                    data = buffer(first, 0, obs)
            except TypeError:
                data = first.more()
                if data:
                    self.producer_fifo.appendleft(data)
                else:
                    del self.producer_fifo[0]
                continue

            # send the data
            try:
                num_sent = self.send(data)
            except socket.error:
                self.handle_error()
                return

            if num_sent:
                if num_sent < len(data) or obs < len(first):
                    self.producer_fifo[0] = first[num_sent:]
                else:
                    del self.producer_fifo[0]
            # we tried to send some actual data
            return 
开发者ID:glmcdona,项目名称:meddle,代码行数:41,代码来源:asynchat.py

示例11: assertItemsEqual

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def assertItemsEqual(self, expected_seq, actual_seq, msg=None):
        """An unordered sequence specific comparison. It asserts that
        actual_seq and expected_seq have the same element counts.
        Equivalent to::

            self.assertEqual(Counter(iter(actual_seq)),
                             Counter(iter(expected_seq)))

        Asserts that each element has the same count in both sequences.
        Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.
        """
        first_seq, second_seq = list(expected_seq), list(actual_seq)
        with warnings.catch_warnings():
            if sys.py3kwarning:
                # Silence Py3k warning raised during the sorting
                for _msg in ["(code|dict|type) inequality comparisons",
                             "builtin_function_or_method order comparisons",
                             "comparing unequal types"]:
                    warnings.filterwarnings("ignore", _msg, DeprecationWarning)
            try:
                first = collections.Counter(first_seq)
                second = collections.Counter(second_seq)
            except TypeError:
                # Handle case with unhashable elements
                differences = _count_diff_all_purpose(first_seq, second_seq)
            else:
                if first == second:
                    return
                differences = _count_diff_hashable(first_seq, second_seq)

        if differences:
            standardMsg = 'Element counts were not equal:\n'
            lines = ['First has %d, Second has %d:  %r' % diff for diff in differences]
            diffMsg = '\n'.join(lines)
            standardMsg = self._truncateMessage(standardMsg, diffMsg)
            msg = self._formatMessage(msg, standardMsg)
            self.fail(msg) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:41,代码来源:case.py

示例12: _class_escape

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def _class_escape(source, escape, nested):
    # handle escape code inside character class
    code = ESCAPES.get(escape)
    if code:
        return code
    code = CATEGORIES.get(escape)
    if code and code[0] == IN:
        return code
    try:
        c = escape[1:2]
        if c == "x":
            # hexadecimal escape (exactly two digits)
            while source.next in HEXDIGITS and len(escape) < 4:
                escape = escape + source.get()
            escape = escape[2:]
            if len(escape) != 2:
                raise error, "bogus escape: %s" % repr("\\" + escape)
            return LITERAL, int(escape, 16) & 0xff
        elif c in OCTDIGITS:
            # octal escape (up to three digits)
            while source.next in OCTDIGITS and len(escape) < 4:
                escape = escape + source.get()
            escape = escape[1:]
            return LITERAL, int(escape, 8) & 0xff
        elif c in DIGITS:
            raise error, "bogus escape: %s" % repr(escape)
        if len(escape) == 2:
            if sys.py3kwarning and c in ASCIILETTERS:
                import warnings
                if c in 'Uu':
                    warnings.warn('bad escape %s; Unicode escapes are '
                                  'supported only since Python 3.3' % escape,
                                  FutureWarning, stacklevel=nested + 6)
                else:
                    warnings.warnpy3k('bad escape %s' % escape,
                                      DeprecationWarning, stacklevel=nested + 6)
            return LITERAL, ord(escape[1])
    except ValueError:
        pass
    raise error, "bogus escape: %s" % repr(escape) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:42,代码来源:sre_parse.py

示例13: parse

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def parse(str, flags=0, pattern=None):
    # parse 're' pattern into list of (opcode, argument) tuples

    source = Tokenizer(str)

    if pattern is None:
        pattern = Pattern()
    pattern.flags = flags
    pattern.str = str

    p = _parse_sub(source, pattern, 0)
    if (sys.py3kwarning and
        (p.pattern.flags & SRE_FLAG_LOCALE) and
        (p.pattern.flags & SRE_FLAG_UNICODE)):
        import warnings
        warnings.warnpy3k("LOCALE and UNICODE flags are incompatible",
                          DeprecationWarning, stacklevel=5)

    tail = source.get()
    if tail == ")":
        raise error, "unbalanced parenthesis"
    elif tail:
        raise error, "bogus characters at end of regular expression"

    if not (flags & SRE_FLAG_VERBOSE) and p.pattern.flags & SRE_FLAG_VERBOSE:
        # the VERBOSE flag was switched on inside the pattern.  to be
        # on the safe side, we'll parse the whole thing again...
        return parse(str, p.pattern.flags)

    if flags & SRE_FLAG_DEBUG:
        p.dump()

    return p 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:sre_parse.py

示例14: test_main

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_main():
    deprecations = [(r'complex divmod\(\), // and % are deprecated$',
                     DeprecationWarning)]
    if sys.py3kwarning:
        deprecations += [
            ("classic (int|long) division", DeprecationWarning),
            ("coerce.. not supported", DeprecationWarning),
            (".+__(get|set|del)slice__ has been removed", DeprecationWarning)]
    with test_support.check_warnings(*deprecations):
        # Run all local test cases, with PTypesLongInitTest first.
        test_support.run_unittest(PTypesLongInitTest, OperatorsTest,
                                  ClassPropertiesAndMethods, DictProxyTests,
                                  PicklingTests) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_descr.py

示例15: test_yield_in_comprehensions

# 需要导入模块: import sys [as 别名]
# 或者: from sys import py3kwarning [as 别名]
def test_yield_in_comprehensions(self):
        # Check yield in comprehensions
        def g(): [x for x in [(yield 1)]]

        def check(code, warntext):
            with check_py3k_warnings((warntext, DeprecationWarning)):
                compile(code, '<test string>', 'exec')
            if sys.py3kwarning:
                with warnings.catch_warnings():
                    warnings.filterwarnings('error', category=DeprecationWarning)
                    with self.assertRaises(SyntaxError) as cm:
                        compile(code, '<test string>', 'exec')
                    self.assertIn(warntext, str(cm.exception))

        check("def g(): [(yield x) for x in ()]",
              "'yield' inside list comprehension")
        check("def g(): [x for x in () if not (yield x)]",
              "'yield' inside list comprehension")
        check("def g(): [y for x in () for y in [(yield x)]]",
              "'yield' inside list comprehension")
        check("def g(): {(yield x) for x in ()}",
              "'yield' inside set comprehension")
        check("def g(): {(yield x): x for x in ()}",
              "'yield' inside dict comprehension")
        check("def g(): {x: (yield x) for x in ()}",
              "'yield' inside dict comprehension")
        check("def g(): ((yield x) for x in ())",
              "'yield' inside generator expression")
        with check_py3k_warnings(("'yield' inside list comprehension",
                                  DeprecationWarning)):
            check_syntax_error(self, "class C: [(yield x) for x in ()]")
        check("class C: ((yield x) for x in ())",
              "'yield' inside generator expression")
        with check_py3k_warnings(("'yield' inside list comprehension",
                                  DeprecationWarning)):
            check_syntax_error(self, "[(yield x) for x in ()]")
        check("((yield x) for x in ())",
              "'yield' inside generator expression") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:40,代码来源:test_grammar.py


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