deltachat-rpc-client 2.28.0__py3-none-any.whl → 2.30.0__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.
@@ -80,6 +80,7 @@ class EventType(str, Enum):
80
80
  CONFIG_SYNCED = "ConfigSynced"
81
81
  WEBXDC_REALTIME_DATA = "WebxdcRealtimeData"
82
82
  WEBXDC_REALTIME_ADVERTISEMENT_RECEIVED = "WebxdcRealtimeAdvertisementReceived"
83
+ TRANSPORTS_MODIFIED = "TransportsModified"
83
84
 
84
85
 
85
86
  class ChatId(IntEnum):
@@ -60,6 +60,10 @@ class Message:
60
60
  """Mark the message as seen."""
61
61
  self._rpc.markseen_msgs(self.account.id, [self.id])
62
62
 
63
+ def exists(self) -> bool:
64
+ """Return True if the message exists."""
65
+ return bool(self._rpc.get_existing_msg_ids(self.account.id, [self.id]))
66
+
63
67
  def continue_autocrypt_key_transfer(self, setup_code: str) -> None:
64
68
  """Continue the Autocrypt Setup Message key transfer.
65
69
 
@@ -3,9 +3,14 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
+ import pathlib
7
+ import platform
6
8
  import random
9
+ import subprocess
10
+ import sys
7
11
  from typing import AsyncGenerator, Optional
8
12
 
13
+ import execnet
9
14
  import py
10
15
  import pytest
11
16
 
@@ -20,6 +25,18 @@ Currently this is "End-to-end encryption available".
20
25
  """
21
26
 
22
27
 
28
+ def pytest_report_header():
29
+ for base in os.get_exec_path():
30
+ fn = pathlib.Path(base).joinpath(base, "deltachat-rpc-server")
31
+ if fn.exists():
32
+ proc = subprocess.Popen([str(fn), "--version"], stderr=subprocess.PIPE)
33
+ proc.wait()
34
+ version = proc.stderr.read().decode().strip()
35
+ return f"deltachat-rpc-server: {fn} [{version}]"
36
+
37
+ return None
38
+
39
+
23
40
  class ACFactory:
24
41
  """Test account factory."""
25
42
 
@@ -197,3 +214,134 @@ def log():
197
214
  print(" " + msg)
198
215
 
199
216
  return Printer()
