sgqlc 1__tar.gz → 3__tar.gz

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.
Files changed (35) hide show
  1. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL}/bin/sgqlc-codegen +6 -2
  2. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/endpoint/http.py +76 -14
  3. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/types/__init__.py +2 -2
  4. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/types/datetime.py +10 -10
  5. {sgqlc-1/sgqlc.egg-info → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages/sgqlc-3-py3.7.egg-info}/PKG-INFO +4 -3
  6. sgqlc-1/AUTHORS +0 -1
  7. sgqlc-1/LICENSE +0 -17
  8. sgqlc-1/MANIFEST.in +0 -6
  9. sgqlc-1/PKG-INFO +0 -442
  10. sgqlc-1/README.rst +0 -421
  11. sgqlc-1/doc/source/_static/.keepme +0 -0
  12. sgqlc-1/doc/source/conf.py +0 -168
  13. sgqlc-1/doc/source/index.rst +0 -20
  14. sgqlc-1/doc/source/sgqlc.endpoint.base.rst +0 -9
  15. sgqlc-1/doc/source/sgqlc.endpoint.http.rst +0 -8
  16. sgqlc-1/doc/source/sgqlc.endpoint.rst +0 -13
  17. sgqlc-1/doc/source/sgqlc.operation.rst +0 -8
  18. sgqlc-1/doc/source/sgqlc.rst +0 -8
  19. sgqlc-1/doc/source/sgqlc.types.datetime.rst +0 -8
  20. sgqlc-1/doc/source/sgqlc.types.relay.rst +0 -8
  21. sgqlc-1/doc/source/sgqlc.types.rst +0 -14
  22. sgqlc-1/setup.cfg +0 -40
  23. sgqlc-1/setup.py +0 -57
  24. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/__init__.py +0 -0
  25. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/endpoint/__init__.py +0 -0
  26. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/endpoint/base.py +0 -0
  27. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/introspection/__init__.py +0 -0
  28. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/introspection/__main__.py +0 -0
  29. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/operation/__init__.py +0 -0
  30. {sgqlc-1 → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages}/sgqlc/types/relay.py +0 -0
  31. {sgqlc-1/sgqlc.egg-info → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages/sgqlc-3-py3.7.egg-info}/SOURCES.txt +0 -0
  32. {sgqlc-1/sgqlc.egg-info → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages/sgqlc-3-py3.7.egg-info}/dependency_links.txt +0 -0
  33. {sgqlc-1/sgqlc.egg-info → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages/sgqlc-3-py3.7.egg-info}/requires.txt +0 -0
  34. {sgqlc-1/sgqlc.egg-info → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages/sgqlc-3-py3.7.egg-info}/top_level.txt +0 -0
  35. {sgqlc-1/sgqlc.egg-info → Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/lib/python3.7/site-packages/sgqlc-3-py3.7.egg-info}/zip-safe +0 -0
@@ -1,7 +1,8 @@
1
- #!/usr/bin/env python3
1
+ #!/Users/gustavo/.local/share/virtualenvs/sgqlc-LJ804sPL/bin/python3
2
2
 
3
3
  import argparse
4
4
  import json
5
+ import keyword
5
6
  import os
6
7
  import os.path
7
8
  import sys
@@ -193,7 +194,10 @@ class %(name)s(sgqlc.types.Enum):
193
194
  s = []
194
195
  for w in cls.re_camel_case_words.findall(name):
195
196
  s.append(w.lower())
196
- return '_'.join(s)
197
+ name = '_'.join(s)
198
+ if keyword.iskeyword(name):
199
+ return name + '_'
200
+ return name
197
201
 
198
202
  def get_type_ref(self, t):
199
203
  kind = t['kind']
@@ -24,11 +24,41 @@ __all__ = ('HTTPEndpoint',)
24
24
  import json
25
25
  import logging
26
26
  import urllib.error
27
+ import urllib.parse
27
28
  import urllib.request
28
29
 
29
30
  from .base import BaseEndpoint
30
31
 
31
32
 
33
+ def add_query_to_url(url, extra_query):
34
+ '''Adds an extra query to URL, returning the new URL.
35
+
36
+ Extra query may be a dict or a list as returned by
37
+ :func:`urllib.parse.parse_qsl()` and :func:`urllib.parse.parse_qs()`.
38
+
39
+ '''
40
+ split = urllib.parse.urlsplit(url)
41
+ merged_query = urllib.parse.parse_qsl(split.query)
42
+ if isinstance(extra_query, dict):
43
+ for k, v in extra_query.items():
44
+ if not isinstance(v, (tuple, list)):
45
+ merged_query.append((k, v))
46
+ else:
47
+ for cv in v:
48
+ merged_query.append((k, cv))
49
+ else:
50
+ merged_query.extend(extra_query)
51
+
52
+ merged_split = urllib.parse.SplitResult(
53
+ split.scheme,
54
+ split.netloc,
55
+ split.path,
56
+ urllib.parse.urlencode(merged_query),
57
+ split.fragment,
58
+ )
59
+ return merged_split.geturl()
60
+
61
+
32
62
  class HTTPEndpoint(BaseEndpoint):
33
63
  '''GraphQL access over HTTP.
34
64
 
@@ -67,7 +97,8 @@ class HTTPEndpoint(BaseEndpoint):
67
97
 
68
98
  logger = logging.getLogger(__name__)
69
99
 
70
- def __init__(self, url, base_headers=None, timeout=None, urlopen=None):
100
+ def __init__(self, url, base_headers=None, timeout=None, urlopen=None,
101
+ method='POST'):
71
102
  '''
72
103
  :param url: the default GraphQL endpoint url.
73
104
  :type url: str
@@ -87,10 +118,12 @@ class HTTPEndpoint(BaseEndpoint):
87
118
  self.base_headers = base_headers or {}
88
119
  self.timeout = timeout
89
120
  self.urlopen = urlopen or urllib.request.urlopen
121
+ self.method = method
90
122
 
91
123
  def __str__(self):
92
- return '%s(url=%s, base_headers=%r, timeout=%r)' % (
93
- self.__class__.__name__, self.url, self.base_headers, self.timeout)
124
+ return '%s(url=%s, base_headers=%r, timeout=%r, method=%s)' % (
125
+ self.__class__.__name__, self.url, self.base_headers, self.timeout,
126
+ self.method)
94
127
 
95
128
  def __call__(self, query, variables=None, operation_name=None,
96
129
  extra_headers=None, timeout=None):
@@ -129,26 +162,25 @@ class HTTPEndpoint(BaseEndpoint):
129
162
  # and generate compact representation of the queries
130
163
  query = bytes(query).decode('utf-8')
131
164
 
132
- post_data = json.dumps({
133
- 'query': query,
134
- 'variables': variables,
135
- 'operationName': operation_name,
136
- }).encode('utf-8')
137
165
  headers = self.base_headers.copy()
138
166
  if extra_headers:
139
167
  headers.update(extra_headers)
168
+
140
169
  headers.update({
141
170
  'Accept': 'application/json; charset=utf-8',
142
- 'Content-Type': 'application/json; charset=utf-8',
143
- 'Content-Length': len(post_data),
144
171
  })
145
172
 
173
+ if self.method.upper() == 'POST':
174
+ get_http_request = self.get_http_post_request
175
+ else:
176
+ get_http_request = self.get_http_get_request
177
+
178
+ req = get_http_request(query, variables, operation_name, headers)
179
+
146
180
  self.logger.debug('Query:\n%s', query)
147
181
 
148
- req = urllib.request.Request(
149
- url=self.url, data=post_data, headers=headers)
150
182
  try:
151
- with urllib.request.urlopen(req, timeout=timeout) as f:
183
+ with self.urlopen(req, timeout=timeout or self.timeout) as f:
152
184
  body = f.read().decode('utf-8')
153
185
  try:
154
186
  data = json.loads(body)
@@ -160,6 +192,30 @@ class HTTPEndpoint(BaseEndpoint):
160
192
  except urllib.error.HTTPError as exc:
161
193
  return self._log_http_error(query, req, exc)
162
194
 
