(self, instance, owner=None, key=MISSING)
| 204 | return value |
| 205 | |
| 206 | def get(self, instance, owner=None, key=MISSING): |
| 207 | if instance is None: |
| 208 | return self |
| 209 | |
| 210 | name = self.name + ('' if key is MISSING else '[{!r}]'.format(key)) |
| 211 | if self.fget is None or self.fget is MISSING: |
| 212 | raise AttributeError('{} is a write-only feature'.format(name)) |
| 213 | |
| 214 | current = self.get_cache(instance, key) |
| 215 | if self.read_once and current is not MISSING: |
| 216 | return current |
| 217 | |
| 218 | # This part calls to the underlying get function wrapping |
| 219 | # and timing, caching, logging and error handling |
| 220 | with instance._lock: |
| 221 | instance.log_info('Getting {}', name) |
| 222 | |
| 223 | try: |
| 224 | tic = time.time() |
| 225 | if key is MISSING: |
| 226 | value = self.fget(instance) |
| 227 | else: |
| 228 | value = self.fget(instance, key) |
| 229 | except Exception as e: |
| 230 | instance.log_error('While getting {}: {}', name, e) |
| 231 | raise e |
| 232 | |
| 233 | instance.timing.add('get_' + name, time.time() - tic) |
| 234 | |
| 235 | instance.log_debug('(raw) Got {} for {}', value, name) |
| 236 | try: |
| 237 | value = self.post_get(value, instance, key) |
| 238 | except Exception as e: |
| 239 | instance.log_error('While post-processing {} for {}: {}', value, name, e) |
| 240 | raise e |
| 241 | |
| 242 | instance.log_info('Got {} for {}', value, name, lantz_feat=(name, str(value))) |
| 243 | |
| 244 | self.set_cache(instance, value, key) |
| 245 | |
| 246 | return value |
| 247 | |
| 248 | def set(self, instance, value, force=False, key=MISSING): |
| 249 | name = self.name + ('' if key is MISSING else '[{!r}]'.format(key)) |
no test coverage detected