Pimped Python property for interfacing with instruments. Can be used as a decorator. Processors can registered for each arguments to modify their values before they are passed to the body of the method. Two standard processors are defined: `values` and `units` and others can be give
| 66 | |
| 67 | |
| 68 | class Feat(object): |
| 69 | """Pimped Python property for interfacing with instruments. Can be used as |
| 70 | a decorator. |
| 71 | |
| 72 | Processors can registered for each arguments to modify their values before |
| 73 | they are passed to the body of the method. Two standard processors are |
| 74 | defined: `values` and `units` and others can be given as callables in the |
| 75 | `procs` parameter. |
| 76 | |
| 77 | If a method contains multiple arguments, use a tuple. None can be used as |
| 78 | `do not change`. |
| 79 | |
| 80 | :param fget: getter function. |
| 81 | :param fset: setter function. |
| 82 | :param doc: docstring, if missing fget or fset docstring will be used. |
| 83 | |
| 84 | :param values: A dictionary to map key to values. |
| 85 | A set to restrict the values. |
| 86 | If a list/tuple instead of a dict is given, the value is not |
| 87 | changed but only tested to belong to the container. |
| 88 | :param units: `Quantity` or string that can be interpreted as units. |
| 89 | :param procs: Other callables to be applied to input arguments. |
| 90 | |
| 91 | """ |
| 92 | |
| 93 | __original_doc__ = '' |
| 94 | |
| 95 | def __init__(self, fget=MISSING, fset=None, doc=None, *, |
| 96 | values=None, units=None, limits=None, procs=None, |
| 97 | read_once=False): |
| 98 | self.fget = fget |
| 99 | self.fset = fset |
| 100 | self.__doc__ = doc |
| 101 | self.name = '?' |
| 102 | |
| 103 | #: instance: value |
| 104 | self.value = WeakKeyDictionary() |
| 105 | |
| 106 | #: instance: key: value |
| 107 | self.modifiers = WeakKeyDictionary() |
| 108 | self.get_processors = WeakKeyDictionary() |
| 109 | self.set_processors = WeakKeyDictionary() |
| 110 | |
| 111 | # Take documentation from fget or fset |
| 112 | # if not provided explicitly. |
| 113 | if self.__doc__ is None: |
| 114 | if fget is not MISSING and fget.__doc__: |
| 115 | self.__doc__ = fget.__doc__ |
| 116 | elif fset and fset.__doc__: |
| 117 | self.__doc__ = fset.__doc__ |
| 118 | |
| 119 | self.modifiers[MISSING] = {MISSING: {'values': values, |
| 120 | 'units': units, |
| 121 | 'limits': limits, |
| 122 | 'processors': procs}} |
| 123 | self.get_processors[MISSING] = {MISSING: ()} |
| 124 | self.set_processors[MISSING] = {MISSING: ()} |
| 125 |
no outgoing calls
no test coverage detected