internal: used to create decorator for class or function objects. `kwargs`: these are typically the keyword arguments passed to the decorator itself. must be a `dict`. The decorator will often update the dict to have defaults or overrides to the parameters passed to
(kwargs={}, update_func=None, generate_xml_func=None)
| 58 | |
| 59 | |
| 60 | def _create_decorator(kwargs={}, update_func=None, generate_xml_func=None): |
| 61 | """internal: used to create decorator for class or function objects. |
| 62 | |
| 63 | `kwargs`: these are typically the keyword arguments passed to the decorator itself. |
| 64 | must be a `dict`. The decorator will often update the dict to have |
| 65 | defaults or overrides to the parameters passed to the decorator, as appropriate. |
| 66 | |
| 67 | `update_func`: if non-None, must be a callable that takes 2 arguments `(decoratedobj, kwargs)`. |
| 68 | The purpose of this callback is to update the kwargs (and return updated version) |
| 69 | for required-yet-missing attributes that can be deduced by introspecting |
| 70 | the `decoratedobj`. |
| 71 | |
| 72 | `generate_xml_func`: must be non-None and must be a callable that takes 2 arguments `(decoratedobj, kwargs)`. |
| 73 | The kwargs can be expected to have been updated by calling `update_func`, if non-None. |
| 74 | The callback typically adds an attribute on the decoratedobj for further processing later. |
| 75 | """ |
| 76 | attrs = kwargs.copy() |
| 77 | |
| 78 | def decorator(func): |
| 79 | original_func = _undecorate(func) |
| 80 | if update_func is not None: |
| 81 | updated_attrs = update_func(original_func, attrs) |
| 82 | else: |
| 83 | updated_attrs = attrs |
| 84 | generate_xml_func(original_func, updated_attrs) |
| 85 | |
| 86 | @wraps(func) |
| 87 | def wrapper(*args, **kwargs): |
| 88 | return func(*args, **kwargs) |
| 89 | |
| 90 | setattr(wrapper, "_pv_original_func", original_func) |
| 91 | return wrapper |
| 92 | |
| 93 | return decorator |
| 94 | |
| 95 | |
| 96 | class smproperty(object): |
no test coverage detected