a F `]"@sddlmZmZddlmZgdZddZGdddeZGdd d ed Z Gd d d e Z Gd dde Z Gddde Z dS))ABCMetaabstractmethod get_dbus_name)get_error_decorator DBusErrorAbstractErrorRule ErrorRuleDefaultErrorRule ErrorMappercsdfdd }|S)aGenerate 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 cs$tg|Rfdd}|S)Ncst|d|S)N)exception_type error_name)add_ruler )cls) error_mapperrr 0/usr/lib/python3.9/site-packages/dasbus/error.py decoratedIs z9get_error_decorator..decorator..decoratedr)r namespacerr)rr decoratorFsz&get_error_decorator..decorator)r r )rrr rrr#s# rc@seZdZdZdS)rzA default DBus error.N)__name__ __module__ __qualname____doc__r r r rrUsrc@sDeZdZdZgZeddZeddZeddZedd Z d S) rz=Abstract rule for mapping a Python exception to a DBus error.cCsdS)zIs this rule matching the given exception type? :param exception_type: a type of the Python error :return: True or False Nr selfr r r r match_type_szAbstractErrorRule.match_typecCsdS)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 rr r rget_namehszAbstractErrorRule.get_namecCsdS)zIs this rule matching the given DBus error? :param error_name: a name of the DBus error :return: True or False Nr rrr r r match_nameqszAbstractErrorRule.match_namecCsdS)zGet 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 rr r rget_typezszAbstractErrorRule.get_typeN) rrrr __slots__rrrr r!r r r rrZs   r) metaclassc@s@eZdZdZddgZddZddZdd Zd d Zd d Z dS)r z4Rule for mapping a Python exception to a DBus error._exception_type _error_namecCs||_||_dS)aVCreate 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%)rr rr r r__init__s zErrorRule.__init__cCs |j|kS)/Is this rule matching the given exception type?r$rr r rrszErrorRule.match_typecCs|jSz-Get a DBus name for the given exception type.r%rr r rrszErrorRule.get_namecCs |j|kS)+Is this rule matching the given DBus error?r*rr r rr szErrorRule.match_namecCs|jSz.Get an exception type of the given DBus error.r(rr r rr!szErrorRule.get_typeN rrrrr"r&rrr r!r r r rr sr c@s@eZdZdZddgZddZddZdd Zd d Zd d Z dS)r zs  2*((