PyLinks 0.0.0.dev39__py3-none-any.whl → 0.0.0.dev40__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.
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyLinks
3
- Version: 0.0.0.dev39
3
+ Version: 0.0.0.dev40
4
4
  Requires-Python: >=3.10
5
5
  Requires-Dist: requests <3,>=2.31.0
6
- Requires-Dist: ExceptionMan ==0.0.0.dev26
7
- Requires-Dist: MDit ==0.0.0.dev26
6
+ Requires-Dist: ExceptionMan ==0.0.0.dev27
7
+ Requires-Dist: MDit ==0.0.0.dev27
8
8
 
@@ -1,6 +1,6 @@
1
1
  pylinks/__init__.py,sha256=75Tgq2JiBuCPJWBTV4JNEEMBtKGw3pEk9jRnoW8KIDs,710
2
2
  pylinks/_settings.py,sha256=gC_S-EQJQNmXT73UWwEwnAZu5nlPrt9f39n99Xd9fFw,322
3
- pylinks/http.py,sha256=e7NBOV33tPbYXOC28SejDwxXmrlpC0336yZahCzTF1c,15161
3
+ pylinks/http.py,sha256=nG5eTSiC00O-vZCswd85WmXrE3-ATobHIeagSApcO48,15243
4
4
  pylinks/media_type.py,sha256=hyR1Ivr4Uo3SoYUQaY1vxQOM1ySpTd74qlwt1gky2OY,3923
5
5
  pylinks/string.py,sha256=yoORoiILKAKzzfDw-bwePBTwb3Shr_RvOSB2tdEZuSU,1397
6
6
  pylinks/url.py,sha256=4YzmNn0U1nzWmcdzEW6RKaZd5uu-MZRimHGl5Xi60Cg,7815
@@ -9,7 +9,7 @@ pylinks/api/doi.py,sha256=7YnMqy4_Ct2sw9Wz4mQC5S4xAahwh6fMUPKAx_qqj-M,5899
9
9
  pylinks/api/github.py,sha256=qsGpDUc5xJBYfl98NMwI4qNALKUOdeDJqXKts4l0rCc,73671
10
10
  pylinks/api/orcid.py,sha256=e0DAuziq7HdGJ4BJOI28mo1emB4_7gPsLxR7VsYPYMA,1377
11
11
  pylinks/exception/__init__.py,sha256=tU-LvaYi4NsLEZeeUN-JjemhefJ6R_DG37fIMoaZ5a4,89
12
- pylinks/exception/api.py,sha256=NbOTTxVO5_dhgEIA76xCb8mm1ILHs_nVCYUpQQ6DAec,5142
12
+ pylinks/exception/api.py,sha256=fLjWQFOUuO-2FDUgEetUHHl6BRryW3_BC2m6Z5sGh5c,5768
13
13
  pylinks/exception/base.py,sha256=dAHiss2J_Sq-4-SkFJHlYVFMw6n5BKGw2oxGFUCgmik,1504
14
14
  pylinks/exception/media_type.py,sha256=QHpXO4GWG_63kZfTkOrTCuOPnKaZ191swvgy6biO_o4,1027
15
15
  pylinks/exception/uri.py,sha256=wVpxsCWiavSyGoUE9ujPtNYaFcP5cuJZZfyGimK6jYs,576
@@ -22,7 +22,7 @@ pylinks/site/pypi.py,sha256=-NSglDo-k55bALi-aN0iF2I6z1WXsjYOIVDyjNUxuuU,1944
22
22
  pylinks/site/readthedocs.py,sha256=_s27ETa3oRoeDdQvFrrtuSh2my6cjWEIEVhwHz0yZ90,1797
23
23
  pylinks/uri/__init__.py,sha256=W38fMHGgV7mg8uPWC8IMWGgmlCQO9VHIqNpInG2NS2I,29
24
24
  pylinks/uri/data.py,sha256=uD1CipMo4oFpxH8liOY24PsxMyuR5kEH2a0XDkO1dgI,6380
25
- PyLinks-0.0.0.dev39.dist-info/METADATA,sha256=uF0gtM-K0B0TxMkoLWSmGEGA8YJin6mgfldhoVsPqds,194
26
- PyLinks-0.0.0.dev39.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
27
- PyLinks-0.0.0.dev39.dist-info/top_level.txt,sha256=LlaTHnPw89VppYU3vCciF81IOSzvc16RkdNkOCqhAcs,8
28
- PyLinks-0.0.0.dev39.dist-info/RECORD,,
25
+ PyLinks-0.0.0.dev40.dist-info/METADATA,sha256=qRbeM5fRryXVpEc_RLyoJTR9gFpFqbsUoH4aM74VdF4,194
26
+ PyLinks-0.0.0.dev40.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
27
+ PyLinks-0.0.0.dev40.dist-info/top_level.txt,sha256=LlaTHnPw89VppYU3vCciF81IOSzvc16RkdNkOCqhAcs,8
28
+ PyLinks-0.0.0.dev40.dist-info/RECORD,,
pylinks/exception/api.py CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  from __future__ import annotations as _annotations
4
4
 
5
+ import json
5
6
  from typing import TYPE_CHECKING as _TYPE_CHECKING
6
7
 
7
8
  import mdit as _mdit
9
+ import json as _json
8
10
  from pylinks.exception import PyLinksError
9
11
 
10
12
  if _TYPE_CHECKING:
@@ -94,6 +96,26 @@ class WebAPIValueError(WebAPIError):
94
96
  return
95
97
 
96
98
 
99
+ class GraphQLResponseError(WebAPIError):
100
+ """
101
+ Exception class for GraphQL
102
+ """
103
+
104
+ def __init__(self, response: dict):
105
+ if "errors" in response:
106
+ intro = "GraphQL response contains errors."
107
+ elif "data" not in response:
108
+ intro = "GraphQL response does not contain data."
109
+ super().__init__(
110
+ title="GraphQL Response Error",
111
+ intro=intro,
112
+ details=_mdit.element.code_block(
113
+ json.dumps(response, indent=3), language="json", caption="GraphQL Response"
114
+ ),
115
+ )
116
+ return
117
+
118
+
97
119
  def _process_response(response: Response):
98
120
  # Decode error reason from server
99
121
  # This part is adapted from `requests` library; See PR #3538 on their GitHub
pylinks/http.py CHANGED
@@ -8,6 +8,8 @@ from typing import TYPE_CHECKING as _TYPE_CHECKING, NamedTuple as _NamedTuple
8
8
  import time
9
9
  from functools import wraps
10
10
  from pathlib import Path
11
+
12
+ import mdit as _mdit
11
13
  import requests
12
14
 
13
15
  from pylinks.exception import api as _exception
@@ -273,10 +275,11 @@ def graphql_query(
273
275
  args["json"]["variables"] = variables
274
276
  response = request(**args)
275
277
  if isinstance(response, dict):
278
+ error_title = "GraphQL API Error"
276
279
  if "errors" in response:
277
- raise _exception.WebAPIError(response)
280
+ raise _exception.GraphQLResponseError(response)
278
281
  elif "data" not in response:
279
- raise _exception.WebAPIError(response)
282
+ raise _exception.GraphQLResponseError(response)
280
283
  else:
281
284
  response = response["data"]
282
285
  return response