GRAYBYTE WORDPRESS FILE MANAGER1324

Server IP : 198.54.121.189 / Your IP : 216.73.216.224
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/cloudlinux/venv/lib/python3.11/site-packages/attr/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/attr//_cmp.py
# SPDX-License-Identifier: MIT


import functools
import types

from ._make import _make_ne


_operation_names = {"eq": "==", "lt": "<", "le": "<=", "gt": ">", "ge": ">="}


def cmp_using(
    eq=None,
    lt=None,
    le=None,
    gt=None,
    ge=None,
    require_same_type=True,
    class_name="Comparable",
):
    """
    Create a class that can be passed into `attrs.field`'s ``eq``, ``order``,
    and ``cmp`` arguments to customize field comparison.

    The resulting class will have a full set of ordering methods if at least
    one of ``{lt, le, gt, ge}`` and ``eq``  are provided.

    :param Optional[callable] eq: `callable` used to evaluate equality of two
        objects.
    :param Optional[callable] lt: `callable` used to evaluate whether one
        object is less than another object.
    :param Optional[callable] le: `callable` used to evaluate whether one
        object is less than or equal to another object.
    :param Optional[callable] gt: `callable` used to evaluate whether one
        object is greater than another object.
    :param Optional[callable] ge: `callable` used to evaluate whether one
        object is greater than or equal to another object.

    :param bool require_same_type: When `True`, equality and ordering methods
        will return `NotImplemented` if objects are not of the same type.

    :param Optional[str] class_name: Name of class. Defaults to 'Comparable'.

    See `comparison` for more details.

    .. versionadded:: 21.1.0
    """

    body = {
        "__slots__": ["value"],
        "__init__": _make_init(),
        "_requirements": [],
        "_is_comparable_to": _is_comparable_to,
    }

    # Add operations.
    num_order_functions = 0
    has_eq_function = False

    if eq is not None:
        has_eq_function = True
        body["__eq__"] = _make_operator("eq", eq)
        body["__ne__"] = _make_ne()

    if lt is not None:
        num_order_functions += 1
        body["__lt__"] = _make_operator("lt", lt)

    if le is not None:
        num_order_functions += 1
        body["__le__"] = _make_operator("le", le)

    if gt is not None:
        num_order_functions += 1
        body["__gt__"] = _make_operator("gt", gt)

    if ge is not None:
        num_order_functions += 1
        body["__ge__"] = _make_operator("ge", ge)

    type_ = types.new_class(
        class_name, (object,), {}, lambda ns: ns.update(body)
    )

    # Add same type requirement.
    if require_same_type:
        type_._requirements.append(_check_same_type)

    # Add total ordering if at least one operation was defined.
    if 0 < num_order_functions < 4:
        if not has_eq_function:
            # functools.total_ordering requires __eq__ to be defined,
            # so raise early error here to keep a nice stack.
            raise ValueError(
                "eq must be define is order to complete ordering from "
                "lt, le, gt, ge."
            )
        type_ = functools.total_ordering(type_)

    return type_


def _make_init():
    """
    Create __init__ method.
    """

    def __init__(self, value):
        """
        Initialize object with *value*.
        """
        self.value = value

    return __init__


def _make_operator(name, func):
    """
    Create operator method.
    """

    def method(self, other):
        if not self._is_comparable_to(other):
            return NotImplemented

        result = func(self.value, other.value)
        if result is NotImplemented:
            return NotImplemented

        return result

    method.__name__ = f"__{name}__"
    method.__doc__ = (
        f"Return a {_operation_names[name]} b.  Computed by attrs."
    )

    return method


def _is_comparable_to(self, other):
    """
    Check whether `other` is comparable to `self`.
    """
    for func in self._requirements:
        if not func(self, other):
            return False
    return True


def _check_same_type(self, other):
    """
    Return True if *self* and *other* are of the same type, False otherwise.
    """
    return other.value.__class__ is self.value.__class__

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
June 25 2025 08:31:36
root / root
0755
__pycache__
--
May 15 2025 08:30:43
root / root
0755
__init__.py
3.165 KB
April 17 2025 13:10:59
root / root
0644
__init__.pyi
17.196 KB
April 17 2025 13:10:59
root / root
0644
_cmp.py
4.002 KB
April 17 2025 13:10:59
root / root
0644
_cmp.pyi
0.39 KB
April 17 2025 13:10:59
root / root
0644
_compat.py
5.667 KB
April 17 2025 13:10:59
root / root
0644
_config.py
0.807 KB
April 17 2025 13:10:59
root / root
0644
_funcs.py
16.338 KB
April 17 2025 13:10:59
root / root
0644
_make.py
94.706 KB
April 17 2025 13:10:59
root / root
0644
_next_gen.py
6.124 KB
April 17 2025 13:10:59
root / root
0644
_typing_compat.pyi
0.458 KB
April 17 2025 13:10:59
root / root
0644
_version_info.py
2.071 KB
April 17 2025 13:10:59
root / root
0644
_version_info.pyi
0.204 KB
April 17 2025 13:10:59
root / root
0644
converters.py
3.518 KB
April 17 2025 13:10:59
root / root
0644
converters.pyi
0.396 KB
April 17 2025 13:10:59
root / root
0644
exceptions.py
1.846 KB
April 17 2025 13:10:59
root / root
0644
exceptions.pyi
0.526 KB
April 17 2025 13:10:59
root / root
0644
filters.py
1.436 KB
April 17 2025 13:10:59
root / root
0644
filters.pyi
0.22 KB
April 17 2025 13:10:59
root / root
0644
py.typed
0 KB
April 17 2025 13:10:59
root / root
0644
setters.py
1.367 KB
April 17 2025 13:10:59
root / root
0644
setters.pyi
0.554 KB
April 17 2025 13:10:59
root / root
0644
validators.py
20.217 KB
April 17 2025 13:10:59
root / root
0644
validators.pyi
2.52 KB
April 17 2025 13:10:59
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF