capyy 0.3.1__tar.gz → 0.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capyy
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Tiny encrypted JSON-over-TCP APIs: call a function in another program, on your Wi-Fi or across the internet
5
5
  Author: Izac
6
6
  License-Expression: MIT
@@ -3,6 +3,7 @@
3
3
  import json as jsonlib # "json" est pris par capy.json()
4
4
  import socket
5
5
  import threading
6
+ from typing import Any
6
7
 
7
8
  from . import _tls
8
9
  from ._tls import SecurityError # noqa: F401 (capy.SecurityError)
@@ -95,7 +96,7 @@ def _hide(line):
95
96
 
96
97
 
97
98
  # Ex : return capy.json('{"text": "Hello"}')
98
- def json(text):
99
+ def json(text) -> Any:
99
100
  try:
100
101
  return jsonlib.loads(text)
101
102
  except ValueError as e:
@@ -113,7 +114,8 @@ _NOTHING = object() # Pour savoir si default a été donné (None est une vraie
113
114
  # Ex : get('{"text": "Hello"}', "text") -> "Hello"
114
115
  # get(reponse, "users.0.name") -> "Izac" (0 = 1er élément d'une liste)
115
116
  # get(reponse, "age", default=0) -> 0 si "age" n'existe pas (au lieu d'une erreur)
116
- def get(data, path, default=_NOTHING):
117
+ # -> Any : la valeur peut être de n'importe quel type (sinon Pylance croit que c'est un object)
118
+ def get(data, path, default=_NOTHING) -> Any:
117
119
  value = json(data) if isinstance(data, str) else data
118
120
  for key in str(path).split("."):
119
121
  if isinstance(value, dict) and key in value:
@@ -150,7 +152,7 @@ def _error(name, data, target):
150
152
  # Du JSON (dict, liste...) -> texte JSON sur une ligne (un texte reste tel quel)
151
153
  # Ex : to_str({"text": "Hello"}) -> '{"text": "Hello"}'
152
154
  # to_str('{"text": "Hello"}', "text") -> "Hello"
153
- def to_str(data, key=None):
155
+ def to_str(data, key=None) -> str:
154
156
  if key is not None:
155
157
  data = get(data, key)
156
158
  if isinstance(data, str):
@@ -163,7 +165,7 @@ def to_str(data, key=None):
163
165
 
164
166
  # -> entier. Accepte 42, 42.0, "42", " 42 "
165
167
  # Ex : to_int("42") -> 42 / to_int("abc") -> ValueError
166
- def to_int(data, key=None):
168
+ def to_int(data, key=None) -> int:
167
169
  if key is not None:
168
170
  data = get(data, key)
169
171
  if isinstance(data, bool): # True est un int pour Python, mais pas pour nous
@@ -182,7 +184,7 @@ def to_int(data, key=None):
182
184
 
183
185
  # -> nombre à virgule. Accepte 4.5, 4, "4.5"
184
186
  # Ex : to_float("4.5") -> 4.5
185
- def to_float(data, key=None):
187
+ def to_float(data, key=None) -> float:
186
188
  if key is not None:
187
189
  data = get(data, key)
188
190
  if not isinstance(data, bool) and isinstance(data, (int, float, str)):
@@ -195,7 +197,7 @@ def to_float(data, key=None):
195
197
 
196
198
  # -> True / False. Accepte true/false, 1/0, "true"/"false", "oui"/"non", "1"/"0"
197
199
  # Ex : to_bool("oui") -> True
198
- def to_bool(data, key=None):
200
+ def to_bool(data, key=None) -> bool:
199
201
  if key is not None:
200
202
  data = get(data, key)
201
203
  if isinstance(data, bool):
@@ -213,7 +215,7 @@ def to_bool(data, key=None):
213
215
 
214
216
  # -> liste. Accepte une liste, un tuple, ou du texte JSON '[1, 2]'
