pytolino 1.6__py3-none-any.whl → 1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytolino/tolino_cloud.py +38 -18
- {pytolino-1.6.dist-info → pytolino-1.7.dist-info}/METADATA +1 -1
- pytolino-1.7.dist-info/RECORD +8 -0
- pytolino-1.6.dist-info/RECORD +0 -8
- {pytolino-1.6.dist-info → pytolino-1.7.dist-info}/WHEEL +0 -0
- {pytolino-1.6.dist-info → pytolino-1.7.dist-info}/licenses/LICENSE +0 -0
- {pytolino-1.6.dist-info → pytolino-1.7.dist-info}/top_level.txt +0 -0
pytolino/tolino_cloud.py
CHANGED
|
@@ -29,7 +29,7 @@ servers_settings = configparser.ConfigParser()
|
|
|
29
29
|
servers_settings.read(SERVERS_SETTINGS_FILE_PATH)
|
|
30
30
|
|
|
31
31
|
PARTNERS = servers_settings.sections()
|
|
32
|
-
TOTAL_RETRY =5
|
|
32
|
+
TOTAL_RETRY = 5
|
|
33
33
|
STATUS_FORCELIST = [404]
|
|
34
34
|
|
|
35
35
|
|
|
@@ -42,23 +42,41 @@ class Client(object):
|
|
|
42
42
|
|
|
43
43
|
"""create a client to communicate with a tolino partner (login, etc..)"""
|
|
44
44
|
|
|
45
|
-
def _log_requests(self, host_response):
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
def _log_requests(self, host_response, error: True or None=None):
|
|
46
|
+
if host_response.status_code >= 400 or error is True:
|
|
47
|
+
logger = logging.error
|
|
48
|
+
else:
|
|
49
|
+
logger = logging.debug
|
|
50
|
+
logger('log request')
|
|
51
|
+
logger('---------------- HTTP response (requests)----------')
|
|
52
|
+
logger(f'status code: {host_response.status_code}')
|
|
53
|
+
logger(f'cookies: {host_response.cookies}')
|
|
54
|
+
logger(f'headers: {host_response.headers}')
|
|
50
55
|
try:
|
|
51
56
|
j = host_response.json()
|
|
52
|
-
|
|
57
|
+
logger(f'json: {j}')
|
|
53
58
|
except requests.JSONDecodeError:
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
logger(f'text: {host_response.text}')
|
|
60
|
+
logger('-------------------------------------------------------')
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
host_response.raise_for_status()
|
|
64
|
+
except requests.exceptions.HTTPError as e:
|
|
65
|
+
raise PytolinoException
|
|
66
|
+
except requests.exceptions.RequestException as e:
|
|
67
|
+
raise PytolinoException
|
|
56
68
|
|
|
57
69
|
def _log_mechanize(self, host_response):
|
|
58
|
-
logging.
|
|
59
|
-
logging.
|
|
60
|
-
logging.
|
|
61
|
-
logging.
|
|
70
|
+
logging.debug('-------------- HTTP response (mechanize)--------------')
|
|
71
|
+
logging.debug(f'status code: {host_response.code}')
|
|
72
|
+
logging.debug(f'headers: {host_response.info()}')
|
|
73
|
+
logging.debug('-------------------------------------------------------')
|
|
74
|
+
if host_response.code >= 400:
|
|
75
|
+
logging.error('-------------- HTTP response (mechanize)----------')
|
|
76
|
+
logging.error(f'status code: {host_response.code}')
|
|
77
|
+
logging.error(f'headers: {host_response.info()}')
|
|
78
|
+
logging.error('--------------------------------------------------')
|
|
79
|
+
raise PytolinoException('http error')
|
|
62
80
|
|
|
63
81
|
def _hardware_id():
|
|
64
82
|
|
|
@@ -159,7 +177,7 @@ class Client(object):
|
|
|
159
177
|
for cookie in self.browser.cookiejar:
|
|
160
178
|
self.session.cookies.set(cookie.name, cookie.value)
|
|
161
179
|
|
|
162
|
-
logging.
|
|
180
|
+
logging.debug(self.server_settings['login_cookie'])
|
|
163
181
|
self._log_mechanize(host_response)
|
|
164
182
|
if not self.server_settings['login_cookie'] in self.session.cookies:
|
|
165
183
|
raise PytolinoException(f'login to {self.server_name} failed.')
|
|
@@ -191,7 +209,8 @@ class Client(object):
|
|
|
191
209
|
host_response.headers['Location']
|
|
192
210
|
).query)
|
|
193
211
|
auth_code = params['code'][0]
|
|
194
|
-
except
|
|
212
|
+
except KeyError:
|
|
213
|
+
self._log_requests(host_response, error=True)
|
|
195
214
|
raise PytolinoException('oauth code request failed.')
|
|
196
215
|
|
|
197
216
|
# Fetch OAUTH access token
|
|
@@ -510,7 +529,8 @@ class Client(object):
|
|
|
510
529
|
|
|
511
530
|
:book_id: id of the book on the serveer
|
|
512
531
|
:filepath: path to the cover file
|
|
513
|
-
:file_ext: png, jpg or jpeg. only necessary if the
|
|
532
|
+
:file_ext: png, jpg or jpeg. only necessary if the
|
|
533
|
+
filepath has no extension
|
|
514
534
|
|
|
515
535
|
"""
|
|
516
536
|
|
|
@@ -525,8 +545,8 @@ class Client(object):
|
|
|
525
545
|
|
|
526
546
|
host_response = self.session.post(
|
|
527
547
|
self.server_settings['cover_url'],
|
|
528
|
-
files
|
|
529
|
-
data
|
|
548
|
+
files=[('file', ('1092560016', open(filepath, 'rb'), mime))],
|
|
549
|
+
data={'deliverableId': book_id},
|
|
530
550
|
headers={
|
|
531
551
|
't_auth_token': self.access_token,
|
|
532
552
|
'hardware_id': self.hardware_id,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pytolino/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pytolino/servers_settings.ini,sha256=IDhstCWbLHaMj3qEOYcbDABaIUKHIz1jEBke3uSE8bI,1473
|
|
3
|
+
pytolino/tolino_cloud.py,sha256=K3eeV2Zj6IgyoGEhCerTnawBJkOm8aUhz4ZrojQUayQ,20072
|
|
4
|
+
pytolino-1.7.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
+
pytolino-1.7.dist-info/METADATA,sha256=UsWaJ9s46hClOr2k6rKSwNPjCUTmEJ6nF82JAvVC1r4,3725
|
|
6
|
+
pytolino-1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
pytolino-1.7.dist-info/top_level.txt,sha256=3stGCqihEMMqlWGkME45OTJ0Prg-FO_kl554rtYNeuU,9
|
|
8
|
+
pytolino-1.7.dist-info/RECORD,,
|
pytolino-1.6.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pytolino/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
pytolino/servers_settings.ini,sha256=IDhstCWbLHaMj3qEOYcbDABaIUKHIz1jEBke3uSE8bI,1473
|
|
3
|
-
pytolino/tolino_cloud.py,sha256=HwrEil5FT-L-4jebc4mC9ThdlgEUGIGc719wqbJpBdY,19239
|
|
4
|
-
pytolino-1.6.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
-
pytolino-1.6.dist-info/METADATA,sha256=FkfXV1lncQyg66TrLTI_l_rGLQ2VjBq6CCuB-MUMvks,3725
|
|
6
|
-
pytolino-1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
pytolino-1.6.dist-info/top_level.txt,sha256=3stGCqihEMMqlWGkME45OTJ0Prg-FO_kl554rtYNeuU,9
|
|
8
|
-
pytolino-1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|