| 372 | | current = context |
|---|
| 373 | | bits = path.split(VARIABLE_ATTRIBUTE_SEPARATOR) |
|---|
| 374 | | while bits: |
|---|
| 375 | | try: # dictionary lookup |
|---|
| 376 | | current = current[bits[0]] |
|---|
| 377 | | except (TypeError, AttributeError, KeyError): |
|---|
| 378 | | try: # attribute lookup |
|---|
| 379 | | current = getattr(current, bits[0]) |
|---|
| 380 | | if callable(current): |
|---|
| 381 | | if getattr(current, 'alters_data', False): |
|---|
| 382 | | current = '' |
|---|
| 383 | | else: |
|---|
| 384 | | try: # method call (assuming no args required) |
|---|
| 385 | | current = current() |
|---|
| 386 | | except SilentVariableFailure: |
|---|
| | 373 | if path[0] in ('"', "'") and path[0] == path[-1]: |
|---|
| | 374 | current = path[1:-1] |
|---|
| | 375 | else: |
|---|
| | 376 | current = context |
|---|
| | 377 | bits = path.split(VARIABLE_ATTRIBUTE_SEPARATOR) |
|---|
| | 378 | while bits: |
|---|
| | 379 | try: # dictionary lookup |
|---|
| | 380 | current = current[bits[0]] |
|---|
| | 381 | except (TypeError, AttributeError, KeyError): |
|---|
| | 382 | try: # attribute lookup |
|---|
| | 383 | current = getattr(current, bits[0]) |
|---|
| | 384 | if callable(current): |
|---|
| | 385 | if getattr(current, 'alters_data', False): |
|---|
| 388 | | except TypeError: # arguments *were* required |
|---|
| 389 | | current = '' # invalid method call |
|---|
| 390 | | except (TypeError, AttributeError): |
|---|
| 391 | | try: # list-index lookup |
|---|
| 392 | | current = current[int(bits[0])] |
|---|
| 393 | | except (IndexError, ValueError, KeyError): |
|---|
| 394 | | raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute |
|---|
| 395 | | del bits[0] |
|---|
| | 387 | else: |
|---|
| | 388 | try: # method call (assuming no args required) |
|---|
| | 389 | current = current() |
|---|
| | 390 | except SilentVariableFailure: |
|---|
| | 391 | current = '' |
|---|
| | 392 | except TypeError: # arguments *were* required |
|---|
| | 393 | current = '' # invalid method call |
|---|
| | 394 | except (TypeError, AttributeError): |
|---|
| | 395 | try: # list-index lookup |
|---|
| | 396 | current = current[int(bits[0])] |
|---|
| | 397 | except (IndexError, ValueError, KeyError): |
|---|
| | 398 | raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute |
|---|
| | 399 | del bits[0] |
|---|