215
217
  # Ex : to_list("[1, 2]") -> [1, 2]
216
- def to_list(data, key=None):
218
+ def to_list(data, key=None) -> list:
217
219
  if key is not None:
218
220
  data = get(data, key)
219
221
  if isinstance(data, (list, tuple)):
@@ -230,7 +232,7 @@ def to_list(data, key=None):
230
232
 
231
233
  # -> dict. Accepte un dict, ou du texte JSON '{"a": 1}'
232
234
  # Ex : to_dict('{"a": 1}') -> {"a": 1}
233
- def to_dict(data, key=None):
235
+ def to_dict(data, key=None) -> dict:
234
236
  if key is not None:
235
237
  data = get(data, key)
236
238
  if isinstance(data, dict):
@@ -248,7 +250,7 @@ def to_dict(data, key=None):
248
250
  # Client : capy.call("127.0.0.1", 4000, "get", id=2) -> dict
249
251
  # Lève ConnectionError si le serveur ne répond pas, SecurityError si ce n'est pas le bon serveur
250
252
  # tls=False : pour un serveur pas chiffré (Server(..., tls=False))
251
- def call(host, port, action, /, tls=True, **params):
253
+ def call(host, port, action, /, tls=True, **params) -> Any:
252
254
  return _call(host, port, action, params, tls, label=f"{host}:{port}")
253
255
 
254
256
 
@@ -289,6 +291,6 @@ def _call(host, port, action, params, tls, label, who="capy"):
289
291
 
290
292
  # Empreinte du certificat des serveurs capy de cette machine (à donner aux clients qui veulent vérifier)
291
293
  # Ex : capy.fingerprint() -> "9dfa7b98…"
292
- def fingerprint():
294
+ def fingerprint() -> str:
293
295
  _tls.server_context("server") # Crée le certificat s'il n'existe pas encore
294
296
  return _tls.my_fingerprint("server")
@@ -20,6 +20,7 @@ import socket
20
20
  import sys
21
21
  import threading
22
22
  import time
23
+ from typing import Any
23
24
 
24
25
  import capy
25
26
  from capy import _tls
@@ -476,7 +477,7 @@ def _call_once(host, port, message):
476
477
  # Appeler une action d'un serveur par son nom, via le relais (comme capy.call)
477
478
  # La connexion chiffrée reste ouverte : seul le 1er appel paie la connexion TLS
478
479
  # Ex : capy.network.call("maison", "test") -> {"text": "Hello"}
479
- def call(name, action, /, **params):
480
+ def call(name, action, /, **params) -> Any:
480
481
  host, port = _address(None)
481
482
  message = {"capy": "call", "to": name, "key": _config["key"], "request": {"action": action, **params}}
482
483
  reply = None
@@ -6,6 +6,7 @@ import json as jsonlib
6
6
  import socket
7
7
  import threading
8
8
  import time
9
+ from typing import Any
9
10
 
10
11
  import capy
11
12
 
@@ -87,7 +88,7 @@ def find(name, timeout=1):
87
88
  # Appeler une action d'un serveur par son nom (comme capy.call, sans IP ni port)
88
89
  # tls=False : pour un serveur pas chiffré (Server(..., tls=False))
89
90
  # Ex : capy.wifi.call("maison", "test") -> {"text": "Hello"}
90
- def call(name, action, /, tls=True, **params):
91
+ def call(name, action, /, tls=True, **params) -> Any:
91
92
  for attempt in range(2):
92
93
  host, port = find(name)
93
94
  if _secure.get(name, True) != tls:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capyy
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Tiny encrypted JSON-over-TCP APIs: call a function in another program, on your Wi-Fi or across the internet
5
5
  Author: Izac
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "capyy"
7
- version = "0.3.1"
7
+ version = "0.3.2"
8
8
  description = "Tiny encrypted JSON-over-TCP APIs: call a function in another program, on your Wi-Fi or across the internet"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes