diff env/lib/python3.7/site-packages/boto/beanstalk/wrapper.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.7/site-packages/boto/beanstalk/wrapper.py	Thu May 14 14:56:58 2020 -0400
@@ -0,0 +1,29 @@
+"""Wraps layer1 api methods and converts layer1 dict responses to objects."""
+from boto.beanstalk.layer1 import Layer1
+import boto.beanstalk.response
+from boto.exception import BotoServerError
+import boto.beanstalk.exception as exception
+
+
+def beanstalk_wrapper(func, name):
+    def _wrapped_low_level_api(*args, **kwargs):
+        try:
+            response = func(*args, **kwargs)
+        except BotoServerError as e:
+            raise exception.simple(e)
+        # Turn 'this_is_a_function_name' into 'ThisIsAFunctionNameResponse'.
+        cls_name = ''.join([part.capitalize() for part in name.split('_')]) + 'Response'
+        cls = getattr(boto.beanstalk.response, cls_name)
+        return cls(response)
+    return _wrapped_low_level_api
+
+
+class Layer1Wrapper(object):
+    def __init__(self, *args, **kwargs):
+        self.api = Layer1(*args, **kwargs)
+
+    def __getattr__(self, name):
+        try:
+            return beanstalk_wrapper(getattr(self.api, name), name)
+        except AttributeError:
+            raise AttributeError("%s has no attribute %r" % (self, name))