195
+ def get_http_post_request(self, query, variables, operation_name, headers):
196
+ post_data = json.dumps({
197
+ 'query': query,
198
+ 'variables': variables,
199
+ 'operationName': operation_name,
200
+ }).encode('utf-8')
201
+ headers.update({
202
+ 'Content-Type': 'application/json; charset=utf-8',
203
+ 'Content-Length': len(post_data),
204
+ })
205
+ return urllib.request.Request(
206
+ url=self.url, data=post_data, headers=headers, method='POST')
207
+
208
+ def get_http_get_request(self, query, variables, operation_name, headers):
209
+ params = {'query': query}
210
+ if operation_name:
211
+ params['operationName'] = operation_name
212
+
213
+ if variables:
214
+ params['variables'] = json.dumps(variables)
215
+
216
+ url = add_query_to_url(self.url, params)
217
+ return urllib.request.Request(url=url, headers=headers, method='GET')
218
+
163
219
  def _log_http_error(self, query, req, exc):
164
220
  '''Log :exc:`urllib.error.HTTPError`, converting to
165
221
  GraphQL's ``{"data": null, "errors": [{"message": str(exc)...}]}``
@@ -240,13 +296,19 @@ if __name__ == '__main__':
240
296
  help='Increase verbosity',
241
297
  action='count',
242
298
  default=0)
299
+ ap.add_argument('--method', '-m',
300
+ choices=['GET', 'POST'],
301
+ help='HTTP Method to use',
302
+ default='POST',
303
+ )
243
304
 
244
305
  args = ap.parse_args()
245
306
 
246
307
  logfmt = '%(levelname)s: %(message)s'
247
308
  logging.basicConfig(format=logfmt, level=max(10, 40 - (args.verbose * 10)))
248
309
 
249
- endpoint = HTTPEndpoint(args.url, dict(args.header), args.timeout)
310
+ endpoint = HTTPEndpoint(args.url, dict(args.header), args.timeout,
311
+ method=args.method)
250
312
  data = endpoint(args.query, dict(args.var))
251
313
 
252
314
  json.dump(data, sys.stdout, sort_keys=True, indent=2, default=str)
@@ -1432,7 +1432,7 @@ class ContainerTypeMeta(BaseMeta):
1432
1432
  if not isinstance(field, Lazy):
1433
1433
  try:
1434
1434
  field = BaseType.__ensure__(field)
1435
- except TypeError as e:
1435
+ except TypeError:
1436
1436
  continue
1437
1437
 
1438
1438
  field = Field(field)
@@ -1779,7 +1779,7 @@ class BaseItem:
1779
1779
  if not self.graphql_name:
1780
1780
  self.graphql_name = self._to_graphql_name(name)
1781
1781
 
1782
- @property
1782
+ @property # noqa: A003
1783
1783
  def type(self):
1784
1784
  if not isinstance(self._type, Lazy):
1785
1785
  return self._type
@@ -49,11 +49,11 @@ type MyDateTimeType {
49
49
  >>> for field_name in obj: # doctest: +ELLIPSIS
50
50
  ... print(field_name, repr(obj[field_name]))
51
51
  time1 datetime.time(12, 34, 56)
52
- time2 datetime.time(12, 34, 56, tzinfo=...(-1, 75600)))
52
+ time2 datetime.time(12, 34, 56, tzinfo=...(days=-1, seconds=75600)))
53
53
  date1 datetime.date(2018, 1, 2)
54
54
  date2 datetime.date(2018, 1, 2)
55
55
  datetime1 datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=....utc)
56
- datetime2 datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(-1, 75600)))
56
+ datetime2 datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...seconds=75600)))
57
57
 
58
58
  Pre-converted types are allowed:
59
59
 
@@ -104,17 +104,17 @@ class Time(Scalar):
104
104
  >>> Time('12:34:56Z') # Z = GMT/UTC
105
105
  datetime.time(12, 34, 56, tzinfo=datetime.timezone.utc)
106
106
  >>> Time('12:34:56-05:30') # doctest: +ELLIPSIS
107
- datetime.time(12, 34, 56, tzinfo=...(-1, 70200)))
107
+ datetime.time(12, 34, 56, tzinfo=...(days=-1, seconds=70200)))
108
108
  >>> Time('12:34:56+05:30') # doctest: +ELLIPSIS
109
- datetime.time(12, 34, 56, tzinfo=...(0, 19800)))
109
+ datetime.time(12, 34, 56, tzinfo=...(seconds=19800)))
110
110
  >>> Time('123456') # compact form
111
111
  datetime.time(12, 34, 56)
112
112
  >>> Time('123456Z') # compact form, GMT/UTC
113
113
  datetime.time(12, 34, 56, tzinfo=datetime.timezone.utc)
114
114
  >>> Time('123456-0530') # doctest: +ELLIPSIS
115
- datetime.time(12, 34, 56, tzinfo=...(-1, 70200)))
115
+ datetime.time(12, 34, 56, tzinfo=...(days=-1, seconds=70200)))
116
116
  >>> Time('123456+0530') # doctest: +ELLIPSIS
117
- datetime.time(12, 34, 56, tzinfo=...(0, 19800)))
117
+ datetime.time(12, 34, 56, tzinfo=...(seconds=19800)))
118
118
 
119
119
  Pre-converted values are allowed:
120
120
 
@@ -216,17 +216,17 @@ class DateTime(Scalar):
216
216
  >>> DateTime('2018-01-02T12:34:56Z') # Z = GMT/UTC
217
217
  datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=datetime.timezone.utc)
218
218
  >>> DateTime('2018-01-02T12:34:56-05:30') # doctest: +ELLIPSIS
219
- datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(-1, 70200)))
219
+ datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=..., seconds=70200)))
220
220
  >>> DateTime('2018-01-02T12:34:56+05:30') # doctest: +ELLIPSIS
221
- datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(0, 19800)))
221
+ datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(seconds=19800)))
222
222
  >>> DateTime('20180102T123456') # compact form
223
223
  datetime.datetime(2018, 1, 2, 12, 34, 56)
224
224
  >>> DateTime('20180102T123456Z') # compact form, GMT/UTC
225
225
  datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=datetime.timezone.utc)
226
226
  >>> DateTime('20180102T123456-0530') # doctest: +ELLIPSIS
227
- datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(-1, 70200)))
227
+ datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=..., seconds=70200)))
228
228
  >>> DateTime('20180102T123456+0530') # doctest: +ELLIPSIS
229
- datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(0, 19800)))
229
+ datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(seconds=19800)))
230
230
 
231
231
  Pre-converted values are allowed:
232
232
 
@@ -1,12 +1,11 @@
1
- Metadata-Version: 1.2
1
+ Metadata-Version: 2.1
2
2
  Name: sgqlc
3
- Version: 1
3
+ Version: 3
4
4
  Summary: Simple GraphQL Client
5
5
  Home-page: http://github.com/profusion/sgqlc
6
6
  Author: Gustavo Sverzut Barbieri
7
7
  Author-email: barbieri@profusion.mobi
8
8
  License: ISCL
9
- Description-Content-Type: UNKNOWN
10
9
  Description: `sgqlc` - Simple GraphQL Client
11
10
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12
11
 
@@ -440,3 +439,5 @@ Classifier: Operating System :: OS Independent
440
439
  Classifier: Programming Language :: Python
441
440
  Classifier: Topic :: Utilities
442
441
  Requires-Python: >=3.6
442
+ Description-Content-Type: text/x-rst
443
+ Provides-Extra: sphinx
sgqlc-1/AUTHORS DELETED
@@ -1 +0,0 @@
1
- Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
sgqlc-1/LICENSE DELETED
@@ -1,17 +0,0 @@
1
- Copyright 2018 ProFUSION Sistemas e Solucoes LTDA
2
-
3
- Permission to use, copy, modify, and/or distribute this software for
4
- any purpose with or without fee is hereby granted, provided that the
5
- above copyright notice and this permission notice appear in all
6
- copies.
7
-
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10
- WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11
- WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12
- AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14
- PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15
- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
- PERFORMANCE OF THIS SOFTWARE.
17
-
sgqlc-1/MANIFEST.in DELETED
@@ -1,6 +0,0 @@
1
- include README.rst
2
- include LICENSE
3
- include AUTHORS
4
- recursive-include doc/source *
5
- prune doc/source/__pycache__
6
- global-exclude *~