From 27714a01490b21e8c60aa35e0faaabcbde8fd8b9 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 17 Apr 2018 17:15:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst | 2 +- aiovk/drivers.py | 4 ++-- aiovk/longpoll.py | 8 ++++---- aiovk/mixins.py | 4 ++-- aiovk/sessions.py | 6 +++--- tests/README.md | 2 +- tests/test_drivers.py | 2 -- tests/{test_logpoll.py => test_longpoll.py} | 0 tests/test_utils.py | 2 +- 9 files changed, 14 insertions(+), 16 deletions(-) rename tests/{test_logpoll.py => test_longpoll.py} (100%) diff --git a/README.rst b/README.rst index 084055e..17e0ded 100644 --- a/README.rst +++ b/README.rst @@ -208,4 +208,4 @@ Use Session object Notice that ``wait`` value only for long pool connection. Real pause could be more ``wait`` time because of need time -for authorisation (if needed), reconnect and etc. +for authorization (if needed), reconnect and etc. diff --git a/aiovk/drivers.py b/aiovk/drivers.py index b8edaa8..d5e1b44 100644 --- a/aiovk/drivers.py +++ b/aiovk/drivers.py @@ -21,7 +21,7 @@ async def start(self, connection, read_until_eof=False): await super().start(connection, read_until_eof) headers = CIMultiDict(self.headers) location = headers.get(hdrs.LOCATION, None) - if location is not None: + if location: headers[hdrs.LOCATION] = location.replace('#', '?') self.headers = CIMultiDictProxy(headers) self.raw_headers = tuple(headers.items()) @@ -95,7 +95,7 @@ async def close(self): await self.session.close() -if ProxyConnector is not None: +if ProxyConnector: class Socks5Driver(HttpDriver): connector = ProxyConnector diff --git a/aiovk/longpoll.py b/aiovk/longpoll.py index 44e2630..912d1a5 100644 --- a/aiovk/longpoll.py +++ b/aiovk/longpoll.py @@ -32,7 +32,7 @@ async def _get_long_poll_server(self, need_pts=False): self.base_url = 'https://{}'.format(response['server']) async def wait(self, need_pts=False): - if self.base_url is None: + if not self.base_url: await self._get_long_poll_server(need_pts) params = { 'ts': self.ts, @@ -40,7 +40,7 @@ async def wait(self, need_pts=False): } params.update(self.base_params) # invalid mymetype from server - code, response = await self.api._session.driver.get_text(self.base_url, params, timeout=2*self.base_params['wait']) + code, response = await self.api._session.driver.get_text(self.base_url, params, timeout=2 * self.base_params['wait']) if code == 403: raise VkLongPollError(403, 'smth weth wrong', @@ -49,7 +49,7 @@ async def wait(self, need_pts=False): ) response = json.loads(response) failed = response.get('failed') - if failed is None: + if not failed: self.ts = response['ts'] return response if failed == 1: @@ -64,7 +64,7 @@ async def wait(self, need_pts=False): return await self.wait() async def get_pts(self, need_ts=False): - if self.base_url is None or self.pts is None: + if not self.base_url or not self.pts: await self._get_long_poll_server(need_pts=True) if need_ts: return self.pts, self.ts diff --git a/aiovk/mixins.py b/aiovk/mixins.py index 2952590..3eb6638 100644 --- a/aiovk/mixins.py +++ b/aiovk/mixins.py @@ -3,7 +3,7 @@ class LimitRateDriverMixin: requests_per_period = 3 - period = 1 #seconds + period = 1 # seconds def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -32,7 +32,7 @@ async def close(self): class SimpleImplicitSessionMixin: """ - Simple implementation of processing captcha and 2factor authorisation + Simple implementation of processing captcha and 2factor authorization """ async def enter_captcha(self, url, sid): diff --git a/aiovk/sessions.py b/aiovk/sessions.py index fa6984d..b76dee6 100644 --- a/aiovk/sessions.py +++ b/aiovk/sessions.py @@ -38,7 +38,7 @@ async def send_api_request(self, method_name: str, params: dict = None, timeout: class TokenSession(BaseSession): """Implements simple session that ues existed token for work""" - API_VERSION = '5.63' + API_VERSION = '5.74' REQUEST_URL = 'https://api.vk.com/method/' def __init__(self, access_token: str = None, timeout: int = 10, driver=None): @@ -111,7 +111,7 @@ async def enter_captcha(self, url: str, sid: str) -> str: class ImplicitSession(TokenSession): """ - For client authorisation in js apps and standalone (desktop and mobile) apps + For client authorization in js apps and standalone (desktop and mobile) apps See more in https://new.vk.com/dev/implicit_flow_user """ AUTH_URL = 'https://oauth.vk.com/authorize' @@ -269,7 +269,7 @@ async def enter_confirmation_code(self) -> str: class AuthorizationCodeSession(TokenSession): """ - For client authorisation in js apps and standalone (desktop and mobile) apps + For client authorization in js apps and standalone (desktop and mobile) apps See more in https://new.vk.com/dev/implicit_flow_user """ CODE_URL = 'https://oauth.vk.com/access_token' diff --git a/tests/README.md b/tests/README.md index 5eae864..516e45b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,5 @@ ### Before testing 1) Rename `auth_data.py.example` to `auth_data.py` -2) Enter your authorisation data +2) Enter your authorization data 3) Add your 2factor code from security settings (under QR code) 4) Run tests diff --git a/tests/test_drivers.py b/tests/test_drivers.py index a0a8e9c..1be7a62 100644 --- a/tests/test_drivers.py +++ b/tests/test_drivers.py @@ -1,10 +1,8 @@ import json import os -import unittest from http.server import HTTPServer from threading import Thread from unittest import mock -import aio.testing import time import math import asyncio diff --git a/tests/test_logpoll.py b/tests/test_longpoll.py similarity index 100% rename from tests/test_logpoll.py rename to tests/test_longpoll.py diff --git a/tests/test_utils.py b/tests/test_utils.py index caf4dba..af1bd00 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -63,7 +63,7 @@ async def foo(a): obj._queue = q yield from foo(obj) - self.assertEqual(q.qsize(), size-1) + self.assertEqual(q.qsize(), size - 1) q.canel() @aio.testing.run_until_complete