aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/api.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-12-23 07:20:36 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-12-23 07:20:36 +0300
commit7b8cc8a9f455eda41b9c7d70f4561a84fcda941e (patch)
treeb9e262e9a1dbb663c3b9f704a9fe4daf54be0ce9 /vk/api.py
parentTravis: online_sessions.sh: refactoring (diff)
downloadvk-scripts-7b8cc8a9f455eda41b9c7d70f4561a84fcda941e.tar.gz
vk-scripts-7b8cc8a9f455eda41b9c7d70f4561a84fcda941e.zip
pylint/pep8 fixes
Diffstat (limited to 'vk/api.py')
-rw-r--r--vk/api.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/vk/api.py b/vk/api.py
index d79122d..0ba2f44 100644
--- a/vk/api.py
+++ b/vk/api.py
@@ -3,8 +3,7 @@
# For details, see https://github.com/egor-tensin/vk-scripts.
# Distributed under the MIT License.
-from collections import Iterable
-from collections.abc import Mapping
+from collections.abc import Iterable, Mapping
from enum import Enum
import json
from urllib.error import URLError
@@ -14,21 +13,24 @@ from urllib.request import urlopen
import vk.error
from vk.user import User
+
def _split_url(url):
return urllib.parse.urlsplit(url)[:3]
+
def _is_empty_param_value(value):
return isinstance(value, str) and not value
+
def _filter_empty_params(params, empty_params=False):
if empty_params:
return params
if isinstance(params, Mapping):
return {name: value for name, value in params.items() if not _is_empty_param_value(value)}
- elif isinstance(params, Iterable):
+ if isinstance(params, Iterable):
return [(name, value) for name, value in params if not _is_empty_param_value(value)]
- else:
- raise TypeError()
+ raise TypeError()
+
def _build_url(scheme, host, path, params=None, empty_params=False):
if params is None:
@@ -43,6 +45,7 @@ def _build_url(scheme, host, path, params=None, empty_params=False):
path = urllib.parse.quote(path)
return urllib.parse.urlunsplit((scheme, host, path, params, ''))
+
def _join_param_values(values):
if isinstance(values, str):
return values
@@ -50,13 +53,16 @@ def _join_param_values(values):
return ','.join(map(str, values))
return values
+
def _join_path(base, url):
if not base.endswith('/'):
base += '/'
return urllib.parse.urljoin(base, url)
+
ACCESS_TOKEN = '9722cef09722cef09722cef071974b8cbe997229722cef0cbabfd816916af6c7bd37006'
+
class Version(Enum):
V5_73 = '5.73'
DEFAULT = V5_73
@@ -64,6 +70,7 @@ class Version(Enum):
def __str__(self):
return self.value
+
class Language(Enum):
EN = 'en'
DEFAULT = EN
@@ -71,6 +78,7 @@ class Language(Enum):
def __str__(self):
return self.value
+
class Method(Enum):
USERS_GET = 'users.get'
FRIENDS_GET = 'friends.get'
@@ -78,6 +86,7 @@ class Method(Enum):
def __str__(self):
return self.value
+
class CommonParameters(Enum):
ACCESS_TOKEN = 'access_token'
VERSION = 'v'
@@ -86,6 +95,7 @@ class CommonParameters(Enum):
def __str__(self):
return self.value
+
class API:
_ROOT_URL = 'https://api.vk.com/method/'
@@ -136,4 +146,5 @@ class API:
fields=_join_param_values(fields))
if 'items' not in response:
raise vk.error.InvalidAPIResponseError(response)
- return self._filter_response_with_users(response['items'], deactivated_users)
+ return self._filter_response_with_users(response['items'],
+ deactivated_users)