gazu 0.10.10__py2.py3-none-any.whl → 0.10.12__py2.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.
gazu/__init__.py CHANGED
@@ -120,9 +120,8 @@ def set_token(token, client=raw.default_client):
120
120
  Args:
121
121
  new_tokens (dict): Tokens to use for authentication.
122
122
  """
123
- tokens = {}
123
+
124
124
  if isinstance(token, dict):
125
- tokens["access_token"] = token["access_token"]
125
+ return raw.set_tokens(token, client=client)
126
126
  else:
127
- tokens["access_token"] = token
128
- return raw.set_tokens(tokens, client=client)
127
+ return raw.set_tokens({"access_token": token}, client=client)
gazu/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.10.10"
1
+ __version__ = "0.10.12"
gazu/client.py CHANGED
@@ -20,6 +20,7 @@ from .exception import (
20
20
  UploadFailedException,
21
21
  )
22
22
 
23
+
23
24
  if sys.version_info[0] == 3:
24
25
  from json import JSONDecodeError
25
26
  else:
@@ -29,17 +30,38 @@ DEBUG = os.getenv("GAZU_DEBUG", "false").lower() == "true"
29
30
 
30
31
 
31
32
  class KitsuClient(object):
32
- def __init__(self, host, ssl_verify=True, cert=None):
33
+ def __init__(
34
+ self,
35
+ host,
36
+ ssl_verify=True,
37
+ cert=None,
38
+ automatic_refresh_token=False,
39
+ callback_not_authenticated=None,
40
+ ):
33
41
  self.tokens = {"access_token": "", "refresh_token": ""}
34
42
  self.session = requests.Session()
35
43
  self.session.verify = ssl_verify
36
44
  self.session.cert = cert
37
45
  self.host = host
38
46
  self.event_host = host
39
-
40
-
41
- def create_client(host, ssl_verify=True, cert=None):
42
- return KitsuClient(host, ssl_verify, cert=None)
47
+ self.automatic_refresh_token = automatic_refresh_token
48
+ self.callback_not_authenticated = callback_not_authenticated
49
+
50
+
51
+ def create_client(
52
+ host,
53
+ ssl_verify=True,
54
+ cert=None,
55
+ automatic_refresh_token=False,
56
+ callback_not_authenticated=None,
57
+ ):
58
+ return KitsuClient(
59
+ host,
60
+ ssl_verify,
61
+ cert=cert,
62
+ automatic_refresh_token=automatic_refresh_token,
63
+ callback_not_authenticated=callback_not_authenticated,
64
+ )
43
65
 
44
66
 
45
67
  default_client = None
@@ -199,11 +221,13 @@ def get(path, json_response=True, params=None, client=default_client):
199
221
  if DEBUG:
200
222
  print("GET", get_full_url(path, client))
201
223
  path = build_path_with_params(path, params)
202
- response = client.session.get(
203
- get_full_url(path, client=client),
204
- headers=make_auth_header(client=client),
205
- )
206
- check_status(response, path)
224
+ retry = True
225
+ while retry:
226
+ response = client.session.get(
227
+ get_full_url(path, client=client),
228
+ headers=make_auth_header(client=client),
229
+ )
230
+ _, retry = check_status(response, path, client=client)
207
231
 
208
232
  if json_response:
209
233
  return response.json()
@@ -222,12 +246,14 @@ def post(path, data, client=default_client):
222
246
  print("POST", get_full_url(path, client))
223
247
  if not "password" in data:
224
248
  print("Body:", data)
225
- response = client.session.post(
226
- get_full_url(path, client),
227
- json=data,
228
- headers=make_auth_header(client=client),
229
- )
230
- check_status(response, path)
249
+ retry = True
250
+ while retry:
251
+ response = client.session.post(
252
+ get_full_url(path, client),
253
+ json=data,
254
+ headers=make_auth_header(client=client),
255
+ )
256
+ _, retry = check_status(response, path, client=client)
231
257
  try:
232
258
  result = response.json()
233
259
  except JSONDecodeError:
@@ -246,12 +272,14 @@ def put(path, data, client=default_client):
246
272
  if DEBUG:
247
273
  print("PUT", get_full_url(path, client))
248
274
  print("Body:", data)
249
- response = client.session.put(
250
- get_full_url(path, client),
251
- json=data,
252
- headers=make_auth_header(client=client),
253
- )
254
- check_status(response, path)
275
+ retry = True
276
+ while retry:
277
+ response = client.session.put(
278
+ get_full_url(path, client),
279
+ json=data,
280
+ headers=make_auth_header(client=client),
281
+ )
282
+ _, retry = check_status(response, path, client=client)
255
283
  return response.json()
256
284
 
257
285
 
@@ -266,14 +294,16 @@ def delete(path, params=None, client=default_client):
266
294
  print("DELETE", get_full_url(path, client))
267
295
  path = build_path_with_params(path, params)
268
296
 
269
- response = client.session.delete(
270
- get_full_url(path, client), headers=make_auth_header(client=client)
271
- )
272
- check_status(response, path)
297
+ retry = True
298
+ while retry:
299
+ response = client.session.delete(
300
+ get_full_url(path, client), headers=make_auth_header(client=client)
301
+ )
302
+ _, retry = check_status(response, path, client=client)
273
303
  return response.text
274
304
 
275
305
 
276
- def check_status(request, path):
306
+ def check_status(request, path, client=None):
277
307
  """
278
308
  Raise an exception related to status code, if the status code does not
279
309
  match a success code. Print error message when it's relevant.
@@ -309,7 +339,24 @@ def check_status(request, path):
309
339
  "Change your proxy configuration to allow bigger files." % path
310
340
  )
311
341
  elif status_code in [401, 422]:
312
- raise NotAuthenticatedException(path)
342
+ try:
343
+ if client is not None and client.automatic_refresh_token:
344
+ from . import refresh_token
345
+
346
+ refresh_token(client=client)
347
+
348
+ return status_code, True
349
+ else:
350
+ raise NotAuthenticatedException(path)
351
+ except NotAuthenticatedException:
352
+ if (
353
+ client is not None
354
+ and client.callback_not_authenticated is not None
355
+ ):
356
+ retry = client.callback_not_authenticated(client, path)
357
+ if retry:
358
+ return status_code, True
359
+ raise
313
360
  elif status_code in [500, 502]:
314
361
  try:
315
362
  stacktrace = request.json().get(
@@ -324,7 +371,7 @@ def check_status(request, path):
324
371
  except Exception:
325
372
  print(request.text)
326
373
  raise ServerErrorException(path)
327
- return status_code
374
+ return status_code, False
328
375
 
329
376
 
330
377
  def fetch_all(path, params=None, client=default_client):
@@ -413,10 +460,15 @@ def upload(path, file_path, data={}, extra_files=[], client=default_client):
413
460
  """
414
461
  url = get_full_url(path, client)
415
462
  files = _build_file_dict(file_path, extra_files)
416
- response = client.session.post(
417
- url, data=data, headers=make_auth_header(client=client), files=files
418
- )
419
- check_status(response, path)
463
+ retry = True
464
+ while retry:
465
+ response = client.session.post(
466
+ url,
467
+ data=data,
468
+ headers=make_auth_header(client=client),
469
+ files=files,
470
+ )
471
+ _, retry = check_status(response, path, client=client)
420
472
  try:
421
473
  result = response.json()
422
474
  except JSONDecodeError:
@@ -465,12 +517,14 @@ def get_file_data_from_url(url, full=False, client=default_client):
465
517
  """
466
518
  if not full:
467
519
  url = get_full_url(url)
468
- response = requests.get(
469
- url,
470
- stream=True,
471
- headers=make_auth_header(client=client),
472
- )
473
- check_status(response, url)
520
+ retry = True
521
+ while retry:
522
+ response = requests.get(
523
+ url,
524
+ stream=True,
525
+ headers=make_auth_header(client=client),
526
+ )
527
+ _, retry = check_status(response, url, client=client)
474
528
  return response.content
475
529
 
476
530
 
gazu/task.py CHANGED
@@ -582,6 +582,40 @@ def remove_task_status(task_status, client=default):
582
582
  )
583
583
 
584
584
 
585
+ def update_task_type(task_type, client=default):
586
+ """
587
+ Update given task type into the API.
588
+
589
+ Args:
590
+ task_type (dict): The task type dict to update.
591
+
592
+ Returns:
593
+ dict: Updated task type.
594
+ """
595
+ return raw.put(
596
+ "data/task-types/%s" % task_type["id"],
597
+ task_type,
598
+ client=client,
599
+ )
600
+
601
+
602
+ def update_task_status(task_status, client=default):
603
+ """
604
+ Update given task status into the API.
605
+
606
+ Args:
607
+ task_status (dict): The task status dict to update.
608
+
609
+ Returns:
610
+ dict: Updated task status.
611
+ """
612
+ return raw.put(
613
+ "data/task-status/%s" % task_status["id"],
614
+ task_status,
615
+ client=client,
616
+ )
617
+
618
+
585
619
  @cache
586
620
  def get_task(task_id, client=default):
587
621
  """
@@ -1166,7 +1200,7 @@ def new_task_status(name, short_name, color, client=default):
1166
1200
 
1167
1201
  def update_task(task, client=default):
1168
1202
  """
1169
- Save given task data into the API. Metadata are fully replaced by the ones
1203
+ Update given task into the API. Metadata are fully replaced by the ones
1170
1204
  set on given task.
