Skip to content

Commit 8a3bc2c

Browse files
committed
Merge branch 'dev'
2 parents f29914e + 8fad377 commit 8a3bc2c

7 files changed

Lines changed: 41 additions & 27 deletions

File tree

jconfig/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@contact: https://vk.com/python273
66
@license Apache License, Version 2.0, see LICENSE file
77
8-
Copyright (C) 2015
8+
Copyright (C) 2016
99
"""
1010

1111
__author__ = 'Kirill Python'

jconfig/jconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@contact: https://vk.com/python273
66
@license Apache License, Version 2.0, see LICENSE file
77
8-
Copyright (C) 2015
8+
Copyright (C) 2016
99
"""
1010

1111
import json

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
@contact: http://vk.com/python273
77
@license Apache License, Version 2.0, see LICENSE file
88
9-
Copyright (C) 2015
9+
Copyright (C) 2016
1010
'''
1111

1212
from distutils.core import setup
1313

1414

1515
setup(
1616
name='vk_api',
17-
version='7.1',
17+
version='7.2',
1818
author='Kirill Python',
19-
author_email='python273@ya.ru',
19+
author_email='whoami@python273.pw',
2020
url='https://github.com/python273/vk_api',
2121
description='Module for writing scripts for vk.com (vkontakte)',
2222
download_url='https://github.com/python273/vk_api/archive/master.zip',

vk_api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
@contact: https://vk.com/python273
66
@license Apache License, Version 2.0, see LICENSE file
77
8-
Copyright (C) 2015
8+
Copyright (C) 2016
99
"""
1010

1111
__author__ = 'Kirill Python'
12-
__version__ = '7.1'
12+
__version__ = '7.2'
1313
__email__ = 'python273@ya.ru'
1414
__contact__ = 'https://vk.com/python273'
1515

vk_api/vk_api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@contact: https://vk.com/python273
66
@license Apache License, Version 2.0, see LICENSE file
77
8-
Copyright (C) 2015
8+
Copyright (C) 2016
99
"""
1010

1111
import re
@@ -120,7 +120,7 @@ def authorization(self, reauth=False):
120120
if not self.check_sid():
121121
self.vk_login()
122122
else:
123-
self.security_check('https://vk.com/')
123+
self.security_check('https://vk.com/settings')
124124

125125
if not self.check_token():
126126
self.api_login()
@@ -365,13 +365,15 @@ def auth_handler(self):
365365
def get_api(self):
366366
return VkApiMethod(self)
367367

368-
def method(self, method, values=None, captcha_sid=None, captcha_key=None):
368+
def method(self, method, values=None, captcha_sid=None, captcha_key=None, raw=False):
369369
""" Использование методов API
370370
371371
:param method: метод
372372
:param values: параметры
373373
:param captcha_sid:
374374
:param captcha_key:
375+
:param raw: при False возвращает response['response'], при True возвращает response
376+
e.g. может понадобиться для метода execute для получения execute_errors
375377
"""
376378

377379
url = 'https://api.vk.com/method/%s' % method
@@ -435,7 +437,7 @@ def method(self, method, values=None, captcha_sid=None, captcha_key=None):
435437

436438
raise error
437439

438-
return response['response']
440+
return response if raw else response['response']
439441

440442

441443
class VkApiMethod:

vk_api/vk_tools.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@contact: https://vk.com/python273
66
@license Apache License, Version 2.0, see LICENSE file
77
8-
Copyright (C) 2015
8+
Copyright (C) 2016
99
"""
1010

1111
import json
@@ -111,21 +111,28 @@ def get_all_slow(self, method, max_count, values=None, key='items',
111111
class VkRequestsPool(object):
112112
""" Позволяет сделать несколько обращений к API за один запрос
113113
за счет метода execute
114+
115+
Если ответ от API приходит в виде list'а (например при вызове users.get),
116+
то значение записывается с ключем list {'list': [...]}
114117
"""
115118

116-
__slots__ = ('vk', 'pool', 'one_param')
119+
__slots__ = ('vk', 'pool', 'one_param', 'execute_errors')
117120

118121
def __init__(self, vk):
119122
self.vk = vk
120123
self.pool = []
121124
self.one_param = False
125+
self.execute_errors = []
122126

123127
def __enter__(self):
124128
return self
125129

126130
def __exit__(self, *args, **kwargs):
127131
self.execute()
128132

133+
def get_execute_errors(self):
134+
return self.execute_errors
135+
129136
def method(self, method, values=None):
130137
""" Добавляет запрос в пулл
131138
@@ -169,7 +176,7 @@ def method_one_param(self, method, default_values=None, key=None,
169176

170177
def check_one_method(self, pool):
171178
""" Возвращает True, если все запросы в пулле к одному методу """
172-
if len(pool) > 1:
179+
if pool:
173180
first_method = pool[0][0]
174181

175182
for req in pool[1:]:
@@ -225,22 +232,30 @@ def execute(self):
225232

226233
if self.one_param:
227234
run_code = self.gen_code_one_param(cur_pool)
235+
elif self.check_one_method(cur_pool):
236+
run_code = self.gen_code_one_method(cur_pool)
228237
else:
229-
one_method = self.check_one_method(cur_pool)
238+
run_code = self.gen_code_many_methods(cur_pool)
230239

231-
if one_method:
232-
run_code = self.gen_code_one_method(cur_pool)
233-
else:
234-
run_code = self.gen_code_many_methods(cur_pool)
240+
response_raw = self.vk.method('execute', {'code': run_code}, raw=True)
235241

236-
response = self.vk.method('execute', {'code': run_code})
242+
response = response_raw['response']
243+
response_errors = response_raw.get('execute_errors')
244+
245+
if response_errors:
246+
self.execute_errors += response_errors[:-1]
237247

238248
for x in range(len(response)):
239249
if self.one_param:
240-
self.one_param['return'][cur_pool[x]] = response[x]
250+
if response[x] is False:
251+
self.one_param['return'][cur_pool[x]] = {'_error': True}
252+
else:
253+
self.one_param['return'][cur_pool[x]] = response[x]
241254
else:
242255
if response[x] is False:
243256
self.pool[i + x][2].update({'_error': True})
257+
elif type(response[x]) is list:
258+
self.pool[i + x][2].update({'list': response[x]})
244259
else:
245260
self.pool[i + x][2].update(response[x])
246261

vk_api/vk_upload.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@contact: https://vk.com/python273
66
@license Apache License, Version 2.0, see LICENSE file
77
8-
Copyright (C) 2015
8+
Copyright (C) 2016
99
"""
1010

1111

@@ -112,7 +112,7 @@ def photo_wall(self, photos, user_id=None, group_id=None):
112112

113113
return response
114114

115-
def audio(self, file_path, artist, title):
115+
def audio(self, file_path, **kwargs):
116116
""" Загрузка аудио
117117
118118
:param file_path: путь к аудиофайлу
@@ -127,10 +127,7 @@ def audio(self, file_path, artist, title):
127127

128128
response = self.vk.http.post(url, files=audio_file).json()
129129

130-
response.update({
131-
'artist': artist,
132-
'title': title
133-
})
130+
response.update(kwargs)
134131

135132
response = self.vk.method('audio.save', response)
136133

0 commit comments

Comments
 (0)