[ Avaa Bypassed ]




Upload:

Command:

www-data@18.227.161.207: ~ $
# This file is part of cloud-init. See LICENSE file for license information.
import collections
import functools
import logging
from typing import NamedTuple, Optional

from cloudinit import features
from cloudinit.log import loggers

LOG = logging.getLogger(__name__)


class DeprecationLog(NamedTuple):
    log_level: int
    message: str


@functools.total_ordering
class Version(
    collections.namedtuple("Version", ["major", "minor", "patch", "rev"])
):
    """A class for comparing versions.

    Implemented as a named tuple with all ordering methods. Comparisons
    between X.Y.N and X.Y always treats the more specific number as larger.

    :param major: the most significant number in a version
    :param minor: next greatest significant number after major
    :param patch: next greatest significant number after minor
    :param rev: the least significant number in a version

    :raises TypeError: If invalid arguments are given.
    :raises ValueError: If invalid arguments are given.

    Examples:
        >>> Version(2, 9) == Version.from_str("2.9")
        True
        >>> Version(2, 9, 1) > Version.from_str("2.9.1")
        False
        >>> Version(3, 10) > Version.from_str("3.9.9.9")
        True
        >>> Version(3, 7) >= Version.from_str("3.7")
        True

    """

    def __new__(
        cls, major: int = -1, minor: int = -1, patch: int = -1, rev: int = -1
    ) -> "Version":
        """Default of -1 allows us to tiebreak in favor of the most specific
        number"""
        return super(Version, cls).__new__(cls, major, minor, patch, rev)

    @classmethod
    def from_str(cls, version: str) -> "Version":
        """Create a Version object from a string.

        :param version: A period-delimited version string, max 4 segments.

        :raises TypeError: Raised if invalid arguments are given.
        :raises ValueError: Raised if invalid arguments are given.

        :return: A Version object.
        """
        return cls(*(list(map(int, version.split(".")))))

    def __gt__(self, other):
        return 1 == self._compare_version(other)

    def __eq__(self, other):
        return (
            self.major == other.major
            and self.minor == other.minor
            and self.patch == other.patch
            and self.rev == other.rev
        )

    def __iter__(self):
        """Iterate over the version (drop sentinels)"""
        for n in (self.major, self.minor, self.patch, self.rev):
            if n != -1:
                yield str(n)
            else:
                break

    def __str__(self):
        return ".".join(self)

    def __hash__(self):
        return hash(str(self))

    def _compare_version(self, other: "Version") -> int:
        """Compare this Version to another.

        :param other: A Version object.

        :return: -1 if self > other, 1 if self < other, else 0
        """
        if self == other:
            return 0
        if self.major > other.major:
            return 1
        if self.minor > other.minor:
            return 1
        if self.patch > other.patch:
            return 1
        if self.rev > other.rev:
            return 1
        return -1


def should_log_deprecation(version: str, boundary_version: str) -> bool:
    """Determine if a deprecation message should be logged.

    :param version: The version in which the thing was deprecated.
    :param boundary_version: The version at which deprecation level is logged.

    :return: True if the message should be logged, else False.
    """
    return boundary_version == "devel" or Version.from_str(
        version
    ) <= Version.from_str(boundary_version)


def log_with_downgradable_level(
    *,
    logger: logging.Logger,
    version: str,
    requested_level: int,
    msg: str,
    args,
):
    """Log a message at the requested level, if that is acceptable.

    If the log level is too high due to the version boundary, log at DEBUG
    level. Useful to add new warnings to previously unguarded code without
    disrupting stable downstreams.

    :param logger: Logger object to log with
    :param version: Version string of the version that this log was introduced
    :param level: Preferred level at which this message should be logged
    :param msg: Message, as passed to the logger.
    :param args: Message formatting args, as passed to the logger

    :return: True if the message should be logged, else False.
    """
    if should_log_deprecation(version, features.DEPRECATION_INFO_BOUNDARY):
        logger.log(requested_level, msg, args)
    else:
        logger.debug(msg, args)