1171
1205
 
1172
1206
  Args:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gazu
3
- Version: 0.10.10
3
+ Version: 0.10.12
4
4
  Summary: Gazu is a client for Zou, the API to store the data of your CG production.
5
5
  Home-page: https://gazu.cg-wire.com/
6
6
  Author: CG Wire
@@ -1,9 +1,9 @@
1
- gazu/__init__.py,sha256=cek7Vq4FrzBIzMvtAjlL-3af5TOVLWywYBSMQQWuYec,3056
2
- gazu/__version__.py,sha256=Aktsk85UlRwldAMwi5D3o9k6UTyqVYYJbSK_i8y26sE,24
1
+ gazu/__init__.py,sha256=gVhtpZsvDiPuqvsEbCrgm6fKw8hluUhqspmlgGNIAvQ,3020
2
+ gazu/__version__.py,sha256=8HmqcalKYluoRM1nCmpntcjsFDeqXAb5Cl0wcMuiFY0,24
3
3
  gazu/asset.py,sha256=GWwam0yqHna_b9_5g5r0-O2zhMb7KlhfbIC17IOXKkY,14488
4
4
  gazu/cache.py,sha256=MnxrnfYN7wHNTTL7qzkEpYCYzWcolT56fqQ0_RegMbE,5879
5
5
  gazu/casting.py,sha256=5xmGMoU3MFgv1br8_5xyTx-Z7wo9r51wRisiblqcr94,3945
6
- gazu/client.py,sha256=wgilPeAAF2D3heOfRkZdMUjR1QzWaFs7vmlEKSjNxsg,13032
6
+ gazu/client.py,sha256=YRIxX7u095XTe28JM0tMZ05WoTcYexJGS2jrxXSAQvs,14640
7
7
  gazu/concept.py,sha256=GcOPEmkbtZcSwlX8tnUj9Q5DTPBprSxtmXhlq7ioPwk,3727
8
8
  gazu/context.py,sha256=iUyug8EUz3kkF-kmYlH5JuLp66TUqR3uhAq7CouVd_U,4349
9
9
  gazu/edit.py,sha256=sPSsnzykGr1Htl6ceKulUSVHGhoQLGLeWDni3Pul7BE,4609
@@ -20,10 +20,10 @@ gazu/scene.py,sha256=bYsy7zKdQfDTfeqNAlgaqGMs2Hhxdy40NGt6TX_FBdA,5307
20
20
  gazu/shot.py,sha256=4fmMj4vWb4VMg92tfRDP5lqjSwip3Yv9lPrKerv_oUM,18850
21
21
  gazu/sorting.py,sha256=qSIO0pOHkj0Tl4gm9BJrYrcifWGGGmsW68Pl86zB_bg,266
22
22
  gazu/sync.py,sha256=OMsbQDROTdEwlukazUXPGnlC29QcaaHvsmqv3WsSexo,21582
23
- gazu/task.py,sha256=4aO8Ggk4lagVaNkFIdFE0-HnCcWg6d38BTFuwlqbyRY,35193
23
+ gazu/task.py,sha256=7A3A_Zms4WlFl72Jqi2u8dWcoVY3d81leFWAE8wOdQQ,35883
24
24
  gazu/user.py,sha256=GyJf6mrynHvLllw3Hsiv-6wjaYTHO_PBNkJzyJjJA1A,9556
25
- gazu-0.10.10.dist-info/LICENSE,sha256=2n6rt7r999OuXp8iOqW9we7ORaxWncIbOwN1ILRGR2g,7651
26
- gazu-0.10.10.dist-info/METADATA,sha256=L-Y-tTqDlvxkwmzjgby8xq_iWk8s1K_83oinzrXTuDg,5182
27
- gazu-0.10.10.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
28
- gazu-0.10.10.dist-info/top_level.txt,sha256=nv7fRIVpYYyIlk_66hBmMyvWcSC7UU-r-GE8uC1u1Go,5
29
- gazu-0.10.10.dist-info/RECORD,,
25
+ gazu-0.10.12.dist-info/LICENSE,sha256=2n6rt7r999OuXp8iOqW9we7ORaxWncIbOwN1ILRGR2g,7651
26
+ gazu-0.10.12.dist-info/METADATA,sha256=khWS9mumUPINWXh353r625F8C_Z-xgmro-Jrk0KZ2v4,5182
27
+ gazu-0.10.12.dist-info/WHEEL,sha256=XRxW4r1PNiVhMpP4bT9oWtu3HyndxpJ84SkubFgzp_Y,109
28
+ gazu-0.10.12.dist-info/top_level.txt,sha256=nv7fRIVpYYyIlk_66hBmMyvWcSC7UU-r-GE8uC1u1Go,5
29
+ gazu-0.10.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any