示例#1
0
    def test_immutable_type_with_mutable_base(self):
        # Add deprecation warning here so it's removed in 3.14
        warnings._deprecated('creating immutable classes with mutable bases',
                             remove=(3, 14))

        class MutableBase:
            def meth(self):
                return 'original'

        with self.assertWarns(DeprecationWarning):
            ImmutableSubclass = _testcapi.make_immutable_type_with_base(
                MutableBase)
        instance = ImmutableSubclass()

        self.assertEqual(instance.meth(), 'original')

        # Cannot override the static type's method
        with self.assertRaisesRegex(
                TypeError, "cannot set 'meth' attribute of immutable type"):
            ImmutableSubclass.meth = lambda self: 'overridden'
        self.assertEqual(instance.meth(), 'original')

        # Can change the method on the mutable base
        MutableBase.meth = lambda self: 'changed'
        self.assertEqual(instance.meth(), 'changed')
示例#2
0
文件: abc.py 项目: nirs/cpython
def __getattr__(name):
    """
    For backwards compatibility, continue to make names
    from _resources_abc available through this module. #93963
    """
    if name in _resources_abc.__all__:
        obj = getattr(_resources_abc, name)
        warnings._deprecated(f"{__name__}.{name}", remove=(3, 14))
        globals()[name] = obj
        return obj
    raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
示例#3
0
The close() method is called automatically when the class instance
is destroyed.

When a file is opened with the extension '.aiff', an AIFF file is
written, otherwise an AIFF-C file is written.  This default can be
changed by calling aiff() or aifc() before the first writeframes or
writeframesraw.
"""

import struct
import builtins
import warnings

__all__ = ["Error", "open"]

warnings._deprecated(__name__, remove=(3, 13))


class Error(Exception):
    pass


_AIFC_version = 0xA2805140  # Version 1 of AIFF-C


def _read_long(file):
    try:
        return struct.unpack('>l', file.read(4))[0]
    except struct.error:
        raise EOFError from None
示例#4
0
import getopt
import time
import socket
import collections
from warnings import _deprecated, warn
from email._header_value_parser import get_addr_spec, get_angle_addr

__all__ = [
    "SMTPChannel", "SMTPServer", "DebuggingServer", "PureProxy",
]

_DEPRECATION_MSG = ('The {name} module is deprecated and unmaintained and will '
                    'be removed in Python {remove}.  Please see aiosmtpd '
                    '(https://aiosmtpd.readthedocs.io/) for the recommended '
                    'replacement.')
_deprecated(__name__, _DEPRECATION_MSG, remove=(3, 12))


# These are imported after the above warning so that users get the correct
# deprecation warning.
import asyncore
import asynchat


program = sys.argv[0]
__version__ = 'Python SMTP proxy version 0.3'


class Devnull:
    def write(self, msg): pass
    def flush(self): pass
示例#5
0
"""Mailcap file handling.  See RFC 1524."""

import os
import warnings
import re

__all__ = ["getcaps", "findmatch"]

_DEPRECATION_MSG = ('The {name} module is deprecated and will be removed in '
                    'Python {remove}. See the mimetypes module for an '
                    'alternative.')
warnings._deprecated(__name__, _DEPRECATION_MSG, remove=(3, 13))


def lineno_sort_key(entry):
    # Sort in ascending order, with unspecified entries at the end
    if 'lineno' in entry:
        return 0, entry['lineno']
    else:
        return 1, 0


_find_unsafe = re.compile(r'[^\xa1-\U0010FFFF\w@+=:,./-]').search


class UnsafeMailcapInput(Warning):
    """Warning raised when refusing unsafe input"""


# Part 1: top-level interface.