Get an item or attribute of an object but prefer the item.
(self, obj, argument)
| 406 | key=lambda x: x.priority)) |
| 407 | |
| 408 | def getitem(self, obj, argument): |
| 409 | """Get an item or attribute of an object but prefer the item.""" |
| 410 | try: |
| 411 | return obj[argument] |
| 412 | except (AttributeError, TypeError, LookupError): |
| 413 | if isinstance(argument, string_types): |
| 414 | try: |
| 415 | attr = str(argument) |
| 416 | except Exception: |
| 417 | pass |
| 418 | else: |
| 419 | try: |
| 420 | return getattr(obj, attr) |
| 421 | except AttributeError: |
| 422 | pass |
| 423 | return self.undefined(obj=obj, name=argument) |
| 424 | |
| 425 | def getattr(self, obj, attribute): |
| 426 | """Get an item or attribute of an object but prefer the attribute. |
no test coverage detected