Skip to content

Commit c1471bd

Browse files
committed
docs: add missing documentation to deltachat-rpc-client
1 parent a981573 commit c1471bd

File tree

12 files changed

+160
-77
lines changed

12 files changed

+160
-77
lines changed

deltachat-rpc-client/src/deltachat_rpc_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Delta Chat JSON-RPC high-level API"""
1+
"""Delta Chat JSON-RPC high-level API."""
22

33
from ._utils import AttrDict, run_bot_cli, run_client_cli
44
from .account import Account

deltachat-rpc-client/src/deltachat_rpc_client/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _run_cli(
115115

116116

117117
def extract_addr(text: str) -> str:
118-
"""extract email address from the given text."""
118+
"""Extract email address from the given text."""
119119
match = re.match(r".*\((.+@.+)\)", text)
120120
if match:
121121
text = match.group(1)
@@ -124,7 +124,7 @@ def extract_addr(text: str) -> str:
124124

125125

126126
def parse_system_image_changed(text: str) -> Optional[Tuple[str, bool]]:
127-
"""return image changed/deleted info from parsing the given system message text."""
127+
"""Return image changed/deleted info from parsing the given system message text."""
128128
text = text.lower()
129129
match = re.match(r"group image (changed|deleted) by (.+).", text)
130130
if match:
@@ -143,7 +143,7 @@ def parse_system_title_changed(text: str) -> Optional[Tuple[str, str]]:
143143

144144

145145
def parse_system_add_remove(text: str) -> Optional[Tuple[str, str, str]]:
146-
"""return add/remove info from parsing the given system message text.
146+
"""Return add/remove info from parsing the given system message text.
147147
148148
returns a (action, affected, actor) tuple.
149149
"""

deltachat-rpc-client/src/deltachat_rpc_client/account.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Account module."""
2+
13
from __future__ import annotations
24

35
from dataclasses import dataclass
@@ -34,7 +36,10 @@ def wait_for_event(self, event_type=None) -> AttrDict:
3436
return next_event
3537

3638
def clear_all_events(self):
37-
"""Removes all queued-up events for a given account. Useful for tests."""
39+
"""Remove all queued-up events for a given account.
40+
41+
Useful for tests.
42+
"""
3843
self._rpc.clear_all_events(self.id)
3944

4045
def remove(self) -> None:
@@ -43,7 +48,9 @@ def remove(self) -> None:
4348

4449
def clone(self) -> "Account":
4550
"""Clone given account.
46-
This uses backup-transfer via iroh, i.e. the 'Add second device' feature."""
51+
52+
This uses backup-transfer via iroh, i.e. the 'Add second device' feature.
53+
"""
4754
future = self._rpc.provide_backup.future(self.id)
4855
qr = self._rpc.get_backup_qr(self.id)
4956
new_account = self.manager.add_account()
@@ -80,7 +87,7 @@ def get_config(self, key: str) -> Optional[str]:
8087
return self._rpc.get_config(self.id, key)
8188

8289
def update_config(self, **kwargs) -> None:
83-
"""update config values."""
90+
"""Update config values."""
8491
for key, value in kwargs.items():
8592
self.set_config(key, value)
8693

@@ -99,10 +106,12 @@ def check_qr(self, qr):
99106
"""Parse QR code contents.
100107
101108
This function takes the raw text scanned
102-
and checks what can be done with it."""
109+
and checks what can be done with it.
110+
"""
103111
return self._rpc.check_qr(self.id, qr)
104112

105113
def set_config_from_qr(self, qr: str):
114+
"""Set configuration values from a QR code."""
106115
self._rpc.set_config_from_qr(self.id, qr)
107116

108117
@futuremethod
@@ -117,7 +126,7 @@ def add_or_update_transport(self, params):
117126

118127
@futuremethod
119128
def list_transports(self):
120-
"""Returns the list of all email accounts that are used as a transport in the current profile."""
129+
"""Return the list of all email accounts that are used as a transport in the current profile."""
121130
transports = yield self._rpc.list_transports.future(self.id)
122131
return transports
123132

@@ -158,7 +167,8 @@ def make_vcard(self, contacts: list[Contact]) -> str:
158167
def import_vcard(self, vcard: str) -> list[Contact]:
159168
"""Import vCard.
160169
161-
Return created or modified contacts in the order they appear in vCard."""
170+
Return created or modified contacts in the order they appear in vCard.
171+
"""
162172
contact_ids = self._rpc.import_vcard_contents(self.id, vcard)
163173
return [Contact(self, contact_id) for contact_id in contact_ids]
164174

