Author: Diane Trout <diane@ghic.org>
Description: This is an upstream fix backported
 to version of ratelimiter as it exists in Debian.
Origin: backport https://github.com/RazerM/ratelimiter/commit/59a0827c434706d62b89e16a220e4ae12e618858

--- a/ratelimiter.py
+++ b/ratelimiter.py
@@ -30,8 +30,6 @@
 __license__ = 'Apache'
 __description__ = 'Simple python rate limiting object'
 
-PY35 = sys.version_info >= (3, 5)
-
 
 class RateLimiter(object):
     """Provides rate limiting for an operation with a configurable number of
@@ -101,30 +99,26 @@
             while self._timespan >= self.period:
                 self.calls.popleft()
 
-    if PY35:
-        # We have to exec this due to syntax errors on earlier versions.
-        aenter_code = dedent("""
-            async def __aenter__(self):
-                if self._alock is None:
-                    self._init_async_lock()
-                    
-                with await self._alock:
-                    # We want to ensure that no more than max_calls were run in the allowed
-                    # period. For this, we store the last timestamps of each call and run
-                    # the rate verification upon each __enter__ call.
-                    if len(self.calls) >= self.max_calls:
-                        until = time.time() + self.period - self._timespan
-                        if self.callback:
-                            asyncio.ensure_future(self.callback(until))
-                        sleeptime = until - time.time()
-                        if sleeptime > 0:
-                            await asyncio.sleep(sleeptime)
-                    return self
+    async def __aenter__(self):
+        if self._alock is None:
+            self._init_async_lock()
+
+        async with self._alock:
+            # We want to ensure that no more than max_calls were run in the allowed
+            # period. For this, we store the last timestamps of each call and run
+            # the rate verification upon each __enter__ call.
+            if len(self.calls) >= self.max_calls:
+                until = time.time() + self.period - self._timespan
+                if self.callback:
+                    asyncio.ensure_future(self.callback(until))
+                sleeptime = until - time.time()
+                if sleeptime > 0:
+                    await asyncio.sleep(sleeptime)
+            return self
 
-            """)
-        exec(aenter_code)
 
-        __aexit__ = asyncio.coroutine(__exit__)
+    async def __aexit__(self, exc_type, exc_value, traceback):
+         return super(AsyncRateLimiter, self).__exit__(exc_type, exc_value, traceback)
 
     @property
     def _timespan(self):
