printnode-community 0.4.0__tar.gz → 0.4.1__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 (43) hide show
  1. {printnode_community-0.4.0 → printnode_community-0.4.1}/.idea/printnode_community.iml +1 -1
  2. {printnode_community-0.4.0 → printnode_community-0.4.1}/PKG-INFO +1 -1
  3. {printnode_community-0.4.0 → printnode_community-0.4.1}/committed/printnode_community-0.3.0-py3-none-any.whl +0 -0
  4. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/auth.py +4 -2
  5. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/computers.py +14 -11
  6. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/model.py +29 -23
  7. {printnode_community-0.4.0 → printnode_community-0.4.1}/pyproject.toml +1 -1
  8. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_computers.py +2 -1
  9. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  10. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  11. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  12. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/github.json +0 -0
  13. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/pull_request_template.md +0 -0
  14. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/workflows/ci.yml +0 -0
  15. {printnode_community-0.4.0 → printnode_community-0.4.1}/.github/workflows/publish.yml +0 -0
  16. {printnode_community-0.4.0 → printnode_community-0.4.1}/.gitignore +0 -0
  17. {printnode_community-0.4.0 → printnode_community-0.4.1}/.idea/.gitignore +0 -0
  18. {printnode_community-0.4.0 → printnode_community-0.4.1}/.idea/inspectionProfiles/Project_Default.xml +0 -0
  19. {printnode_community-0.4.0 → printnode_community-0.4.1}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
  20. {printnode_community-0.4.0 → printnode_community-0.4.1}/.idea/modules.xml +0 -0
  21. {printnode_community-0.4.0 → printnode_community-0.4.1}/.idea/vcs.xml +0 -0
  22. {printnode_community-0.4.0 → printnode_community-0.4.1}/AGENTS.md +0 -0
  23. {printnode_community-0.4.0 → printnode_community-0.4.1}/CONTRIBUTING.md +0 -0
  24. {printnode_community-0.4.0 → printnode_community-0.4.1}/LICENSE +0 -0
  25. {printnode_community-0.4.0 → printnode_community-0.4.1}/README.md +0 -0
  26. {printnode_community-0.4.0 → printnode_community-0.4.1}/SECURITY.md +0 -0
  27. {printnode_community-0.4.0 → printnode_community-0.4.1}/committed/.gitignore +0 -0
  28. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/__init__.py +0 -0
  29. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/accounts.py +0 -0
  30. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/gateway.py +0 -0
  31. {printnode_community-0.4.0 → printnode_community-0.4.1}/printnode_community/util.py +0 -0
  32. {printnode_community-0.4.0 → printnode_community-0.4.1}/renovate.json +0 -0
  33. {printnode_community-0.4.0 → printnode_community-0.4.1}/scripts/check-lockfile.sh +0 -0
  34. {printnode_community-0.4.0 → printnode_community-0.4.1}/scripts/pypi_release_decision.py +0 -0
  35. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/README.md +0 -0
  36. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/__init__.py +0 -0
  37. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_accounts.py +0 -0
  38. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_auth.py +0 -0
  39. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_imports.py +0 -0
  40. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_model.py +0 -0
  41. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_pypi_release_decision.py +0 -0
  42. {printnode_community-0.4.0 → printnode_community-0.4.1}/tests/test_util.py +0 -0
  43. {printnode_community-0.4.0 → printnode_community-0.4.1}/uv.lock +0 -0
@@ -4,7 +4,7 @@
4
4
  <content url="file://$MODULE_DIR$">
5
5
  <excludeFolder url="file://$MODULE_DIR$/.venv" />
6
6
  </content>
7
- <orderEntry type="jdk" jdkName="uv (printnode_community)" jdkType="Python SDK" />
7
+ <orderEntry type="inheritedJdk" />
8
8
  <orderEntry type="sourceFolder" forTests="false" />
9
9
  </component>
10
10
  <component name="PyDocumentationSettings">
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: printnode_community
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Community-maintained Python client for PrintNode's API
5
5
  Project-URL: Homepage, https://github.com/cbusillo/printnode_community
6
6
  Project-URL: Repository, https://github.com/cbusillo/printnode_community
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import os
3
3
  import re
4
+ from collections.abc import Callable
4
5
 
5
6
  import requests
6
7
 
@@ -66,7 +67,7 @@ class Auth:
66
67
  def delete(self, endpoint, request_headers=None):
67
68
  return self._request(requests.delete, endpoint, None, request_headers)
68
69
 
69
- def _request(self, method, endpoint, fields=None, request_headers=None):
70
+ def _request(self, method: Callable[..., requests.Response], endpoint, fields=None, request_headers=None):
70
71
  # request handling
71
72
 
72
73
  # :param method - requests.(get/post/patch/delete)
@@ -123,7 +124,8 @@ class Auth:
123
124
  else:
124
125
  raise Exception('status code: ' + str(response.status_code))
125
126
 
126
- def _is_hundreth(self, hundreth, number):
127
+ @staticmethod
128
+ def _is_hundreth(hundreth, number):
127
129
  pattern = str(hundreth) + r'\d{2,}'
