+
    ic]"  c                   s    ^ RI HtHt ^ RIHt . ROtR t ! R	 R]4      t ! R
 R]R7      t	 ! R R]	4      t
 ! R R]	4      t ! R R]4      tR# )i    )ABCMetaabstractmethodget_dbus_name	DBusErrorAbstractErrorRule	ErrorRuleDefaultErrorRuleErrorMapperc                s   a  RV 3R llpV# )ae  Generate a decorator for DBus errors.

Create a function for decorating Python exception classes.
The decorator will add a new rule to the given error mapper
that will map the class to the specified error name.

Definition of the decorator:

.. code-block:: python

    decorator(error_name, namespace=())

The decorator accepts a name of the DBus error and optionally
a namespace of the DBus name. The namespace will be used as
a prefix of the DBus name.

Usage:

.. code-block:: python

    # Create an error mapper.
    error_mapper = ErrorMapper()

    # Create a decorator for DBus errors and use it to map
    # the class ExampleError to the name my.example.Error.
    dbus_error = create_error_decorator(error_mapper)

    @dbus_error("my.example.Error")
    class ExampleError(DBusError):
        pass

:param error_mapper: an error mapper
:return: a decorator
c                 s4   <a  \        . VOS N5!  o VV 3R  lpV# )c                 s@   < SP                  \        V SR 7      4       V # ))exception_type
error_name)add_ruler   )Zclserror_mapperr
   s   &1/usr/lib/python3.14/site-packages/dasbus/error.py	decoratedZ9get_error_decorator.<locals>.decorator.<locals>.decoratedI   s%    !!)"%#  J    r   )r
   Z	namespacer   r   s   f& r   	decoratorZ&get_error_decorator.<locals>.decoratorF   s"    ":I:z:
	 r   ) r   )r   r   s   f r   get_error_decoratorr   #   s    F
 r   c                   s    ] tR t^UtRtRtR# )r   zA default DBus error.r   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   U   s    r   c                   sh   a  ] tR t^Zt o Rt. t]R 4       t]R 4       t]R 4       t	]R 4       t
RtV tR# )r   z=Abstract rule for mapping a Python exception to a DBus error.c                    R# )zzIs this rule matching the given exception type?

:param exception_type: a type of the Python error
:return: True or False
Nr   selfr	      &&r   
match_typeZAbstractErrorRule.match_type_        	r   c                r   )zGet a DBus name for the given exception type.

:param exception_type: a type of the Python error
:return: a name of the DBus error
Nr   r   r   r   get_nameZAbstractErrorRule.get_nameh   r   r   c                r   )zpIs this rule matching the given DBus error?

:param error_name: a name of the DBus error
:return: True or False
Nr   r   r
   r   r   
match_nameZAbstractErrorRule.match_nameq   r   r   c                r   )zGet an exception type of the given DBus error.

param error_name: a name of the DBus error
:return: a type of the Python error
Nr   r    r   r   get_typeZAbstractErrorRule.get_typez   r   r   r   N)r   r   r   r   r   	__slots__r   r   r   r!   r"   r   __classdictcell____classdict__   @r   r   r   Z   s[     GI       r   )Z	metaclassc                   sJ   a  ] tR t^t o RtRR.tR tR tR tR t	R t
R	tV tR
# )r   z4Rule for mapping a Python exception to a DBus error._exception_type_error_namec                    Wn         W n        R# )a  Create a new error rule.

The rule will return the Python type exception_type
for the DBue error error_name.

The rule will return the DBue name error_name for
the Python type exception_type

:param exception_type: a type of the Python error
:param error_name: a name of the DBus error
N)r(   r)   )r   r	   r
      &&&r   __init__ZErrorRule.__init__   s      .%r   c                     V P                   V8H  # )/Is this rule matching the given exception type?r(   r   r   r   r   ZErrorRule.match_type   s    ##~55r   c                    V P                   # z-Get a DBus name for the given exception type.r)   r   r   r   r   ZErrorRule.get_name   s    r   c                r-   )+Is this rule matching the given DBus error?r2   r    r   r   r!   ZErrorRule.match_name   s    :--r   c                r0   z.Get an exception type of the given DBus error.r/   r    r   r   r"   ZErrorRule.get_type   s    ###r   )r)   r(   Nr   r   r   r   r   r#   r,   r   r   r!   r"   r   r$   r%   r'   r   r   r      s5     > 	I