def deprecate(
    *,
    deprecated: str,
    deprecated_version: str,
    extra_message: Optional[str] = None,
    schedule: int = 5,
    skip_log: bool = False,
) -> DeprecationLog:
    """Mark a "thing" as deprecated. Deduplicated deprecations are
    logged.

    :param deprecated: Noun to be deprecated. Write this as the start
        of a sentence, with no period. Version and extra message will
        be appended.
    :param deprecated_version: The version in which the thing was
        deprecated
    :param extra_message: A remedy for the user's problem. A good
        message will be actionable and specific (i.e., don't use a
        generic "Use updated key." if the user used a deprecated key).
        End the string with a period.
    :param schedule: Manually set the deprecation schedule. Defaults to
        5 years. Leave a comment explaining your reason for deviation if
        setting this value.
    :param skip_log: Return log text rather than logging it. Useful for
        running prior to logging setup.
    :return: NamedTuple containing log level and log message
        DeprecationLog(level: int, message: str)

    Note: uses keyword-only arguments to improve legibility
    """
    if not hasattr(deprecate, "log"):
        setattr(deprecate, "log", set())
    message = extra_message or ""
    dedup = hash(deprecated + message + deprecated_version + str(schedule))
    version = Version.from_str(deprecated_version)
    version_removed = Version(version.major + schedule, version.minor)
    deprecate_msg = (
        f"{deprecated} is deprecated in "
        f"{deprecated_version} and scheduled to be removed in "
        f"{version_removed}. {message}"
    ).rstrip()
    if not should_log_deprecation(
        deprecated_version, features.DEPRECATION_INFO_BOUNDARY
    ):
        level = logging.INFO
    elif hasattr(LOG, "deprecated"):
        level = loggers.DEPRECATED
    else:
        level = logging.WARN
    log_cache = getattr(deprecate, "log")
    if not skip_log and dedup not in log_cache:
        log_cache.add(dedup)
        LOG.log(level, deprecate_msg)
    return DeprecationLog(level, deprecate_msg)


def deprecate_call(
    *, deprecated_version: str, extra_message: str, schedule: int = 5
):
    """Mark a "thing" as deprecated. Deduplicated deprecations are
    logged.

    :param deprecated_version: The version in which the thing was
        deprecated
    :param extra_message: A remedy for the user's problem. A good
        message will be actionable and specific (i.e., don't use a
        generic "Use updated key." if the user used a deprecated key).
        End the string with a period.
    :param schedule: Manually set the deprecation schedule. Defaults to
        5 years. Leave a comment explaining your reason for deviation if
        setting this value.

    Note: uses keyword-only arguments to improve legibility
    """

    def wrapper(func):
        @functools.wraps(func)
        def decorator(*args, **kwargs):
            # don't log message multiple times
            out = func(*args, **kwargs)
            deprecate(
                deprecated_version=deprecated_version,
                deprecated=func.__name__,
                extra_message=extra_message,
                schedule=schedule,
            )
            return out

        return decorator

    return wrapper

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
analyze Folder 0755
cmd Folder 0755
config Folder 0755
distros Folder 0755
filters Folder 0755
handlers Folder 0755
log Folder 0755
mergers Folder 0755
net Folder 0755
reporting Folder 0755
sources Folder 0755
__init__.py File 0 B 0644
apport.py File 8.27 KB 0644
atomic_helper.py File 2.79 KB 0644
cloud.py File 3.22 KB 0644
dmi.py File 7.86 KB 0644
event.py File 2 KB 0644
features.py File 4.87 KB 0644
gpg.py File 7.99 KB 0644
helpers.py File 16.16 KB 0644
importer.py File 2.43 KB 0644
lifecycle.py File 7.78 KB 0644
netinfo.py File 24.02 KB 0644
performance.py File 3.1 KB 0644
persistence.py File 2.52 KB 0644
registry.py File 1022 B 0644
safeyaml.py File 10.11 KB 0644
settings.py File 2.12 KB 0644
signal_handler.py File 1.75 KB 0644
simpletable.py File 1.93 KB 0644
socket.py File 5.93 KB 0644
ssh_util.py File 22.22 KB 0644
stages.py File 41.53 KB 0644
subp.py File 12.36 KB 0644
temp_utils.py File 2.94 KB 0644
templater.py File 7.8 KB 0644
type_utils.py File 703 B 0644
url_helper.py File 34.7 KB 0644
user_data.py File 14.44 KB 0644
util.py File 90.43 KB 0644
version.py File 564 B 0644
warnings.py File 3.76 KB 0644