128
130
  return bool(re.match(pattern, str(number)))
129
131
 
@@ -59,7 +59,7 @@ class Computers:
59
59
 
60
60
  return states
61
61
 
62
- def get_printers(self, computer=None, printer=None, limit=None, after=None, dir=None):
62
+ def get_printers(self, computer=None, printer=None, limit=None, after=None, dir=None) -> list[Printer] | Printer:
63
63
  """queries API for printers.
64
64
  the printer argument can be:
65
65
  * id of the printer, in which case a single printer is returned
@@ -117,11 +117,10 @@ class Computers:
117
117
  printers = self.get_printers(
118
118
  computer=computer,
119
119
  printer=printer)
120
- if self._is_multi_query(printer):
121
- if len(printers) == 0:
122
- return []
123
- else:
120
+ if isinstance(printers, Printer):
124
121
  printers = [printers]
122
+ elif len(printers) == 0:
123
+ return []
125
124
  printer_ids = [p.id for p in printers]
126
125
  printer_url = ','.join(map(str, printer_ids))
127
126
  url = '/printers/{}/printjobs'.format(printer_url)
@@ -229,7 +228,8 @@ class Computers:
229
228
  def _get_printjob_id(self, printjob):
230
229
  return self._get_model_id(printjob, PrintJob)
231
230
 
232
- def _get_model_id(self, model, model_type):
231
+ @staticmethod
232
+ def _get_model_id(model, model_type):
233
233
  if isinstance(model, int):
234
234
  return model
235
235
  elif isinstance(model, model_type):
@@ -237,7 +237,8 @@ class Computers:
237
237
  else:
238
238
  raise TypeError(str(type(model)))
239
239
 
240
- def _is_multi_query(self, obj):
240
+ @staticmethod
241
+ def _is_multi_query(obj):
241
242
  if obj is None:
242
243
  return True
243
244
  elif isinstance(obj, int):
@@ -249,7 +250,8 @@ class Computers:
249
250
  else:
250
251
  raise TypeError('type "{}" unsupported'.format(type(obj)))
251
252
 
252
- def _create_pagination_params(self, limit, after, dir):
253
+ @staticmethod
254
+ def _create_pagination_params(limit, after, page_direction):
253
255
  params = []
254
256
  if limit is not None:
255
257
  if isinstance(limit, int):
@@ -261,10 +263,11 @@ class Computers:
261
263
  params.append('after={}'.format(after))
262
264
  else:
263
265
  raise TypeError('after: "{}"'.format(type(after)))
264
- if dir is not None:
265
- if dir == 'asc' or dir == 'desc':
266
- params.append('dir={}'.format(dir))
266
+ if page_direction is not None:
267
+ if page_direction == 'asc' or page_direction == 'desc':
268
+ params.append('dir={}'.format(page_direction))
267
269
  else:
268
270
  raise TypeError("dir must equal 'asc' or 'desc'")
269
271
  if len(params) > 0:
270
272
  return '&'.join(params)
273
+ return None
@@ -18,6 +18,7 @@ def safe_tuple_populate(tuple_class, fields, defaults={}):
18
18
  assert isinstance(defaults, dict)
19
19
 
20
20
  fk = set(fields.keys())
21
+ # noinspection PyProtectedMember
21
22
  tk = set(tuple_class._fields)
22
23
 
23
24
  # add in missing fields using defaults if present
@@ -28,6 +29,7 @@ def safe_tuple_populate(tuple_class, fields, defaults={}):
28
29
  for key in (fk - tk):
29
30
  fields.pop(key)
30
31
 
32
+ # noinspection PyArgumentList
31
33
  return tuple_class(**fields)
32
34
 
33
35
 
@@ -102,31 +104,35 @@ class ModelFactory:
102
104
  fields = self._underscore_keys(state_dict)
103
105
  return safe_tuple_populate(State, fields)
104
106
 
105
- def _underscore_keys(self, input_dict):
107
+ @staticmethod
108
+ def _underscore_keys(input_dict):
106
109
  return {
107
110
  camel_to_underscore(k): v
108
111
  for k, v in input_dict.items()}
109
112
 
110
- def _rename_field(self, obj_dict, old_name, new_name):
113
+ @staticmethod
114
+ def _rename_field(obj_dict, old_name, new_name):
111
115
  if old_name not in obj_dict:
112
116
  return
113
117
  assert new_name not in obj_dict
114
118
  obj_dict[new_name] = obj_dict[old_name]
115
119
  del obj_dict[old_name]
116
120
 
117
- def _create_nested_model(self, fields, field_name, factory):
121
+ @staticmethod
122
+ def _create_nested_model(fields, field_name, factory):
118
123
  if field_name in fields and fields[field_name] is not None:
119
124
  fields[field_name] = factory(fields[field_name])
120
125
 
121
- def _map(self, f, iter):
122
- return list(map(f, iter))
126
+ @staticmethod
127
+ def _map(f, items):
128
+ return list(map(f, items))
123
129
 
124
130
 
125
131
  class Model:
126
132
  pass
127
133
 
128
134
 
129
- Account = namedtuple('Account', [
135
+ _AccountFields = namedtuple('Account', [
130
136
  'id',
131
137
  'firstname',
132
138
  'lastname',
@@ -146,11 +152,11 @@ Account = namedtuple('Account', [
146
152
  'permissions'])
147
153
 
148
154
 
149
- class Account(Account, Model):
155
+ class Account(_AccountFields, Model):
150
156
  pass
151
157
 
152
158
 
153
- Computer = namedtuple('Computer', [
159
+ _ComputerFields = namedtuple('Computer', [
154
160
  'id',
155
161
  'name',
156
162
  'inet',
@@ -161,11 +167,11 @@ Computer = namedtuple('Computer', [
161
167
  'state'])
162
168
 
163
169
 
164
- class Computer(Computer, Model):
170
+ class Computer(_ComputerFields, Model):
165
171
  pass
166
172
 
167
173
 
168
- Printer = namedtuple('Printer', [
174
+ _PrinterFields = namedtuple('Printer', [
169
175
  'id',
170
176
  'computer',
171
177
  'name',
@@ -176,11 +182,11 @@ Printer = namedtuple('Printer', [
176
182
  'state'])
177
183
 
178
184
 
179
- class Printer(Printer, Model):
185
+ class Printer(_PrinterFields, Model):
180
186
  pass
181
187
 
182
188
 
183
- PrintJob = namedtuple('PrintJob', [
189
+ _PrintJobFields = namedtuple('PrintJob', [
184
190
  'id',
185
191
  'printer',
186
192
  'title',
@@ -195,10 +201,10 @@ PrintJob = namedtuple('PrintJob', [
195
201
  'state'])
196
202
 
197
203
 
198
- class PrintJob(PrintJob, Model):
204
+ class PrintJob(_PrintJobFields, Model):
199
205
  pass
200
206
 
201
- Scale = namedtuple('Scale', [
207
+ _ScaleFields = namedtuple('Scale', [
202
208
  'measurement',
203
209
  'mass',
204
210
  'product',
@@ -215,10 +221,10 @@ Scale = namedtuple('Scale', [
215
221
  'ntp_offset'])
216
222
 
217
223
 
218
- class Scale(Scale, Model):
224
+ class Scale(_ScaleFields, Model):
219
225
  pass
220
226
 
221
- Client = namedtuple('Client', [
227
+ _ClientFields = namedtuple('Client', [
222
228
  'id',
223
229
  'enabled',
224
230
  'edition',
@@ -232,10 +238,10 @@ Client = namedtuple('Client', [
232
238
  ])
233
239
 
234
240
 
235
- class Client(Client, Model):
241
+ class Client(_ClientFields, Model):
236
242
  pass
237
243
 
238
- Download = namedtuple('Download', [
244
+ _DownloadFields = namedtuple('Download', [
239
245
  'edition',
240
246
  'version',
241
247
  'os',
@@ -247,10 +253,10 @@ Download = namedtuple('Download', [
247
253
  ])
248
254
 
249
255
 
250
- class Download(Download, Model):
256
+ class Download(_DownloadFields, Model):
251
257
  pass
252
258
 
253
- State = namedtuple('State', [
259
+ _StateFields = namedtuple('State', [
254
260
  'print_job_id',
255
261
  'state',
256
262
  'message',
@@ -261,10 +267,10 @@ State = namedtuple('State', [
261
267
  ])
262
268
 
263
269
 
264
- class State(State, Model):
270
+ class State(_StateFields, Model):
265
271
  pass
266
272
 
267
- Capabilities = namedtuple('Capabilities', [
273
+ _CapabilitiesFields = namedtuple('Capabilities', [
268
274
  'bins',
269
275
  'collate',
270
276
  'copies',
@@ -280,5 +286,5 @@ Capabilities = namedtuple('Capabilities', [
280
286
  ])
281
287
 
282
288
 
283
- class Capabilities(Capabilities, Model):
289
+ class Capabilities(_CapabilitiesFields, Model):
284
290
  pass
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "printnode_community"
7
- version = "0.4.0"
7
+ version = "0.4.1"
8
8
  description = "Community-maintained Python client for PrintNode's API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -164,6 +164,7 @@ def test_get_printer_by_id_returns_single_printer():
164
164
  result = computers.get_printers(printer=200)
165
165
 
166
166
  assert auth.get_calls == ['/printers/200']
167
+ assert isinstance(result, Printer)
167
168
  assert result.id == 200
168
169
 
169
170
 
@@ -176,7 +177,7 @@ def test_get_printer_by_model_instance_returns_single_printer():
176
177
 
177
178
  result = computers.get_printers(printer=printer)
178
179
 
179
- assert isinstance(printer, Printer)
180
+ assert isinstance(result, Printer)
180
181
  assert auth.get_calls == ['/printers/200']
181
182
  assert result.id == 200
182
183