File: //usr/local/lib/python3.9/site-packages/celery/utils/__pycache__/objects.cpython-39.pyc
a
X>hw � @ sL d Z ddlmZ dZG dd� d�Zd
dd�ZG d d
� d
�ZG dd� d�ZdS )z7Object related utilities, including introspection, etc.� )�reduce)�Bunch�FallbackContext�getitem_property�
mro_lookupc @ s e Zd ZdZdd� ZdS )r z-Object that enables you to modify attributes.c K s | j �|� d S �N)�__dict__�update)�self�kwargs� r �>/usr/local/lib/python3.9/site-packages/celery/utils/objects.py�__init__
s zBunch.__init__N)�__name__�
__module__�__qualname__�__doc__r r r r r
r s r Nc
C s� |s
t � n|}|sg n|}| �� D ]`}||v rpz|j| }|j}W n ttfyX Y n0 ||vrj| S dS ||jv r"| S q"dS )a Return the first node by MRO order that defines an attribute.
Arguments:
cls (Any): Child class to traverse.
attr (str): Name of attribute to find.
stop (Set[Any]): A set of types that if reached will stop
the search.
monkey_patched (Sequence): Use one of the stop classes
if the attributes module origin isn't in this list.
Used to detect monkey patched attributes.
Returns:
Any: The attribute value, or :const:`None` if not found.
N)�set�mror r �AttributeError�KeyError)�cls�attr�stopZmonkey_patched�node�valueZ
module_originr r r
r s
r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) r a� Context workaround.
The built-in ``@contextmanager`` utility does not work well
when wrapping other contexts, as the traceback is wrong when
the wrapped context raises.
This solves this problem and can be used instead of ``@contextmanager``
in this example::
@contextmanager
def connection_or_default_connection(connection=None):
if connection:
# user already has a connection, shouldn't close
# after use
yield connection
else:
# must've new connection, and also close the connection
# after the block returns
with create_new_connection() as connection:
yield connection
This wrapper can be used instead for the above like this::
def connection_or_default_connection(connection=None):
return FallbackContext(connection, create_new_connection)
c O s"