From a444cc5d40fe5b721df3475eadf9b3af75a6b8a8 Mon Sep 17 00:00:00 2001 From: Joshua Wong Date: Sun, 8 Apr 2018 11:28:44 +0800 Subject: [PATCH] Implemented Context Manager for Requests --- agithub/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/agithub/base.py b/agithub/base.py index 88b8a31..4136eb1 100644 --- a/agithub/base.py +++ b/agithub/base.py @@ -430,3 +430,19 @@ def _filterEmptyHeaders(self, headers): newHeaders[header] = headers[header] return newHeaders + +class connectionManager(object): + ''' + Context manager for handling connections in client.request + ''' + def __init__(self, client): + self.conn = client.get_connection() + + def __enter__(self): + return self.conn + + def __exit__(self, exc_type, exc_value, traceback): + self.conn.close() + + +