Skip to content

Commit 366225e

Browse files
committed
Some refactoring
1 parent 10ef41f commit 366225e

2 files changed

Lines changed: 14 additions & 26 deletions

File tree

vk_api/tools.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def get_all_iter(self, method, max_count, values=None, key='items',
5353
:type limit: int
5454
"""
5555

56-
if values:
57-
values = values.copy()
58-
else:
59-
values = {}
56+
values = values.copy() if values else {}
6057

6158
items_count = 0
6259
offset = 0
@@ -111,21 +108,16 @@ def get_all_slow_iter(self, method, max_count, values=None, key='items',
111108
но может прийти больше
112109
"""
113110

114-
if not values:
115-
values = {}
116-
else:
117-
values = values.copy()
111+
values = values.copy() if values else {}
118112

119-
values.update({'count': max_count})
113+
values['count'] = max_count
120114

121115
response = self.vk.method(method, values)
122116
count = response['count']
123117
items_count = 0
124118

125-
for i in range(max_count, count + 1, max_count):
126-
values.update({
127-
'offset': i
128-
})
119+
for offset in range(max_count, count + 1, max_count):
120+
values['offset'] = offset
129121

130122
response = self.vk.method(method, values)
131123
items = response[key]

vk_api/vk_api.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
RE_LOGIN_HASH = re.compile(r'name="lg_h" value="([a-z0-9]+)"')
2727
RE_CAPTCHAID = re.compile(r"onLoginCaptcha\('(\d+)'")
2828
RE_NUMBER_HASH = re.compile(r"al_page: '3', hash: '([a-z0-9]+)'")
29-
RE_AUTH_HASH = re.compile(r"\{.*?act: 'a_authcheck_code'.+?hash: '([a-z_0-9]+)'.*?\}")
29+
RE_AUTH_HASH = re.compile(
30+
r"\{.*?act: 'a_authcheck_code'.+?hash: '([a-z_0-9]+)'.*?\}"
31+
)
3032
RE_TOKEN_URL = re.compile(r'location\.href = "(.*?)"\+addr;')
3133

3234
RE_PHONE_PREFIX = re.compile(r'label ta_r">\+(.*?)<')
@@ -372,7 +374,7 @@ def too_many_rps_handler(self, error):
372374
return error.try_method()
373375

374376
def auth_handler(self):
375-
raise AuthError("No handler for two-factor authorization.")
377+
raise AuthError('No handler for two-factor authentication')
376378

377379
def get_api(self):
378380
return VkApiMethod(self)
@@ -389,23 +391,17 @@ def method(self, method, values=None, captcha_sid=None, captcha_key=None, raw=Fa
389391
"""
390392

391393
url = 'https://api.vk.com/method/%s' % method
392-
393-
if values:
394-
values = values.copy()
395-
else:
396-
values = {}
394+
values = values.copy() if values else {}
397395

398396
if 'v' not in values:
399-
values.update({'v': self.api_version})
397+
values['v'] = self.api_version
400398

401399
if self.token:
402-
values.update({'access_token': self.token['access_token']})
400+
values['access_token'] = self.token['access_token']
403401

404402
if captcha_sid and captcha_key:
405-
values.update({
406-
'captcha_sid': captcha_sid,
407-
'captcha_key': captcha_key
408-
})
403+
values['captcha_sid'] = captcha_sid
404+
values['captcha_key'] = captcha_key
409405

410406
with self.lock:
411407
# Ограничение 3 запроса в секунду

0 commit comments

Comments
 (0)