217
+
218
+
219
+ #
220
+ # support for testing against different deltachat-rpc-server/clients
221
+ # installed into a temporary virtualenv and connected via 'execnet' channels
222
+ #
223
+
224
+
225
+ def find_path(venv, name):
226
+ is_windows = platform.system() == "Windows"
227
+ bin = venv / ("bin" if not is_windows else "Scripts")
228
+
229
+ tryadd = [""]
230
+ if is_windows:
231
+ tryadd += os.environ["PATHEXT"].split(os.pathsep)
232
+ for ext in tryadd:
233
+ p = bin.joinpath(name + ext)
234
+ if p.exists():
235
+ return str(p)
236
+
237
+ return None
238
+
239
+
240
+ @pytest.fixture(scope="session")
241
+ def get_core_python_env(tmp_path_factory):
242
+ """Return a factory to create virtualenv environments with rpc server/client packages
243
+ installed.
244
+
245
+ The factory takes a version and returns a (python_path, rpc_server_path) tuple
246
+ of the respective binaries in the virtualenv.
247
+ """
248
+
249
+ envs = {}
250
+
251
+ def get_versioned_venv(core_version):
252
+ venv = envs.get(core_version)
253
+ if not venv:
254
+ venv = tmp_path_factory.mktemp(f"temp-{core_version}")
255
+ subprocess.check_call([sys.executable, "-m", "venv", venv])
256
+
257
+ python = find_path(venv, "python")
258
+ pkgs = [f"deltachat-rpc-server=={core_version}", f"deltachat-rpc-client=={core_version}", "pytest"]
259
+ subprocess.check_call([python, "-m", "pip", "install"] + pkgs)
260
+
261
+ envs[core_version] = venv
262
+ python = find_path(venv, "python")
263
+ rpc_server_path = find_path(venv, "deltachat-rpc-server")
264
+ print(f"python={python}\nrpc_server={rpc_server_path}")
265
+ return python, rpc_server_path
266
+
267
+ return get_versioned_venv
268
+
269
+
270
+ @pytest.fixture
271
+ def alice_and_remote_bob(tmp_path, acfactory, get_core_python_env):
272
+ """return local Alice account, a contact to bob, and a remote 'eval' function for bob.
273
+
274
+ The 'eval' function allows to remote-execute arbitrary expressions
275
+ that can use the `bob` online account, and the `bob_contact_alice`.
276
+ """
277
+
278
+ def factory(core_version):
279
+ python, rpc_server_path = get_core_python_env(core_version)
280
+ gw = execnet.makegateway(f"popen//python={python}")
281
+
282
+ accounts_dir = str(tmp_path.joinpath("account1_venv1"))
283
+ channel = gw.remote_exec(remote_bob_loop)
284
+ cm = os.environ.get("CHATMAIL_DOMAIN")
285
+
286
+ # trigger getting an online account on bob's side
287
+ channel.send((accounts_dir, str(rpc_server_path), cm))
288
+
289
+ # meanwhile get a local alice account
290
+ alice = acfactory.get_online_account()
291
+ channel.send(alice.self_contact.make_vcard())
292
+
293
+ # wait for bob to have started
294
+ sysinfo = channel.receive()
295
+ assert sysinfo == f"v{core_version}"
296
+ bob_vcard = channel.receive()
297
+ [alice_contact_bob] = alice.import_vcard(bob_vcard)
298
+
299
+ def eval(eval_str):
300
+ channel.send(eval_str)
301
+ return channel.receive()
302
+
303
+ return alice, alice_contact_bob, eval
304
+
305
+ return factory
306
+
307
+
308
+ def remote_bob_loop(channel):
309
+ # This function executes with versioned
310
+ # deltachat-rpc-client/server packages
311
+ # installed into the virtualenv.
312
+ #
313
+ # The "channel" argument is a send/receive pipe
314
+ # to the process that runs the corresponding remote_exec(remote_bob_loop)
315
+
316
+ import os
317
+
318
+ from deltachat_rpc_client import DeltaChat, Rpc
319
+ from deltachat_rpc_client.pytestplugin import ACFactory
320
+
321
+ accounts_dir, rpc_server_path, chatmail_domain = channel.receive()
322
+ os.environ["CHATMAIL_DOMAIN"] = chatmail_domain
323
+
324
+ # older core versions don't support specifying rpc_server_path
325
+ # so we can't just pass `rpc_server_path` argument to Rpc constructor
326
+ basepath = os.path.dirname(rpc_server_path)
327
+ os.environ["PATH"] = os.pathsep.join([basepath, os.environ["PATH"]])
328
+ rpc = Rpc(accounts_dir=accounts_dir)
329
+
330
+ with rpc:
331
+ dc = DeltaChat(rpc)
332
+ channel.send(dc.rpc.get_system_info()["deltachat_core_version"])
333
+ acfactory = ACFactory(dc)
334
+ bob = acfactory.get_online_account()
335
+ alice_vcard = channel.receive()
336
+ [alice_contact] = bob.import_vcard(alice_vcard)
337
+ ns = {"bob": bob, "bob_contact_alice": alice_contact}
338
+ channel.send(bob.self_contact.make_vcard())
339
+
340
+ while 1:
341
+ eval_str = channel.receive()
342
+ res = eval(eval_str, ns)
343
+ try:
344
+ channel.send(res)
345
+ except Exception:
346
+ # some unserializable result
347
+ channel.send(None)
@@ -9,7 +9,7 @@ import os
9
9
  import subprocess
