forked from DreamLab/AsyncOpenStackClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.py
More file actions
28 lines (21 loc) · 849 Bytes
/
Copy pathproxy.py
File metadata and controls
28 lines (21 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class ResourceProxy:
def __init__(self, api, resource_name):
self.resource_name = resource_name
self.api = api
def __getattr__(self, name):
return MethodProxy(self.api, self.resource_name, name)
class MethodProxy:
def __init__(self, api, resource, method):
self.api = api
self.resource = resource
self.method = method
def __call__(self, *args, **kwargs):
resource = getattr(self.api, self.resource)
method = getattr(resource, self.method)
if resource.actions[self.method]['method'] in ('GET',):
return self.get_result(method(*args, params=kwargs))
else:
return self.get_result(method(*args, body=kwargs))
async def get_result(self, method_awaitable):
result = await method_awaitable
return result.body