&6 .$ $r   c                   sJ   a  ] tR t^t o RtRR.tR tR tR tR t	R t
R	tV tR
# )r   z<Default rule for mapping a Python exception to a DBus error._default_type_default_namespacec                r*   )aF  Create a new default rule.

The rule will return the Python type default_type
for the all DBus errors.

The rule will generate a DBus name with the prefix
default_namespace for all Python exception types.

:param default_type: a default type of the Python error
:param default_namespace: a default namespace of the DBus error
N)r6   r7   )r   default_typedefault_namespacer+   r   r,   ZDefaultErrorRule.__init__   s     *"3r   c                r   )r.   Tr   r   r   r   r   ZDefaultErrorRule.match_type       r   c                sF    \        . V P                  OVP                  N5!  # r1   )r   r7   r   r   r   r   r   ZDefaultErrorRule.get_name   s!    Od55O~7N7NOOr   c                r   )r3   Tr   r    r   r   r!   ZDefaultErrorRule.match_name   r:   r   c                r0   r4   )r6   r    r   r   r"   ZDefaultErrorRule.get_type   s    !!!r   )r7   r6   Nr5   r%   r'   r   r   r      s6     F 	I
4P" "r   c                   sT   a  ] tR t^t o RtR.tR tV 3R lR ltR tR t	R t
R	tV tR
# )r   z3Class for mapping Python exceptions to DBus errors._error_rulesc                s4    . V n         V P                  4        R# )zCreate a new error mapper.N)r;   reset_rulesr      &r   r,   ZErrorMapper.__init__   s    r   c                s    < V ^8  d   QhRS[ /# )i   rule)r   )formatr&   s   "r   Z__annotate__ZErrorMapper.__annotate__   s     	' 	'. 	'r   c                s<    V P                   P                  V4       R# )zAdd a rule to the error mapper.

The new rule will have a higher priority than
the rules already contained in the error mapper.

:param rule: an error rule
:type rule: an instance of AbstractErrorRule
N)r;   Zappend)r   r?   r   r   r   ZErrorMapper.add_rule   s     	  &r   c                sT    . V n         V P                  \        \        RR7      4       R# )zReset rules in the error mapper.

Reset the error rules to the initial state.
All rules will be replaced with the default ones.
)r8   r9   N)ZnotZknownZError)r;   r   r   r   r=   r>   r   r<   ZErrorMapper.reset_rules   s(      	&"7
 	r   c                s    \        V P                  4       F-  pVP                  V4      '       g   K  VP                  V4      u # 	  \	        RP                  VP                  4      4      h)a  Get a DBus name of the Python exception.

Try to find a matching rule in the error mapper.
If a rule matches the given exception type, use
the rule to get the name of the DBus error.

The rules in the error mapper are processed in
the reversed order to respect the priority of
the rules.

:param exception_type: a type of the Python error
:type exception_type: a subclass of Exception
:return: a name of the DBus error
:raise LookupError: if no name is found
zNo name found for '{}'.)reversedr;   r   r   LookupErrorr@   r   )r   r	   r?      && r   get_error_nameZErrorMapper.get_error_name   sZ      T../D~..}}^44 0 %,,^-D-DE
 	
r   c                s    \        V P                  4       F-  pVP                  V4      '       g   K  VP                  V4      u # 	  \	        RP                  V4      4      h)a  Get a Python exception type of the DBus error.

Try to find a matching rule in the error mapper.
If a rule matches the given name of a DBus error,
use the rule to get the type of a Python exception.

The rules in the error mapper are processed in
the reversed order to respect the priority of
the rules.

:param error_name: a name of the DBus error
:return: a type of the Python exception
:rtype: a subclass of Exception
:raise LookupError: if no type is found
zNo type found for '{}'.)rA   r;   r!   r"   rB   r@   )r   r
   r?   rC   r   get_exception_typeZErrorMapper.get_exception_type  sP      T../Dz**}}Z00 0 3:::FGGr   )r;   N)r   r   r   r   r   r#   r,   r   r<   rD   rE   r   r$   r%   r'   r   r   r      s5     = I
	' 	'
0H Hr   N)r   r   r   r   r   r   )Zabcr    r   Zdasbus.namespacer   Z__all__r   Z	Exceptionr   r   r   r   Zobjectr   r   r   r   <module>rF      s_   * ( */d		 	
'' 'T%$! %$P%"( %"PPH& PHr   