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 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
- logging.info('-------------------- HTTP response --------------------')
47
- logging.info(f'status code: {host_response.status_code}')
48
- logging.info(f'cookies: {host_response.cookies}')
49
- logging.info(f'headers: {host_response.headers}')
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
- logging.debug(f'json: {j}')
57
+ logger(f'json: {j}')
53
58
  except requests.JSONDecodeError:
54
- logging.debug(f'text: {host_response.text}')
55
- logging.info('-------------------------------------------------------')
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.info('-------------------- HTTP response --------------------')
59
- logging.info(f'status code: {host_response.code}')
60
- logging.info(f'headers: {host_response.info()}')
61
- logging.info('-------------------------------------------------------')
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.info(self.server_settings['login_cookie'])
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 ValueError:
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 filepath has no extension
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 = [('file', ('1092560016', open(filepath, 'rb'), mime))],
529
- data = {'deliverableId': book_id},
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytolino
3
- Version: 1.6
3
+ Version: 1.7
4
4
  Summary: client for tolino cloud
5
5
  Author: Imam Usmani
6
6
  Project-URL: Source Code, https://github.com/ImamAzim/pytolino
@@ -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,,
@@ -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