(obj, attr, value=None)
| 11 | |
| 12 | |
| 13 | def attrget(obj, attr, value=None): |
| 14 | try: |
| 15 | if hasattr(obj, "has_key") and attr in obj: |
| 16 | return obj[attr] |
| 17 | except TypeError: |
| 18 | # Handle the case where has_key takes different number of arguments. |
| 19 | # This is the case with Model objects on appengine. See #134 |
| 20 | pass |
| 21 | if ( |
| 22 | hasattr(obj, "keys") and attr in obj |
| 23 | ): # needed for Py3, has_key doesn't exist anymore |
| 24 | return obj[attr] |
| 25 | elif hasattr(obj, attr): |
| 26 | return getattr(obj, attr) |
| 27 | return value |
| 28 | |
| 29 | |
| 30 | class Form: |