| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 1 | '''Replace auto-generated classes with our own, where necessary. |
| 2 | ''' |
| 3 | |
| Adam Israel | c3e6c2e | 2018-03-01 09:31:50 -0500 | [diff] [blame] | 4 | from . import _client, _definitions, overrides # isort:skip |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 5 | |
| 6 | for o in overrides.__all__: |
| Adam Israel | 1a15d1c | 2017-10-23 12:00:49 -0400 | [diff] [blame] | 7 | if "Facade" not in o: |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 8 | # Override stuff in _definitions, which is all imported |
| 9 | # into _client. We Monkey patch both the original class and |
| 10 | # the ref in _client (import shenanigans are fun!) |
| 11 | setattr(_definitions, o, getattr(overrides, o)) |
| 12 | setattr(_client, o, getattr(overrides, o)) |
| 13 | # We shouldn't be overriding Facades! |
| 14 | else: |
| 15 | raise ValueError( |
| 16 | "Cannot override a versioned Facade class -- you must patch " |
| 17 | "it instead.") |
| 18 | |
| 19 | for o in overrides.__patches__: |
| 20 | # Patch a versioned Facade. |
| 21 | for client_version in _client.CLIENTS.values(): |
| 22 | try: |
| 23 | c_type = getattr(client_version, o) |
| 24 | except AttributeError: |
| 25 | # Not all the _client<version> modules may have the |
| 26 | # facade. That's okay -- we just skip over them. |
| 27 | continue |
| 28 | o_type = getattr(overrides, o) |
| 29 | for a in dir(o_type): |
| 30 | if not a.startswith('_'): |
| 31 | setattr(c_type, a, getattr(o_type, a)) |
| 32 | |
| Adam Israel | c3e6c2e | 2018-03-01 09:31:50 -0500 | [diff] [blame] | 33 | from ._client import * # noqa, isort:skip |