@@ -227,12 +237,12 @@ def get_contacts(
227237

228238
@property
229239
def self_contact(self) -> Contact:
230-
"""This account's identity as a Contact."""
240+
"""Account's identity as a Contact."""
231241
return Contact(self, SpecialContactId.SELF)
232242

233243
@property
234244
def device_contact(self) -> Chat:
235-
"""This account's device contact."""
245+
"""Account's device contact."""
236246
return Contact(self, SpecialContactId.DEVICE)
237247

238248
def get_chatlist(
@@ -290,8 +300,7 @@ def get_chat_by_id(self, chat_id: int) -> Chat:
290300
return Chat(self, chat_id)
291301

292302
def secure_join(self, qrdata: str) -> Chat:
293-
"""Continue a Setup-Contact or Verified-Group-Invite protocol started on
294-
another device.
303+
"""Continue a Setup-Contact or Verified-Group-Invite protocol started on another device.
295304
296305
The function returns immediately and the handshake runs in background, sending
297306
and receiving several messages.
@@ -361,22 +370,26 @@ def wait_for_msgs_noticed_event(self):
361370
def wait_for_incoming_msg(self):
362371
"""Wait for incoming message and return it.
363372
364-
Consumes all events before the next incoming message event."""
373+
Consumes all events before the next incoming message event.
374+
"""
365375
return self.get_message_by_id(self.wait_for_incoming_msg_event().msg_id)
366376

367377
def wait_for_securejoin_inviter_success(self):
378+
"""Wait until SecureJoin process finishes successfully on the inviter side."""
368379
while True:
369380
event = self.wait_for_event()
370381
if event["kind"] == "SecurejoinInviterProgress" and event["progress"] == 1000:
371382
break
372383

373384
def wait_for_securejoin_joiner_success(self):
385+
"""Wait until SecureJoin process finishes successfully on the joiner side."""
374386
while True:
375387
event = self.wait_for_event()
376388
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
377389
break
378390

379391
def wait_for_reactions_changed(self):
392+
"""Wait for reaction change event."""
380393
return self.wait_for_event(EventType.REACTIONS_CHANGED)
381394

382395
def get_fresh_messages_in_arrival_order(self) -> list[Message]:

deltachat-rpc-client/src/deltachat_rpc_client/chat.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Chat module."""
2+
13
from __future__ import annotations
24

35
import calendar
@@ -89,7 +91,8 @@ def set_name(self, name: str) -> None:
8991
def set_ephemeral_timer(self, timer: int) -> None:
9092
"""Set ephemeral timer of this chat in seconds.
9193
92-
0 means the timer is disabled, use 1 for immediate deletion."""
94+
0 means the timer is disabled, use 1 for immediate deletion.
95+
"""
9396
self._rpc.set_chat_ephemeral_timer(self.account.id, self.id, timer)
9497

9598
def get_encryption_info(self) -> str:
@@ -199,12 +202,12 @@ def get_draft(self) -> Optional[AttrDict]:
199202
return snapshot
200203

201204
def get_messages(self, info_only: bool = False, add_daymarker: bool = False) -> list[Message]:
202-
"""get the list of messages in this chat."""
205+
"""Get the list of messages in this chat."""
203206
msgs = self._rpc.get_message_ids(self.account.id, self.id, info_only, add_daymarker)
204207
return [Message(self.account, msg_id) for msg_id in msgs]
205208

206209
def get_fresh_message_count(self) -> int:
207-
"""Get number of fresh messages in this chat"""
210+
"""Get number of fresh messages in this chat."""
208211
return self._rpc.get_fresh_msg_cnt(self.account.id, self.id)
209212

210213
def mark_noticed(self) -> None:

deltachat-rpc-client/src/deltachat_rpc_client/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(
4848
self.add_hooks(hooks or [])
4949

5050
def add_hooks(self, hooks: Iterable[tuple[Callable, Union[type, EventFilter]]]) -> None:
51+
"""Register multiple hooks."""
5152
for hook, event in hooks:
5253
self.add_hook(hook, event)
5354

@@ -77,9 +78,11 @@ def remove_hook(self, hook: Callable, event: Union[type, EventFilter]) -> None:
7778
self._hooks.get(type(event), set()).remove((hook, event))
7879

7980
def is_configured(self) -> bool:
81+
"""Return True if the client is configured."""
8082
return self.account.is_configured()
8183

8284
def configure(self, email: str, password: str, **kwargs) -> None:
85+
"""Configure the client."""
8386
self.account.set_config("addr", email)
8487
self.account.set_config("mail_pw", password)
8588
for key, value in kwargs.items():
@@ -198,5 +201,6 @@ class Bot(Client):
198201
"""Simple bot implementation that listens to events of a single account."""
199202

200203
def configure(self, email: str, password: str, **kwargs) -> None:
204+
"""Configure the bot."""
201205
kwargs.setdefault("bot", "1")
202206
super().configure(email, password, **kwargs)

deltachat-rpc-client/src/deltachat_rpc_client/const.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1+
"""Constants module."""
2+
13
from enum import Enum, IntEnum
24

35
COMMAND_PREFIX = "/"
46

57

68
class ContactFlag(IntEnum):
9+
"""Bit flags for get_contacts() method."""
10+
711
VERIFIED_ONLY = 0x01
812
ADD_SELF = 0x02
913

1014

1115
class ChatlistFlag(IntEnum):
16+
"""Bit flags for get_chatlist() method."""
17+
1218
ARCHIVED_ONLY = 0x01
1319
NO_SPECIALS = 0x02
1420
ADD_ALLDONE_HINT = 0x04
1521
FOR_FORWARDING = 0x08
1622

1723

1824
class SpecialContactId(IntEnum):
25+
"""Special contact IDs."""
26+
1927
SELF = 1
2028
INFO = 2 # centered messages as "member added", used in all chats
2129
DEVICE = 5 # messages "update info" in the device-chat
2230
LAST_SPECIAL = 9
2331

2432

2533
class EventType(str, Enum):
26-
"""Core event types"""
34+
"""Core event types."""
2735

2836
INFO = "Info"
2937
SMTP_CONNECTED = "SmtpConnected"
@@ -71,7 +79,7 @@ class EventType(str, Enum):
7179

7280

7381
class ChatId(IntEnum):
74-
"""Special chat ids"""
82+
"""Special chat IDs."""
7583

7684
TRASH = 3
7785
ARCHIVED_LINK = 6
@@ -80,7 +88,7 @@ class ChatId(IntEnum):
8088

8189

8290
class ChatType(IntEnum):
83-
"""Chat types"""
91+
"""Chat type."""
8492

8593
UNDEFINED = 0
8694
SINGLE = 100
@@ -90,15 +98,15 @@ class ChatType(IntEnum):
9098

9199

92100
class ChatVisibility(str, Enum):
93-
"""Chat visibility types"""
101+
"""Chat visibility types."""
94102

95103
NORMAL = "Normal"
96104
ARCHIVED = "Archived"
97105
PINNED = "Pinned"
98106

99107

100108
class DownloadState(str, Enum):
101-
"""Message download state"""
109+
"""Message download state."""
102110

103111
DONE = "Done"
104112
AVAILABLE = "Available"
@@ -159,22 +167,22 @@ class MessageState(IntEnum):
159167

160168

161169
class MessageId(IntEnum):
162-
"""Special message ids"""
170+
"""Special message IDs."""
163171

164172
DAYMARKER = 9
165173
LAST_SPECIAL = 9
166174

167175

168176
class CertificateChecks(IntEnum):
169-
"""Certificate checks mode"""
177+
"""Certificate checks mode."""
170178

171179
AUTOMATIC = 0
172180
STRICT = 1
173181
ACCEPT_INVALID_CERTIFICATES = 3
174182

175183

176184
class Connectivity(IntEnum):
177-
"""Connectivity states"""
185+
"""Connectivity states."""
178186

179187
NOT_CONNECTED = 1000
180188
CONNECTING = 2000
@@ -183,7 +191,7 @@ class Connectivity(IntEnum):
183191

184192

185193
class KeyGenType(IntEnum):
186-
"""Type of the key to generate"""
194+
"""Type of the key to generate."""
187195

188196
DEFAULT = 0
189197
RSA2048 = 1
@@ -193,45 +201,45 @@ class KeyGenType(IntEnum):
193201

194202
# "Lp" means "login parameters"
195203
class LpAuthFlag(IntEnum):
196-
"""Authorization flags"""
204+
"""Authorization flags."""
197205

198206
OAUTH2 = 0x2
199207
NORMAL = 0x4
200208

201209

202210
class MediaQuality(IntEnum):
203-
"""Media quality setting"""
211+
"""Media quality setting."""
204212

205213
BALANCED = 0
206214
WORSE = 1
207215

208216

209217
class ProviderStatus(IntEnum):
210-
"""Provider status according to manual testing"""
218+
"""Provider status according to manual testing."""
211219

212220
OK = 1
213221
PREPARATION = 2
214222
BROKEN = 3
215223

216224

217225
class PushNotifyState(IntEnum):
218-
"""Push notifications state"""
226+
"""Push notifications state."""
219227

220228
NOT_CONNECTED = 0
221229
HEARTBEAT = 1
222230
CONNECTED = 2
223231

224232

225233
class ShowEmails(IntEnum):
226-
"""Show emails mode"""
234+
"""Show emails mode."""
227235

228236
OFF = 0
229237
ACCEPTED_CONTACTS = 1
230238
ALL = 2
231239

232240

233241
class SocketSecurity(IntEnum):
234-
"""Socket security"""
242+
"""Socket security."""
235243

236244
AUTOMATIC = 0
237245
SSL = 1
@@ -240,7 +248,7 @@ class SocketSecurity(IntEnum):
240248

241249

242250
class VideochatType(IntEnum):
243-
"""Video chat URL type"""
251+
"""Video chat URL type."""
244252

245253
UNKNOWN = 0
246254
BASICWEBRTC = 1

0 commit comments

Comments
 (0)