10
10
  import sys
11
11
  from queue import Empty, Queue
12
- from threading import Event, Thread
12
+ from threading import Thread
13
13
  from typing import Any, Iterator, Optional
14
14
 
15
15
 
@@ -17,25 +17,6 @@ class JsonRpcError(Exception):
17
17
  """JSON-RPC error."""
18
18
 
19
19
 
20
- class RpcFuture:
21
- """RPC future waiting for RPC call result."""
22
-
23
- def __init__(self, rpc: "Rpc", request_id: int, event: Event):
24
- self.rpc = rpc
25
- self.request_id = request_id
26
- self.event = event
27
-
28
- def __call__(self):
29
- """Wait for the future to return the result."""
30
- self.event.wait()
31
- response = self.rpc.request_results.pop(self.request_id)
32
- if "error" in response:
33
- raise JsonRpcError(response["error"])
34
- if "result" in response:
35
- return response["result"]
36
- return None
37
-
38
-
39
20
  class RpcMethod:
40
21
  """RPC method."""
41
22
 
@@ -57,20 +38,26 @@ class RpcMethod:
57
38
  "params": args,
58
39
  "id": request_id,
59
40
  }
60
- event = Event()
61
- self.rpc.request_events[request_id] = event
41
+ self.rpc.request_results[request_id] = queue = Queue()
62
42
  self.rpc.request_queue.put(request)
63
43
 
64
- return RpcFuture(self.rpc, request_id, event)
44
+ def rpc_future():
45
+ """Wait for the request to receive a result."""
46
+ response = queue.get()
47
+ if "error" in response:
48
+ raise JsonRpcError(response["error"])
49
+ return response.get("result", None)
50
+
51
+ return rpc_future
65
52
 
66
53
 
67
54
  class Rpc:
68
55
  """RPC client."""
69
56
 
70
- def __init__(self, accounts_dir: Optional[str] = None, **kwargs):
57
+ def __init__(self, accounts_dir: Optional[str] = None, rpc_server_path="deltachat-rpc-server", **kwargs):
71
58
  """Initialize RPC client.
72
59
 
73
- The given arguments will be passed to subprocess.Popen().
60
+ The 'kwargs' arguments will be passed to subprocess.Popen().
74
61
  """
75
62
  if accounts_dir:
76
63
  kwargs["env"] = {
@@ -79,13 +66,12 @@ class Rpc:
79
66
  }
80
67
 
81
68
  self._kwargs = kwargs
69
+ self.rpc_server_path = rpc_server_path
82
70
  self.process: subprocess.Popen
83
71
  self.id_iterator: Iterator[int]
84
72
  self.event_queues: dict[int, Queue]
85
- # Map from request ID to `threading.Event`.
86
- self.request_events: dict[int, Event]
87
- # Map from request ID to the result.
88
- self.request_results: dict[int, Any]
73
+ # Map from request ID to a Queue which provides a single result
74
+ self.request_results: dict[int, Queue]
89
75
  self.request_queue: Queue[Any]
90
76
  self.closing: bool
91
77
  self.reader_thread: Thread
@@ -94,27 +80,18 @@ class Rpc:
94
80
 
95
81
  def start(self) -> None:
96
82
  """Start RPC server subprocess."""
83
+ popen_kwargs = {"stdin": subprocess.PIPE, "stdout": subprocess.PIPE}
97
84
  if sys.version_info >= (3, 11):
98
- self.process = subprocess.Popen(
99
- "deltachat-rpc-server",
100
- stdin=subprocess.PIPE,
101
- stdout=subprocess.PIPE,
102
- # Prevent subprocess from capturing SIGINT.
103
- process_group=0,
104
- **self._kwargs,
105
- )
85
+ # Prevent subprocess from capturing SIGINT.
86
+ popen_kwargs["process_group"] = 0
106
87
  else:
