dimp 2.4.3__tar.gz → 2.5.0__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 (53) hide show
  1. {dimp-2.4.3 → dimp-2.5.0}/PKG-INFO +13 -5
  2. {dimp-2.4.3 → dimp-2.5.0}/README.md +12 -4
  3. dimp-2.5.0/dimp/__init__.py +384 -0
  4. {dimp-2.4.3 → dimp-2.5.0}/dimp/crypto/__init__.py +37 -13
  5. {dimp-2.4.3/dimp/mkm → dimp-2.5.0/dimp/dkd}/__init__.py +18 -41
  6. {dimp-2.4.3 → dimp-2.5.0}/dimp/dkd/base.py +25 -12
  7. {dimp-2.4.3 → dimp-2.5.0}/dimp/dkd/envelope.py +27 -7
  8. {dimp-2.4.3 → dimp-2.5.0}/dimp/dkd/instant.py +11 -7
  9. {dimp-2.4.3 → dimp-2.5.0}/dimp/dkd/reliable.py +9 -9
  10. {dimp-2.4.3 → dimp-2.5.0}/dimp/dkd/secure.py +17 -10
  11. dimp-2.5.0/dimp/ext/__init__.py +187 -0
  12. dimp-2.5.0/dimp/ext/cmd_ext.py +135 -0
  13. {dimp-2.4.3 → dimp-2.5.0}/dimp/format/__init__.py +26 -61
  14. {dimp-2.4.3 → dimp-2.5.0}/dimp/format/base.py +145 -45
  15. {dimp-2.4.3 → dimp-2.5.0}/dimp/format/data.py +21 -49
  16. dimp-2.4.3/dimp/format/file.py → dimp-2.5.0/dimp/format/pnf.py +119 -44
  17. dimp-2.4.3/dimp/format/file_wrapper.py → dimp-2.5.0/dimp/format/pnf_wrapper.py +87 -23
  18. dimp-2.5.0/dimp/protocol/__init__.py +126 -0
  19. dimp-2.5.0/dimp/protocol/command.py +206 -0
  20. {dimp-2.4.3 → dimp-2.5.0}/dimp/protocol/types.py +24 -25
  21. dimp-2.4.3/dimp/crypto/algorithms.py → dimp-2.5.0/dimp/types/__init__.py +25 -15
  22. dimp-2.5.0/dimp/types/dictionary.py +276 -0
  23. {dimp-2.4.3 → dimp-2.5.0}/dimp.egg-info/PKG-INFO +13 -5
  24. {dimp-2.4.3 → dimp-2.5.0}/dimp.egg-info/SOURCES.txt +4 -20
  25. dimp-2.5.0/dimp.egg-info/requires.txt +2 -0
  26. {dimp-2.4.3 → dimp-2.5.0}/setup.py +3 -3
  27. dimp-2.4.3/dimp/__init__.py +0 -282
  28. dimp-2.4.3/dimp/dkd/__init__.py +0 -127
  29. dimp-2.4.3/dimp/ext/__init__.py +0 -103
  30. dimp-2.4.3/dimp/format/duri.py +0 -285
  31. dimp-2.4.3/dimp/format/embed.py +0 -224
  32. dimp-2.4.3/dimp/format/pnf.py +0 -185
  33. dimp-2.4.3/dimp/format/pnf_wrapper.py +0 -225
  34. dimp-2.4.3/dimp/mkm/docs.py +0 -149
  35. dimp-2.4.3/dimp/mkm/document.py +0 -266
  36. dimp-2.4.3/dimp/mkm/meta.py +0 -212
  37. dimp-2.4.3/dimp/protocol/__init__.py +0 -187
  38. dimp-2.4.3/dimp/protocol/assets.py +0 -221
  39. dimp-2.4.3/dimp/protocol/base.py +0 -298
  40. dimp-2.4.3/dimp/protocol/commands.py +0 -267
  41. dimp-2.4.3/dimp/protocol/contents.py +0 -457
  42. dimp-2.4.3/dimp/protocol/docs.py +0 -164
  43. dimp-2.4.3/dimp/protocol/files.py +0 -497
  44. dimp-2.4.3/dimp/protocol/forward.py +0 -257
  45. dimp-2.4.3/dimp/protocol/groups.py +0 -264
  46. dimp-2.4.3/dimp/protocol/quote.py +0 -237
  47. dimp-2.4.3/dimp/protocol/receipt.py +0 -196
  48. dimp-2.4.3/dimp/protocol/version.py +0 -82
  49. dimp-2.4.3/dimp.egg-info/requires.txt +0 -2
  50. {dimp-2.4.3 → dimp-2.5.0}/LICENSE +0 -0
  51. {dimp-2.4.3 → dimp-2.5.0}/dimp.egg-info/dependency_links.txt +0 -0
  52. {dimp-2.4.3 → dimp-2.5.0}/dimp.egg-info/top_level.txt +0 -0
  53. {dimp-2.4.3 → dimp-2.5.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dimp
3
- Version: 2.4.3
3
+ Version: 2.5.0
4
4
  Summary: Decentralized Instant Messaging Protocol
5
5
  Home-page: https://github.com/dimchat/core-py
6
6
  Author: Albert Moky
@@ -29,6 +29,8 @@ License-File: LICENSE
29
29
 
30
30
  ## Dependencies
31
31
 
32
+ * Latest Versions
33
+
32
34
  | Name | Version | Description |
33
35
  |------|---------|-------------|
34
36
  | [Ming Ke Ming (名可名)](https://github.com/dimchat/mkm-py) | [![Version](https://img.shields.io/pypi/v/mkm)](https://pypi.org/project/mkm) | Decentralized User Identity Authentication |
@@ -47,7 +49,6 @@ License-File: LICENSE
47
49
  ```python
48
50
  from abc import ABC, abstractmethod
49
51
  from enum import IntEnum
50
- from collections.abc import Mapping
51
52
  from typing import Optional
52
53
 
53
54
  from dimp import *
@@ -82,9 +83,9 @@ class HandshakeCommand(Command, ABC):
82
83
  "type" : i2s(0x88),
83
84
  "sn" : 12345,
84
85
 
85
- "command" : "handshake", // command name
86
- "title" : "Hello world!", // "DIM?", "DIM!"
87
- "session" : "{SESSION_ID}", // session key
86
+ "command" : "handshake", // command name
87
+ "title" : "Hello world!", // "DIM?", "DIM!"
88
+ "session" : "{SESSION_KEY}", // session key
88
89
  }
89
90
  """
90
91
  HANDSHAKE = 'handshake'
@@ -147,6 +148,13 @@ class HandshakeCommand(Command, ABC):
147
148
  again = ask # (2. S->C) ask client to handshake with new session key
148
149
  restart = offer # (3. C->S) handshake with new session key
149
150
  success = accepted # (4. S->C) notice the client that handshake accepted
151
+ ```
152
+
153
+ ```python
154
+ from collections.abc import Mapping
155
+ from typing import Optional
156
+
157
+ from dimp import *
150
158
 
151
159
 
152
160
  class BaseHandshakeCommand(BaseCommand, HandshakeCommand):
@@ -15,6 +15,8 @@
15
15
 
16
16
  ## Dependencies
17
17
 
18
+ * Latest Versions
19
+
18
20
  | Name | Version | Description |
19
21
  |------|---------|-------------|
20
22
  | [Ming Ke Ming (名可名)](https://github.com/dimchat/mkm-py) | [![Version](https://img.shields.io/pypi/v/mkm)](https://pypi.org/project/mkm) | Decentralized User Identity Authentication |
@@ -33,7 +35,6 @@
33
35
  ```python
34
36
  from abc import ABC, abstractmethod
35
37
  from enum import IntEnum
36
- from collections.abc import Mapping
37
38
  from typing import Optional
38
39
 
39
40
  from dimp import *
@@ -68,9 +69,9 @@ class HandshakeCommand(Command, ABC):
68
69
  "type" : i2s(0x88),
69
70
  "sn" : 12345,
70
71
 
71
- "command" : "handshake", // command name
72
- "title" : "Hello world!", // "DIM?", "DIM!"
73
- "session" : "{SESSION_ID}", // session key
72
+ "command" : "handshake", // command name
73
+ "title" : "Hello world!", // "DIM?", "DIM!"
74
+ "session" : "{SESSION_KEY}", // session key
74
75
  }
75
76
  """
76
77
  HANDSHAKE = 'handshake'
@@ -133,6 +134,13 @@ class HandshakeCommand(Command, ABC):
133
134
  again = ask # (2. S->C) ask client to handshake with new session key
134
135
  restart = offer # (3. C->S) handshake with new session key
135
136
  success = accepted # (4. S->C) notice the client that handshake accepted
137
+ ```
138
+
139
+ ```python
140
+ from collections.abc import Mapping
141
+ from typing import Optional
142
+
143
+ from dimp import *
136
144
 
137
145
 
138
146
  class BaseHandshakeCommand(BaseCommand, HandshakeCommand):
@@ -0,0 +1,384 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # DIMP : Decentralized Instant Messaging Protocol
4
+ #
5
+ # Written in 2019 by Moky <albert.moky@gmail.com>
6
+ # ==============================================================================
7
+ # MIT License
8
+ #
9
+ # Copyright (c) 2019 Albert Moky
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ # of this software and associated documentation files (the "Software"), to deal
13
+ # in the Software without restriction, including without limitation the rights
14
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ # copies of the Software, and to permit persons to whom the Software is
16
+ # furnished to do so, subject to the following conditions:
17
+ #
18
+ # The above copyright notice and this permission notice shall be included in all
19
+ # copies or substantial portions of the Software.
20
+ #
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ # SOFTWARE.
28
+ # ==============================================================================
29
+
30
+ """
31
+ DIMP
32
+ ~~~~
33
+
34
+ Decentralized Instant Messaging Protocol
35
+ """
36
+
37
+ from .types import *
38
+ from .format import *
39
+ from .crypto import *
40
+ from .protocol import *
41
+ from .dkd import *
42
+ from .ext import *
43
+
44
+
45
+ name = "DIMP"
46
+
47
+ __author__ = 'Albert Moky'
48
+
49
+ __all__ = [
50
+
51
+ 'Singleton',
52
+
53
+ 'final',
54
+
55
+ 'StrMap', 'MutableStrMap',
56
+ 'AnyList', 'StrList',
57
+
58
+ 'URI', 'DateTime',
59
+
60
+ 'Stringer',
61
+ 'ConstantString', # 'String',
62
+ 'Mapper',
63
+
64
+ 'Converter', 'DataConverter', 'BaseConverter',
65
+ 'Copier', 'DataCopier', 'BaseCopier',
66
+ 'Wrapper', 'DataWrapper', 'BaseWrapper',
67
+
68
+ 'Dictionary',
69
+
70
+ ################################################################
71
+ #
72
+ # Format
73
+ #
74
+ ################################################################
75
+
76
+ 'DataCoder', 'Hex', 'Base58', 'Base64',
77
+
78
+ 'ObjectCoder', 'JSON',
79
+ 'MapCoder', 'JSONMap',
80
+ 'StringCoder', 'UTF8',
81
+
82
+ 'TransportableResource',
83
+ 'TransportableData', 'TransportableDataFactory',
84
+ # 'FormatExtensions',
85
+ # 'TransportableDataHelper',
86
+ # 'shared_format_extensions', 'ted_helper',
87
+
88
+ #
89
+ # TED
90
+ #
91
+
92
+ 'BaseString', 'BaseData',
93
+
94
+ 'PlainData',
95
+
96
+ #
97
+ # PNF
98
+ #
99
+
100
+ 'TransportableFile', 'TransportableFileFactory',
101
+ # 'TransportableFileExtension',
102
+ # 'TransportableFileHelper',
103
+ # 'pnf_helper',
104
+ 'TransportableFileWrapper', 'TransportableFileWrapperFactory',
105
+ # 'TransportableFileWrapperExtension',
106
+ # 'pnf_wrapper_factory',
107
+
108
+ ################################################################
109
+ #
110
+ # Crypto
111
+ #
112
+ ################################################################
113
+
114
+ 'MessageDigester',
115
+ 'SHA256', 'KECCAK256', 'RIPEMD160',
116
+
117
+ #
118
+ # Crypto
119
+ #
120
+
121
+ 'CryptographyKey', 'EncryptKey', 'DecryptKey',
122
+ 'AsymmetricKey', 'SignKey', 'VerifyKey',
123
+ # 'CryptoExtensions',
124
+ # 'shared_crypto_extensions',
125
+
126
+ 'SymmetricKey', 'SymmetricKeyFactory',
127
+ # 'SymmetricKeyExtension',
128
+ # 'SymmetricKeyHelper',
129
+ # 'symmetric_helper',
130
+
131
+ 'PublicKey', 'PublicKeyFactory',
132
+ # 'PublicKeyExtension',
133
+ # 'PublicKeyHelper',
134
+ # 'public_helper',
135
+
136
+ 'PrivateKey', 'PrivateKeyFactory',
137
+ # 'PrivateKeyExtension',
138
+ # 'PrivateKeyHelper',
139
+ # 'private_helper',
140
+
141
+ #
142
+ # Encrypted Key Bundle
143
+ #
144
+
145
+ 'BytesMap',
146
+
147
+ 'EncryptedBundle',
148
+ # 'EncryptedBundleExtension',
149
+ # 'EncryptedBundleHandler',
150
+ # 'bundle_handler',
151
+
152
+ 'UserEncryptedBundle',
153
+
154
+ # 'DefaultBundleHandler',
155
+
156
+ ################################################################
157
+ #
158
+ # Protocol
159
+ #
160
+ ################################################################
161
+
162
+ #
163
+ # Ming-Ke-Ming
164
+ #
165
+
166
+ 'EntityType',
167
+ # 'AccountExtensions',
168
+ # 'shared_account_extensions',
169
+
170
+ 'Address', 'AddressFactory',
171
+ # 'AddressExtension',
172
+ # 'AddressHelper',
173
+ # 'address_helper',
174
+
175
+ 'ID', 'IDFactory',
176
+ # 'IDExtension',
177
+ # 'IDHelper',
178
+ # 'id_helper',
179
+
180
+ 'Meta', 'MetaFactory',
181
+ # 'MetaExtension',
182
+ # 'MetaHelper',
183
+ # 'meta_helper',
184
+
185
+ 'TAI',
186
+ 'Document', 'DocumentFactory',
187
+ # 'DocumentExtension',
188
+ # 'DocumentHelper',
189
+ # 'doc_helper',
190
+
191
+ 'ANYWHERE', 'EVERYWHERE',
192
+ 'ANYONE', 'EVERYONE', 'FOUNDER',
193
+ 'Identifier', # 'BroadcastAddress',
194
+
195
+ #
196
+ # Dao-Ke-Dao
197
+ #
198
+
199
+ 'Message',
200
+ # 'MessageExtensions',
201
+ # 'shared_message_extensions',
202
+
203
+ 'Envelope', 'EnvelopeFactory',
204
+ # 'EnvelopeHelper',
205
+ # 'envelope_helper',
206
+
207
+ 'InstantMessage', 'InstantMessageFactory',
208
+ # 'InstantMessageExtension',
209
+ # 'InstantMessageHelper',
210
+ # 'instant_helper',
211
+
212
+ 'SecureMessage', 'SecureMessageFactory',
213
+ # 'SecureMessageExtension',
214
+ # 'SecureMessageHelper',
215
+ # 'secure_helper',
216
+
217
+ 'ReliableMessage', 'ReliableMessageFactory',
218
+ # 'ReliableMessageExtension',
219
+ # 'ReliableMessageHelper',
220
+ # 'reliable_helper',
221
+
222
+ 'Content', 'ContentFactory',
223
+ # 'ContentExtension',
224
+ # 'ContentHelper',
225
+ # 'content_helper',
226
+
227
+ #
228
+ # Core Protocols
229
+ #
230
+
231
+ 'ContentType',
232
+
233
+ 'Command', 'CommandFactory',
234
+ # 'CommandExtension',
235
+ # 'CommandHelper',
236
+ # 'command_helper',
237
+
238
+ #
239
+ # Message Implementations
240
+ #
241
+
242
+ 'MessageEnvelope',
243
+
244
+ 'BaseMessage',
245
+ 'PlainMessage',
246
+ 'EncryptedMessage',
247
+ 'NetworkMessage',
248
+
249
+ ################################################################
250
+ #
251
+ # Extensions
252
+ #
253
+ ################################################################
254
+
255
+ #
256
+ # Format
257
+ #
258
+
259
+ 'FormatExtensions',
260
+ 'TransportableDataHelper',
261
+ 'shared_format_extensions', 'ted_helper',
262
+
263
+ #
264
+ # Crypto
265
+ #
266
+
267
+ 'CryptoExtensions',
268
+ 'shared_crypto_extensions',
269
+
270
+ 'SymmetricKeyExtension',
271
+ 'SymmetricKeyHelper',
272
+ 'symmetric_helper',
273
+
274
+ 'PublicKeyExtension',
275
+ 'PublicKeyHelper',
276
+ 'public_helper',
277
+
278
+ 'PrivateKeyExtension',
279
+ 'PrivateKeyHelper',
280
+ 'private_helper',
281
+
282
+ #
283
+ # Account
284
+ #
285
+
286
+ 'AccountExtensions',
287
+ 'shared_account_extensions',
288
+
289
+ 'AddressExtension',
290
+ 'AddressHelper',
291
+ 'address_helper',
292
+
293
+ 'IDExtension',
294
+ 'IDHelper',
295
+ 'id_helper',
296
+
297
+ 'MetaExtension',
298
+ 'MetaHelper',
299
+ 'meta_helper',
300
+
301
+ 'DocumentExtension',
302
+ 'DocumentHelper',
303
+ 'doc_helper',
304
+
305
+ #
306
+ # General Extensions
307
+ #
308
+
309
+ 'GeneralCryptoExtension',
310
+ 'CryptoKeyHandler',
311
+ 'crypto_handler',
312
+
313
+ 'GeneralAccountExtension',
314
+ 'AccountHandler',
315
+ 'account_handler',
316
+
317
+ #
318
+ # Bundle
319
+ #
320
+
321
+ 'EncryptedBundleExtension',
322
+ 'EncryptedBundleHandler',
323
+ 'bundle_handler',
324
+
325
+ 'DefaultBundleHandler',
326
+
327
+ #
328
+ # Message
329
+ #
330
+
331
+ 'MessageExtensions',
332
+ 'shared_message_extensions',
333
+
334
+ 'EnvelopeHelper',
335
+ 'envelope_helper',
336
+
337
+ 'InstantMessageExtension',
338
+ 'InstantMessageHelper',
339
+ 'instant_helper',
340
+
341
+ 'SecureMessageExtension',
342
+ 'SecureMessageHelper',
343
+ 'secure_helper',
344
+
345
+ 'ReliableMessageExtension',
346
+ 'ReliableMessageHelper',
347
+ 'reliable_helper',
348
+
349
+ 'ContentExtension',
350
+ 'ContentHelper',
351
+ 'content_helper',
352
+
353
+ #
354
+ # General Extensions
355
+ #
356
+
357
+ 'MessageHandlerExtension',
358
+ 'MessageHandler',
359
+ 'message_handler',
360
+
361
+ #
362
+ # Transportable File
363
+ #
364
+
365
+ 'TransportableFileExtension',
366
+ 'TransportableFileHelper',
367
+ 'pnf_helper',
368
+
369
+ 'TransportableFileWrapperExtension',
370
+ 'pnf_wrapper_factory',
371
+
372
+ #
373
+ # Command
374
+ #
375
+
376
+ 'CommandExtension',
377
+ 'CommandHelper',
378
+ 'command_helper',
379
+
380
+ 'GeneralCommandExtension',
381
+ 'CommandHandler',
382
+ 'command_handler',
383
+
384
+ ]
@@ -28,10 +28,18 @@
28
28
  # SOFTWARE.
29
29
  # ==============================================================================
30
30
 
31
+ """
32
+ Cryptography
33
+ ~~~~~~~~~~~~
34
+
35
+ 1. Crypto Keys
36
+ 2. Data Digest
37
+ 3. Data Format
38
+ """
39
+
31
40
  from mkm.digest import *
32
41
  from mkm.crypto import *
33
-
34
- from .algorithms import AsymmetricAlgorithms, SymmetricAlgorithms
42
+ from dkd.crypto import *
35
43
 
36
44
 
37
45
  __all__ = [
@@ -42,28 +50,44 @@ __all__ = [
42
50
 
43
51
  'MessageDigester',
44
52
  'SHA256', 'KECCAK256', 'RIPEMD160',
45
- 'sha256', 'keccak256', 'ripemd160',
46
53
 
47
54
  #
48
55
  # Crypto
49
56
  #
50
57
 
51
- 'CryptographyKey',
52
- 'EncryptKey', 'DecryptKey', 'SignKey', 'VerifyKey',
53
- 'SymmetricKey', 'AsymmetricKey',
54
- 'PrivateKey', 'PublicKey',
58
+ 'CryptographyKey', 'EncryptKey', 'DecryptKey',
59
+ 'AsymmetricKey', 'SignKey', 'VerifyKey',
60
+ # 'CryptoExtensions',
61
+ # 'shared_crypto_extensions',
55
62
 
56
- 'SymmetricKeyFactory', 'PrivateKeyFactory', 'PublicKeyFactory',
63
+ 'SymmetricKey', 'SymmetricKeyFactory',
64
+ # 'SymmetricKeyExtension',
65
+ # 'SymmetricKeyHelper',
66
+ # 'symmetric_helper',
57
67
 
58
- # 'SymmetricKeyHelper', 'PublicKeyHelper', 'PrivateKeyHelper',
68
+ 'PublicKey', 'PublicKeyFactory',
69
+ # 'PublicKeyExtension',
70
+ # 'PublicKeyHelper',
71
+ # 'public_helper',
59
72
 
60
- # 'SymmetricKeyExtension', 'PublicKeyExtension', 'PrivateKeyExtension',
61
- # 'CryptoExtensions', 'shared_crypto_extensions',
73
+ 'PrivateKey', 'PrivateKeyFactory',
74
+ # 'PrivateKeyExtension',
75
+ # 'PrivateKeyHelper',
76
+ # 'private_helper',
77
+
78
+ #
79
+ # Encrypted Key Bundle
80
+ #
62
81
 
82
+ 'BytesMap',
63
83
 
64
- # ----------------------------------------------------------------
84
+ 'EncryptedBundle',
85
+ # 'EncryptedBundleExtension',
86
+ # 'EncryptedBundleHandler',
87
+ # 'bundle_handler',
65
88
 
89
+ 'UserEncryptedBundle',
66
90
 
67
- 'AsymmetricAlgorithms', 'SymmetricAlgorithms',
91
+ # 'DefaultBundleHandler',
68
92
 
69
93
  ]
@@ -3,7 +3,6 @@
3
3
  # DIMP : Decentralized Instant Messaging Protocol
4
4
  #
5
5
  # Written in 2019 by Moky <albert.moky@gmail.com>
6
- #
7
6
  # ==============================================================================
8
7
  # MIT License
9
8
  #
@@ -28,55 +27,33 @@
28
27
  # SOFTWARE.
29
28
  # ==============================================================================
30
29
 
31
- from mkm.protocol import *
32
- from mkm.protocol.broadcast import BroadcastAddress, Identifier
33
-
34
- from ..protocol import MetaType
35
- from ..protocol import DocumentType
36
- from ..protocol import Visa, Bulletin
37
-
38
- from .meta import BaseMeta
39
- from .document import BaseDocument
40
- from .docs import BaseVisa, BaseBulletin
41
-
42
-
43
- __all__ = [
44
-
45
- #
46
- # Protocol
47
- #
48
-
49
- 'EntityType',
50
- 'Address', 'ID',
51
- 'Meta', 'TAI', 'Document',
52
-
53
- 'AddressFactory', 'IDFactory',
54
- 'MetaFactory', 'DocumentFactory',
55
30
 
56
- 'ANYWHERE', 'EVERYWHERE',
57
- 'ANYONE', 'EVERYONE', 'FOUNDER',
58
- 'BroadcastAddress', 'Identifier',
31
+ """
32
+ Dao-Ke-Dao
33
+ ~~~~~~~~~~
59
34
 
60
- # 'AddressHelper', 'IDHelper',
61
- # 'MetaHelper', 'DocumentHelper',
35
+ Universal Message Module
36
+ """
62
37
 
63
- # 'AddressExtension', 'IDExtension',
64
- # 'MetaExtension', 'DocumentExtension',
65
- # 'AccountExtensions', 'shared_account_extensions',
38
+ from .envelope import MessageEnvelope
66
39
 
40
+ from .base import BaseMessage
41
+ from .instant import PlainMessage
42
+ from .secure import EncryptedMessage
43
+ from .reliable import NetworkMessage
67
44
 
68
- # ----------------------------------------------------------------
69
45
 
70
-
71
- 'MetaType',
72
- 'DocumentType',
73
- 'Visa', 'Bulletin',
46
+ __all__ = [
74
47
 
75
48
  #
76
- # Implementations
49
+ # Message Implementations
77
50
  #
78
51
 
79
- 'BaseMeta',
80
- 'BaseDocument', 'BaseVisa', 'BaseBulletin',
52
+ 'MessageEnvelope',
53
+
54
+ 'BaseMessage',
55
+ 'PlainMessage',
56
+ 'EncryptedMessage',
57
+ 'NetworkMessage',
81
58
 
82
59
  ]
@@ -53,15 +53,37 @@ from typing import Optional
53
53
 
54
54
  from mkm.types import DateTime
55
55
  from mkm.types import StrMap
56
- from mkm.types import Dictionary
57
56
 
58
57
  from mkm.protocol import ID
59
58
  from dkd.protocol import Envelope, Message
60
59
 
60
+ from ..types import Dictionary
61
+
61
62
 
62
63
  class BaseMessage(Dictionary, Message):
64
+ """
65
+ Message with Envelope
66
+ ~~~~~~~~~~~~~~~~~~~~~
67
+
68
+ Base classes for messages
69
+ This class is used to create a message
70
+ with the envelope fields, such as 'sender', 'receiver', and 'time'
71
+
72
+ data format: {
73
+ //-- envelope
74
+ "sender" : "moki@xxx",
75
+ "receiver" : "hulk@yyy",
76
+ "time" : 123.45,
77
+
78
+ //-- body
79
+ ...
80
+ }
81
+ """
63
82
 
64
83
  def __init__(self, msg: StrMap = None, head: Envelope = None):
84
+ """Create a message with an existing envelope (shares its dictionary),
85
+ or decode from a network dictionary.
86
+ """
65
87
  if msg is None:
66
88
  # 1. new message with envelope
67
89
  assert head is not None, 'message envelope should not be empty'
@@ -82,6 +104,8 @@ class BaseMessage(Dictionary, Message):
82
104
  self.__envelope = env
83
105
  return env
84
106
 
107
+ # --------
108
+
85
109
  @property # Override
86
110
  def sender(self) -> ID:
87
111
  return self.envelope.sender
@@ -101,14 +125,3 @@ class BaseMessage(Dictionary, Message):
101
125
  @property # Override
102
126
  def type(self) -> Optional[str]:
103
127
  return self.envelope.type
104
-
105
- @classmethod
106
- def is_broadcast(cls, msg: Message) -> bool:
107
- if msg.receiver.is_broadcast:
108
- return True
109
- # check exposed group
110
- overt_group = msg.get('group')
111
- if overt_group is None:
112
- return False
113
- group = ID.parse(identifier=overt_group)
114
- return group is not None and group.is_broadcast