From fb9f0e27aa02d4f27f1a9862af5e636df1fb66fe Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 14 Feb 2019 13:33:16 +0300 Subject: [PATCH] Add contextmanager to Control module --- python3_anticaptcha/AntiCaptchaControl.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/python3_anticaptcha/AntiCaptchaControl.py b/python3_anticaptcha/AntiCaptchaControl.py index 8611f91..61e0fa8 100644 --- a/python3_anticaptcha/AntiCaptchaControl.py +++ b/python3_anticaptcha/AntiCaptchaControl.py @@ -11,6 +11,14 @@ class AntiCaptchaControl: :param anticaptcha_key: Ключ антикапчи """ self.ANTICAPTCHA_KEY = anticaptcha_key + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + if exc_type: + return False + return True def get_balance(self): ''' @@ -43,6 +51,14 @@ class aioAntiCaptchaControl: :param anticaptcha_key: Ключ антикапчи """ self.ANTICAPTCHA_KEY = anticaptcha_key + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + if exc_type: + return False + return True async def get_balance(self): ''' @@ -64,4 +80,4 @@ class aioAntiCaptchaControl: } async with aiohttp.ClientSession() as session: async with session.post(incorrect_captcha_url, json=payload) as resp: - return await resp.json() \ No newline at end of file + return await resp.json()