107
- self.process = subprocess.Popen(
108
- "deltachat-rpc-server",
109
- stdin=subprocess.PIPE,
110
- stdout=subprocess.PIPE,
111
- # `process_group` is not supported before Python 3.11.
112
- preexec_fn=os.setpgrp, # noqa: PLW1509
113
- **self._kwargs,
114
- )
88
+ # `process_group` is not supported before Python 3.11.
89
+ popen_kwargs["preexec_fn"] = os.setpgrp # noqa: PLW1509
90
+
91
+ popen_kwargs.update(self._kwargs)
92
+ self.process = subprocess.Popen(self.rpc_server_path, **popen_kwargs)
115
93
  self.id_iterator = itertools.count(start=1)
116
94
  self.event_queues = {}
117
- self.request_events = {}
118
95
  self.request_results = {}
119
96
  self.request_queue = Queue()
120
97
  self.closing = False
@@ -149,9 +126,7 @@ class Rpc:
149
126
  response = json.loads(line)
150
127
  if "id" in response:
151
128
  response_id = response["id"]
152
- event = self.request_events.pop(response_id)
153
- self.request_results[response_id] = response
154
- event.set()
129
+ self.request_results.pop(response_id).put(response)
155
130
  else:
156
131
  logging.warning("Got a response without ID: %s", response)
157
132
  except Exception:
@@ -1,15 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deltachat-rpc-client
3
- Version: 2.28.0
3
+ Version: 2.30.0
4
4
  Summary: Python client for Delta Chat core JSON-RPC interface
5
+ License-Expression: MPL-2.0
5
6
  Classifier: Development Status :: 5 - Production/Stable
6
7
  Classifier: Intended Audience :: Developers
7
- Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
8
8
  Classifier: Operating System :: POSIX :: Linux
9
9
  Classifier: Operating System :: MacOS :: MacOS X
10
10
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.8
12
- Classifier: Programming Language :: Python :: 3.9
13
11
  Classifier: Programming Language :: Python :: 3.10
14
12
  Classifier: Programming Language :: Python :: 3.11
15
13
  Classifier: Programming Language :: Python :: 3.12
@@ -17,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.13
17
15
  Classifier: Programming Language :: Python :: 3.14
18
16
  Classifier: Topic :: Communications :: Chat
19
17
  Classifier: Topic :: Communications :: Email
20
- Requires-Python: >=3.8
18
+ Requires-Python: >=3.10
21
19
  Description-Content-Type: text/markdown
22
20
  License-File: LICENSE
23
21
  Dynamic: license-file
@@ -54,6 +52,15 @@ $ pip install .
54
52
 
55
53
  Additional arguments to `tox` are passed to pytest, e.g. `tox -- -s` does not capture test output.
56
54
 
55
+
56
+ ## Activating current checkout of deltachat-rpc-client and -server for development
57
+
58
+ Go to root repository directory and run:
59
+ ```
60
+ $ scripts/make-rpc-testenv.sh
61
+ $ source venv/bin/activate
62
+ ```
63
+
57
64
  ## Using in REPL
58
65
 
59
66
  Setup a development environment:
@@ -3,17 +3,17 @@ deltachat_rpc_client/_utils.py,sha256=v0iWVSa6S-s078GgnnhflCRhA9pfWI-CfK8mjZ4zjX
3
3
  deltachat_rpc_client/account.py,sha256=CNUwmWNdWlaEXuDHy0Xld7EFnNaBrMk_BORkVeNIql4,19549
4
4
  deltachat_rpc_client/chat.py,sha256=x5CEIORL1-731QC4KcXd_0JKtRpe7nT9oAygmKkooHI,11707
5
5
  deltachat_rpc_client/client.py,sha256=6eP_lH5z7G5Sy7vDRNfKNY3dkUqJqKZDVyCGjynsuW8,7181
6
- deltachat_rpc_client/const.py,sha256=p6hSXNYLBpPLpMz0UkT8QnMrqmA_cZ3sw-o8S3ryVM4,6675
6
+ deltachat_rpc_client/const.py,sha256=fnM377RkqOf4rM_jhy-O8dK-MbFLXQYtvprsvVWg2YI,6722
7
7
  deltachat_rpc_client/contact.py,sha256=NLh1XNnD_LQf27pNcVgqNN97Gbv190VSCuEyjjce4L4,1893
8
8
  deltachat_rpc_client/deltachat.py,sha256=-6SqQAS8_mMWLBP3U1HvFsNIpcAPYBlmqF8R6Bt90YQ,1894
9
9
  deltachat_rpc_client/events.py,sha256=Y45LoGlQy0i1U-LhoqF9njqJWA8v4b-XHfXZ4VOr1TQ,10205
10
- deltachat_rpc_client/message.py,sha256=PWSm5e-woWgYXPcnwygQO0fNSRV-NvKvuerqWkJxiik,4996
10
+ deltachat_rpc_client/message.py,sha256=xA3rLUOPkakqr7kW3JORVYLKHQxvggBqgrXPnDK1a0s,5156
11
11
  deltachat_rpc_client/py.typed,sha256=nGQ9Itq-bkXBn5Ri1JIR0oYnDNv7LDRfkowxBSSqVTM,60
12
- deltachat_rpc_client/pytestplugin.py,sha256=aoueJt7pXJUQsSBRRyVHLU-geSC9LUOJ7qlvJbWTB4A,5899
13
- deltachat_rpc_client/rpc.py,sha256=AUY8UJP7NlRSE5ewJs9jGxJdK8etKqsCEFWiIqnX5T8,6981
14
- deltachat_rpc_client-2.28.0.dist-info/licenses/LICENSE,sha256=Pz2eACSxkhsGfW9_iN60pgy-enjnbGTj8df8O3ebnQQ,16726
15
- deltachat_rpc_client-2.28.0.dist-info/METADATA,sha256=ClJk90k_SAgeIo42XgVpCsctIIQHyC4QVnZUuuSY7HI,2225
16
- deltachat_rpc_client-2.28.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- deltachat_rpc_client-2.28.0.dist-info/entry_points.txt,sha256=VHpX6EnKBaNj89qJWctApThnMa8suyaamfZEnQacXgc,81
18
- deltachat_rpc_client-2.28.0.dist-info/top_level.txt,sha256=ePNMkY10htGrLiLydH1ITvYFM3LcTEa51HyPqJ40hDk,21
19
- deltachat_rpc_client-2.28.0.dist-info/RECORD,,
12
+ deltachat_rpc_client/pytestplugin.py,sha256=ptQg9BMtNqTmFY3-InFVMRmeRqQBGym7wgdORSaOEk0,10804
13
+ deltachat_rpc_client/rpc.py,sha256=V26Z6rSjwAIWinPft5jnJIQrQg6lnlqLVf9BPWgz6iE,6318
14
+ deltachat_rpc_client-2.30.0.dist-info/licenses/LICENSE,sha256=Pz2eACSxkhsGfW9_iN60pgy-enjnbGTj8df8O3ebnQQ,16726
15
+ deltachat_rpc_client-2.30.0.dist-info/METADATA,sha256=kfNx5cYlTHO6OTASnSaGoM7My-NlSB1rQzHMBbTug70,2274
16
+ deltachat_rpc_client-2.30.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ deltachat_rpc_client-2.30.0.dist-info/entry_points.txt,sha256=VHpX6EnKBaNj89qJWctApThnMa8suyaamfZEnQacXgc,81
18
+ deltachat_rpc_client-2.30.0.dist-info/top_level.txt,sha256=ePNMkY10htGrLiLydH1ITvYFM3LcTEa51HyPqJ40hDk,21
19
+ deltachat_rpc_client-2.30.0.dist-info/RECORD,,