PyEventEngine 0.3.0.post5__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.
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/PKG-INFO +109 -109
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/PyEventEngine.egg-info/PKG-INFO +109 -109
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/PyEventEngine.egg-info/SOURCES.txt +0 -2
- pyeventengine-0.3.2/event_engine/__init__.py +3 -0
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/event_engine/native/_event.py +20 -1
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/event_engine/native/_topic.py +1 -1
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/event_engine/native/_topic_c.py +94 -94
- pyeventengine-0.3.2/setup.cfg +22 -0
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/setup.py +17 -4
- PyEventEngine-0.3.0.post5/event_engine/__init__.py +0 -3
- PyEventEngine-0.3.0.post5/event_engine/cpp/topic_api.cpp +0 -288
- PyEventEngine-0.3.0.post5/setup.cfg +0 -7
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/LICENSE +0 -0
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/PyEventEngine.egg-info/dependency_links.txt +0 -0
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/PyEventEngine.egg-info/top_level.txt +0 -0
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/README.md +0 -0
- {PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/event_engine/native/__init__.py +0 -0
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: PyEventEngine
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary: Basic event engine
|
|
5
|
-
Home-page: https://github.com/BolunHan/PyEventEngine.git
|
|
6
|
-
Author: Bolun.Han
|
|
7
|
-
Author-email: Bolun.Han@outlook.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Requires-Python: >=3.
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
|
|
19
|
-
# PyEventEngine
|
|
20
|
-
|
|
21
|
-
python native event engine
|
|
22
|
-
|
|
23
|
-
# Install
|
|
24
|
-
|
|
25
|
-
```shell
|
|
26
|
-
pip install git+https://github.com/BolunHan/PyEventEngine.git
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
or
|
|
30
|
-
|
|
31
|
-
```shell
|
|
32
|
-
pip install PyEventEngine
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
# Use
|
|
36
|
-
|
|
37
|
-
## basic usage
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
# init event engine
|
|
41
|
-
import time
|
|
42
|
-
from event_engine import EventEngine, Topic
|
|
43
|
-
|
|
44
|
-
EVENT_ENGINE = EventEngine()
|
|
45
|
-
EVENT_ENGINE.start()
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# register handler
|
|
49
|
-
def test_handler(msg, **kwargs):
|
|
50
|
-
print(msg)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
EVENT_ENGINE.register_handler(topic=Topic('SimpleTopic'), handler=test_handler)
|
|
54
|
-
|
|
55
|
-
# publish message
|
|
56
|
-
EVENT_ENGINE.put(topic=Topic('SimpleTopic'), msg='topic called')
|
|
57
|
-
time.sleep(1)
|
|
58
|
-
EVENT_ENGINE.stop()
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## regular topic
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
# init event engine
|
|
65
|
-
import time
|
|
66
|
-
from event_engine import EventEngine, Topic, RegularTopic
|
|
67
|
-
|
|
68
|
-
EVENT_ENGINE = EventEngine()
|
|
69
|
-
EVENT_ENGINE.start()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# register handler
|
|
73
|
-
def test_handler(msg, **kwargs):
|
|
74
|
-
print(msg)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
EVENT_ENGINE.register_handler(topic=RegularTopic('RegularTopic.*'), handler=test_handler)
|
|
78
|
-
|
|
79
|
-
# publish message
|
|
80
|
-
EVENT_ENGINE.put(topic=Topic('RegularTopic.ChildTopic0'), msg='topic called')
|
|
81
|
-
time.sleep(1)
|
|
82
|
-
EVENT_ENGINE.stop()
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## timer topic
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
# init event engine
|
|
89
|
-
import time
|
|
90
|
-
from event_engine import EventEngine, Topic, RegularTopic
|
|
91
|
-
|
|
92
|
-
EVENT_ENGINE = EventEngine()
|
|
93
|
-
EVENT_ENGINE.start()
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# register handler
|
|
97
|
-
def test_handler(**kwargs):
|
|
98
|
-
print(kwargs)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
topic = EVENT_ENGINE.get_timer(interval=1)
|
|
102
|
-
EVENT_ENGINE.register_handler(topic=topic, handler=test_handler)
|
|
103
|
-
|
|
104
|
-
# publish message
|
|
105
|
-
time.sleep(5)
|
|
106
|
-
EVENT_ENGINE.stop()
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
See more advanced usage at .Demo
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyEventEngine
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: Basic event engine
|
|
5
|
+
Home-page: https://github.com/BolunHan/PyEventEngine.git
|
|
6
|
+
Author: Bolun.Han
|
|
7
|
+
Author-email: Bolun.Han@outlook.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
|
|
19
|
+
# PyEventEngine
|
|
20
|
+
|
|
21
|
+
python native event engine
|
|
22
|
+
|
|
23
|
+
# Install
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
pip install git+https://github.com/BolunHan/PyEventEngine.git
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
pip install PyEventEngine
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# Use
|
|
36
|
+
|
|
37
|
+
## basic usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
# init event engine
|
|
41
|
+
import time
|
|
42
|
+
from event_engine import EventEngine, Topic
|
|
43
|
+
|
|
44
|
+
EVENT_ENGINE = EventEngine()
|
|
45
|
+
EVENT_ENGINE.start()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# register handler
|
|
49
|
+
def test_handler(msg, **kwargs):
|
|
50
|
+
print(msg)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
EVENT_ENGINE.register_handler(topic=Topic('SimpleTopic'), handler=test_handler)
|
|
54
|
+
|
|
55
|
+
# publish message
|
|
56
|
+
EVENT_ENGINE.put(topic=Topic('SimpleTopic'), msg='topic called')
|
|
57
|
+
time.sleep(1)
|
|
58
|
+
EVENT_ENGINE.stop()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## regular topic
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
# init event engine
|
|
65
|
+
import time
|
|
66
|
+
from event_engine import EventEngine, Topic, RegularTopic
|
|
67
|
+
|
|
68
|
+
EVENT_ENGINE = EventEngine()
|
|
69
|
+
EVENT_ENGINE.start()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# register handler
|
|
73
|
+
def test_handler(msg, **kwargs):
|
|
74
|
+
print(msg)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
EVENT_ENGINE.register_handler(topic=RegularTopic('RegularTopic.*'), handler=test_handler)
|
|
78
|
+
|
|
79
|
+
# publish message
|
|
80
|
+
EVENT_ENGINE.put(topic=Topic('RegularTopic.ChildTopic0'), msg='topic called')
|
|
81
|
+
time.sleep(1)
|
|
82
|
+
EVENT_ENGINE.stop()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## timer topic
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# init event engine
|
|
89
|
+
import time
|
|
90
|
+
from event_engine import EventEngine, Topic, RegularTopic
|
|
91
|
+
|
|
92
|
+
EVENT_ENGINE = EventEngine()
|
|
93
|
+
EVENT_ENGINE.start()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# register handler
|
|
97
|
+
def test_handler(**kwargs):
|
|
98
|
+
print(kwargs)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
topic = EVENT_ENGINE.get_timer(interval=1)
|
|
102
|
+
EVENT_ENGINE.register_handler(topic=topic, handler=test_handler)
|
|
103
|
+
|
|
104
|
+
# publish message
|
|
105
|
+
time.sleep(5)
|
|
106
|
+
EVENT_ENGINE.stop()
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
See more advanced usage at .Demo
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: PyEventEngine
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary: Basic event engine
|
|
5
|
-
Home-page: https://github.com/BolunHan/PyEventEngine.git
|
|
6
|
-
Author: Bolun.Han
|
|
7
|
-
Author-email: Bolun.Han@outlook.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Requires-Python: >=3.
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
|
|
19
|
-
# PyEventEngine
|
|
20
|
-
|
|
21
|
-
python native event engine
|
|
22
|
-
|
|
23
|
-
# Install
|
|
24
|
-
|
|
25
|
-
```shell
|
|
26
|
-
pip install git+https://github.com/BolunHan/PyEventEngine.git
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
or
|
|
30
|
-
|
|
31
|
-
```shell
|
|
32
|
-
pip install PyEventEngine
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
# Use
|
|
36
|
-
|
|
37
|
-
## basic usage
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
# init event engine
|
|
41
|
-
import time
|
|
42
|
-
from event_engine import EventEngine, Topic
|
|
43
|
-
|
|
44
|
-
EVENT_ENGINE = EventEngine()
|
|
45
|
-
EVENT_ENGINE.start()
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# register handler
|
|
49
|
-
def test_handler(msg, **kwargs):
|
|
50
|
-
print(msg)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
EVENT_ENGINE.register_handler(topic=Topic('SimpleTopic'), handler=test_handler)
|
|
54
|
-
|
|
55
|
-
# publish message
|
|
56
|
-
EVENT_ENGINE.put(topic=Topic('SimpleTopic'), msg='topic called')
|
|
57
|
-
time.sleep(1)
|
|
58
|
-
EVENT_ENGINE.stop()
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## regular topic
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
# init event engine
|
|
65
|
-
import time
|
|
66
|
-
from event_engine import EventEngine, Topic, RegularTopic
|
|
67
|
-
|
|
68
|
-
EVENT_ENGINE = EventEngine()
|
|
69
|
-
EVENT_ENGINE.start()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# register handler
|
|
73
|
-
def test_handler(msg, **kwargs):
|
|
74
|
-
print(msg)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
EVENT_ENGINE.register_handler(topic=RegularTopic('RegularTopic.*'), handler=test_handler)
|
|
78
|
-
|
|
79
|
-
# publish message
|
|
80
|
-
EVENT_ENGINE.put(topic=Topic('RegularTopic.ChildTopic0'), msg='topic called')
|
|
81
|
-
time.sleep(1)
|
|
82
|
-
EVENT_ENGINE.stop()
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## timer topic
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
# init event engine
|
|
89
|
-
import time
|
|
90
|
-
from event_engine import EventEngine, Topic, RegularTopic
|
|
91
|
-
|
|
92
|
-
EVENT_ENGINE = EventEngine()
|
|
93
|
-
EVENT_ENGINE.start()
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# register handler
|
|
97
|
-
def test_handler(**kwargs):
|
|
98
|
-
print(kwargs)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
topic = EVENT_ENGINE.get_timer(interval=1)
|
|
102
|
-
EVENT_ENGINE.register_handler(topic=topic, handler=test_handler)
|
|
103
|
-
|
|
104
|
-
# publish message
|
|
105
|
-
time.sleep(5)
|
|
106
|
-
EVENT_ENGINE.stop()
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
See more advanced usage at .Demo
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyEventEngine
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: Basic event engine
|
|
5
|
+
Home-page: https://github.com/BolunHan/PyEventEngine.git
|
|
6
|
+
Author: Bolun.Han
|
|
7
|
+
Author-email: Bolun.Han@outlook.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
|
|
19
|
+
# PyEventEngine
|
|
20
|
+
|
|
21
|
+
python native event engine
|
|
22
|
+
|
|
23
|
+
# Install
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
pip install git+https://github.com/BolunHan/PyEventEngine.git
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
pip install PyEventEngine
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# Use
|
|
36
|
+
|
|
37
|
+
## basic usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
# init event engine
|
|
41
|
+
import time
|
|
42
|
+
from event_engine import EventEngine, Topic
|
|
43
|
+
|
|
44
|
+
EVENT_ENGINE = EventEngine()
|
|
45
|
+
EVENT_ENGINE.start()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# register handler
|
|
49
|
+
def test_handler(msg, **kwargs):
|
|
50
|
+
print(msg)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
EVENT_ENGINE.register_handler(topic=Topic('SimpleTopic'), handler=test_handler)
|
|
54
|
+
|
|
55
|
+
# publish message
|
|
56
|
+
EVENT_ENGINE.put(topic=Topic('SimpleTopic'), msg='topic called')
|
|
57
|
+
time.sleep(1)
|
|
58
|
+
EVENT_ENGINE.stop()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## regular topic
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
# init event engine
|
|
65
|
+
import time
|
|
66
|
+
from event_engine import EventEngine, Topic, RegularTopic
|
|
67
|
+
|
|
68
|
+
EVENT_ENGINE = EventEngine()
|
|
69
|
+
EVENT_ENGINE.start()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# register handler
|
|
73
|
+
def test_handler(msg, **kwargs):
|
|
74
|
+
print(msg)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
EVENT_ENGINE.register_handler(topic=RegularTopic('RegularTopic.*'), handler=test_handler)
|
|
78
|
+
|
|
79
|
+
# publish message
|
|
80
|
+
EVENT_ENGINE.put(topic=Topic('RegularTopic.ChildTopic0'), msg='topic called')
|
|
81
|
+
time.sleep(1)
|
|
82
|
+
EVENT_ENGINE.stop()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## timer topic
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# init event engine
|
|
89
|
+
import time
|
|
90
|
+
from event_engine import EventEngine, Topic, RegularTopic
|
|
91
|
+
|
|
92
|
+
EVENT_ENGINE = EventEngine()
|
|
93
|
+
EVENT_ENGINE.start()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# register handler
|
|
97
|
+
def test_handler(**kwargs):
|
|
98
|
+
print(kwargs)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
topic = EVENT_ENGINE.get_timer(interval=1)
|
|
102
|
+
EVENT_ENGINE.register_handler(topic=topic, handler=test_handler)
|
|
103
|
+
|
|
104
|
+
# publish message
|
|
105
|
+
time.sleep(5)
|
|
106
|
+
EVENT_ENGINE.stop()
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
See more advanced usage at .Demo
|
|
@@ -7,8 +7,6 @@ PyEventEngine.egg-info/SOURCES.txt
|
|
|
7
7
|
PyEventEngine.egg-info/dependency_links.txt
|
|
8
8
|
PyEventEngine.egg-info/top_level.txt
|
|
9
9
|
event_engine/__init__.py
|
|
10
|
-
event_engine/cpp/topic_api.cpp
|
|
11
|
-
event_engine/cpp/topic_api.cpp
|
|
12
10
|
event_engine/native/__init__.py
|
|
13
11
|
event_engine/native/_event.py
|
|
14
12
|
event_engine/native/_topic.py
|
|
@@ -139,7 +139,7 @@ class EventEngineBase(object):
|
|
|
139
139
|
self._get_lock = Semaphore(0)
|
|
140
140
|
self._deque: deque[EventDict] = deque(maxlen=buffer_size if buffer_size else None)
|
|
141
141
|
self._active: bool = False
|
|
142
|
-
self._engine: Thread =
|
|
142
|
+
self._engine: Thread = None
|
|
143
143
|
self._event_hooks: dict[Topic, EventHook] = {}
|
|
144
144
|
|
|
145
145
|
if buffer_size and buffer_size < 8:
|
|
@@ -184,6 +184,7 @@ class EventEngineBase(object):
|
|
|
184
184
|
return
|
|
185
185
|
|
|
186
186
|
self._active = True
|
|
187
|
+
self._engine = Thread(target=self._run, name='EventEngine')
|
|
187
188
|
self._engine.start()
|
|
188
189
|
|
|
189
190
|
def stop(self) -> None:
|
|
@@ -198,6 +199,18 @@ class EventEngineBase(object):
|
|
|
198
199
|
self._get_lock.release()
|
|
199
200
|
self._engine.join()
|
|
200
201
|
|
|
202
|
+
def clear(self) -> None:
|
|
203
|
+
if self._active:
|
|
204
|
+
self.logger.error('EventEngine must be stopped before cleared!')
|
|
205
|
+
return
|
|
206
|
+
|
|
207
|
+
self._event_hooks.clear()
|
|
208
|
+
self._deque.clear()
|
|
209
|
+
|
|
210
|
+
if self._buffer_size:
|
|
211
|
+
self._put_lock._value = self._buffer_size
|
|
212
|
+
self._get_lock._value = 0
|
|
213
|
+
|
|
201
214
|
def put(self, topic: str | Topic, block: bool = True, timeout: float = None, *args, **kwargs):
|
|
202
215
|
"""
|
|
203
216
|
fast way to put an event, kwargs MUST NOT contain "topic", "block" and "timeout" keywords
|
|
@@ -384,3 +397,9 @@ class EventEngine(EventEngineBase):
|
|
|
384
397
|
|
|
385
398
|
for timer in self.timer.values():
|
|
386
399
|
timer.join()
|
|
400
|
+
|
|
401
|
+
def clear(self) -> None:
|
|
402
|
+
for t in self.timer.values():
|
|
403
|
+
t.join(timeout=0)
|
|
404
|
+
|
|
405
|
+
self.timer.clear()
|
|
@@ -116,7 +116,7 @@ class PatternTopic(Topic):
|
|
|
116
116
|
pattern_parts = pattern.split('.')
|
|
117
117
|
|
|
118
118
|
# Check if the number of parts in result and pattern are the same
|
|
119
|
-
if len(result_parts)
|
|
119
|
+
if len(result_parts) < len(pattern_parts):
|
|
120
120
|
raise cls.NotMatchError(f'Target {target} not match with pattern {pattern}.')
|
|
121
121
|
|
|
122
122
|
# Generate the mapping dictionary
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import ctypes
|
|
4
|
-
import pathlib
|
|
5
|
-
import platform
|
|
6
|
-
import re
|
|
7
|
-
|
|
8
|
-
from ._topic import Topic, RegularTopic as RegularTopicBase, PatternTopic as PatternTopicBase
|
|
9
|
-
|
|
10
|
-
__all__ = ['Topic', 'RegularTopic', 'PatternTopic']
|
|
11
|
-
|
|
12
|
-
topic_lib = None
|
|
13
|
-
|
|
14
|
-
if platform.system() == 'Windows':
|
|
15
|
-
package_name = 'topic_api.(.*).pyd'
|
|
16
|
-
elif platform.system() == 'Darwin':
|
|
17
|
-
package_name = '^topic_api(.*).so$'
|
|
18
|
-
else:
|
|
19
|
-
package_name = '^topic_api(.*).so$'
|
|
20
|
-
|
|
21
|
-
ROOT_DIR = pathlib.Path(__file__).parent.parent
|
|
22
|
-
ENCODING = 'utf-8'
|
|
23
|
-
|
|
24
|
-
for _ in ROOT_DIR.iterdir():
|
|
25
|
-
if lib_path := re.search(package_name, _.name):
|
|
26
|
-
topic_lib = ctypes.CDLL(str(_))
|
|
27
|
-
break
|
|
28
|
-
|
|
29
|
-
# Load the shared library
|
|
30
|
-
if topic_lib is None:
|
|
31
|
-
raise ImportError(f'EventEngine.Topic c extension {package_name} not found in {ROOT_DIR}! Fallback to native lib!')
|
|
32
|
-
|
|
33
|
-
# Function prototypes
|
|
34
|
-
# topic_lib.delete_vector.restype = [ctypes.POINTER]
|
|
35
|
-
topic_lib.get_vector_value.restype = ctypes.c_char_p
|
|
36
|
-
topic_lib.is_regular_match.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
|
|
37
|
-
topic_lib.is_regular_match.restype = ctypes.c_int
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
# Define the RegularTopic class in Python
|
|
41
|
-
class RegularTopic(RegularTopicBase):
|
|
42
|
-
"""
|
|
43
|
-
topic in regular expression. e.g. "TickData.(.+).((SZ)|(SH)).((Realtime)|(History))"
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
def match(self, topic: str):
|
|
47
|
-
match = topic_lib.is_regular_match(topic.encode(ENCODING), self._value.encode(ENCODING))
|
|
48
|
-
|
|
49
|
-
if match:
|
|
50
|
-
return Topic(topic=topic, pattern=self.value)
|
|
51
|
-
else:
|
|
52
|
-
return None
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
# Define the PatternTopic class in Python
|
|
56
|
-
class PatternTopic(PatternTopicBase):
|
|
57
|
-
"""
|
|
58
|
-
topic for event hook. e.g. "TickData.{symbol}.{market}.{flag}"
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
def match(self, topic: str):
|
|
62
|
-
mapping = self.extract_mapping(target=topic, pattern=self._value, encoding=ENCODING)
|
|
63
|
-
|
|
64
|
-
if mapping:
|
|
65
|
-
return Topic(topic, pattern=self._value, **mapping)
|
|
66
|
-
else:
|
|
67
|
-
return None
|
|
68
|
-
|
|
69
|
-
@classmethod
|
|
70
|
-
def extract_mapping(cls, target: str, pattern: str, encoding: str = ENCODING) -> dict[str, str]:
|
|
71
|
-
# noinspection PyArgumentList
|
|
72
|
-
keys_ptr, values_ptr = ctypes.POINTER(ctypes.c_void_p)(), ctypes.POINTER(ctypes.c_void_p)()
|
|
73
|
-
mapping = {}
|
|
74
|
-
|
|
75
|
-
topic_lib.extract_mapping(
|
|
76
|
-
target.encode(encoding),
|
|
77
|
-
pattern.encode(encoding),
|
|
78
|
-
ctypes.byref(keys_ptr),
|
|
79
|
-
ctypes.byref(values_ptr)
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
for i in range(topic_lib.vector_size(ctypes.byref(keys_ptr))):
|
|
83
|
-
key = topic_lib.get_vector_value(ctypes.byref(keys_ptr), i)
|
|
84
|
-
value = topic_lib.get_vector_value(ctypes.byref(values_ptr), i)
|
|
85
|
-
# print(key, value)
|
|
86
|
-
mapping[key.decode(encoding)] = value.decode(encoding)
|
|
87
|
-
|
|
88
|
-
# topic_lib.delete_vector(ctypes.byref(keys_ptr))
|
|
89
|
-
# topic_lib.delete_vector(ctypes.byref(values_ptr))
|
|
90
|
-
|
|
91
|
-
del keys_ptr
|
|
92
|
-
del values_ptr
|
|
93
|
-
|
|
94
|
-
return mapping
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import pathlib
|
|
5
|
+
import platform
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
from ._topic import Topic, RegularTopic as RegularTopicBase, PatternTopic as PatternTopicBase
|
|
9
|
+
|
|
10
|
+
__all__ = ['Topic', 'RegularTopic', 'PatternTopic']
|
|
11
|
+
|
|
12
|
+
topic_lib = None
|
|
13
|
+
|
|
14
|
+
if platform.system() == 'Windows':
|
|
15
|
+
package_name = 'topic_api.(.*).pyd'
|
|
16
|
+
elif platform.system() == 'Darwin':
|
|
17
|
+
package_name = '^topic_api(.*).so$'
|
|
18
|
+
else:
|
|
19
|
+
package_name = '^topic_api(.*).so$'
|
|
20
|
+
|
|
21
|
+
ROOT_DIR = pathlib.Path(__file__).parent.parent
|
|
22
|
+
ENCODING = 'utf-8'
|
|
23
|
+
|
|
24
|
+
for _ in ROOT_DIR.iterdir():
|
|
25
|
+
if lib_path := re.search(package_name, _.name):
|
|
26
|
+
topic_lib = ctypes.CDLL(str(_))
|
|
27
|
+
break
|
|
28
|
+
|
|
29
|
+
# Load the shared library
|
|
30
|
+
if topic_lib is None:
|
|
31
|
+
raise ImportError(f'EventEngine.Topic c extension {package_name} not found in {ROOT_DIR}! Fallback to native lib!')
|
|
32
|
+
|
|
33
|
+
# Function prototypes
|
|
34
|
+
# topic_lib.delete_vector.restype = [ctypes.POINTER]
|
|
35
|
+
topic_lib.get_vector_value.restype = ctypes.c_char_p
|
|
36
|
+
topic_lib.is_regular_match.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
|
|
37
|
+
topic_lib.is_regular_match.restype = ctypes.c_int
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Define the RegularTopic class in Python
|
|
41
|
+
class RegularTopic(RegularTopicBase):
|
|
42
|
+
"""
|
|
43
|
+
topic in regular expression. e.g. "TickData.(.+).((SZ)|(SH)).((Realtime)|(History))"
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def match(self, topic: str):
|
|
47
|
+
match = topic_lib.is_regular_match(topic.encode(ENCODING), self._value.encode(ENCODING))
|
|
48
|
+
|
|
49
|
+
if match:
|
|
50
|
+
return Topic(topic=topic, pattern=self.value)
|
|
51
|
+
else:
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Define the PatternTopic class in Python
|
|
56
|
+
class PatternTopic(PatternTopicBase):
|
|
57
|
+
"""
|
|
58
|
+
topic for event hook. e.g. "TickData.{symbol}.{market}.{flag}"
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def match(self, topic: str):
|
|
62
|
+
mapping = self.extract_mapping(target=topic, pattern=self._value, encoding=ENCODING)
|
|
63
|
+
|
|
64
|
+
if mapping:
|
|
65
|
+
return Topic(topic, pattern=self._value, **mapping)
|
|
66
|
+
else:
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def extract_mapping(cls, target: str, pattern: str, encoding: str = ENCODING) -> dict[str, str]:
|
|
71
|
+
# noinspection PyArgumentList
|
|
72
|
+
keys_ptr, values_ptr = ctypes.POINTER(ctypes.c_void_p)(), ctypes.POINTER(ctypes.c_void_p)()
|
|
73
|
+
mapping = {}
|
|
74
|
+
|
|
75
|
+
topic_lib.extract_mapping(
|
|
76
|
+
target.encode(encoding),
|
|
77
|
+
pattern.encode(encoding),
|
|
78
|
+
ctypes.byref(keys_ptr),
|
|
79
|
+
ctypes.byref(values_ptr)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
for i in range(topic_lib.vector_size(ctypes.byref(keys_ptr))):
|
|
83
|
+
key = topic_lib.get_vector_value(ctypes.byref(keys_ptr), i)
|
|
84
|
+
value = topic_lib.get_vector_value(ctypes.byref(values_ptr), i)
|
|
85
|
+
# print(key, value)
|
|
86
|
+
mapping[key.decode(encoding)] = value.decode(encoding)
|
|
87
|
+
|
|
88
|
+
# topic_lib.delete_vector(ctypes.byref(keys_ptr))
|
|
89
|
+
# topic_lib.delete_vector(ctypes.byref(values_ptr))
|
|
90
|
+
|
|
91
|
+
del keys_ptr
|
|
92
|
+
del values_ptr
|
|
93
|
+
|
|
94
|
+
return mapping
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = PyEventEngine
|
|
3
|
+
version = attr: event_engine.__init__.__version__
|
|
4
|
+
author = Bolun.Han
|
|
5
|
+
author_email = Bolun.Han@outlook.com
|
|
6
|
+
description = Basic event engine
|
|
7
|
+
long_description = file: README.md
|
|
8
|
+
long_description_content_type = text/markdown
|
|
9
|
+
url = https://github.com/BolunHan/PyEventEngine.git
|
|
10
|
+
license = MIT
|
|
11
|
+
classifiers =
|
|
12
|
+
Programming Language :: Python :: 3.8
|
|
13
|
+
Programming Language :: Python :: 3.9
|
|
14
|
+
Programming Language :: Python :: 3.10
|
|
15
|
+
Programming Language :: Python :: 3.11
|
|
16
|
+
Programming Language :: Python :: 3.12
|
|
17
|
+
Operating System :: OS Independent
|
|
18
|
+
|
|
19
|
+
[egg_info]
|
|
20
|
+
tag_build =
|
|
21
|
+
tag_date = 0
|
|
22
|
+
|
|
@@ -44,10 +44,23 @@ setuptools.setup(
|
|
|
44
44
|
"Programming Language :: Python :: 3.12",
|
|
45
45
|
"Operating System :: OS Independent",
|
|
46
46
|
],
|
|
47
|
-
python_requires='>=3.
|
|
47
|
+
python_requires='>=3.12',
|
|
48
48
|
license='MIT',
|
|
49
49
|
install_requires=[],
|
|
50
|
-
ext_modules=[
|
|
51
|
-
|
|
52
|
-
],
|
|
50
|
+
# ext_modules=[
|
|
51
|
+
# setuptools.extension.Extension(r'event_engine.topic_api', sources=[r'event_engine/cpp/topic_api.cpp'], include_dirs=[], language='c++', optional=True),
|
|
52
|
+
# setuptools.extension.Extension(r'event_engine.event_api', sources=[r'event_engine/cpp/event_api.cpp'], include_dirs=[], language='c++', optional=True)
|
|
53
|
+
# ],
|
|
54
|
+
command_options={
|
|
55
|
+
'nuitka': {
|
|
56
|
+
# boolean option, e.g. if you cared for C compilation commands
|
|
57
|
+
'--show-scons': ("setup.py", True),
|
|
58
|
+
# options without value, e.g. enforce using Clang
|
|
59
|
+
'--clang': ("setup.py", None),
|
|
60
|
+
# options with single values, e.g. enable a plugin of Nuitka
|
|
61
|
+
# '--enable-plugin': ("setup.py", "pyside2"),
|
|
62
|
+
# options with several values, e.g. avoiding including modules
|
|
63
|
+
# '--nofollow-import-to': ("setup.py", ["*.tests", "*.distutils"]),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
53
66
|
)
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
#include <iostream>
|
|
2
|
-
#include <regex>
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <unordered_map>
|
|
5
|
-
#include <utility>
|
|
6
|
-
#include <vector>
|
|
7
|
-
|
|
8
|
-
extern "C" {
|
|
9
|
-
#include <stdlib.h>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class Topic : public std::unordered_map<std::string, std::string> {
|
|
13
|
-
public:
|
|
14
|
-
class Error : public std::exception {
|
|
15
|
-
public:
|
|
16
|
-
explicit Error(std::string msg) : message(std::move(msg)) {}
|
|
17
|
-
|
|
18
|
-
[[nodiscard]] const char *what() const noexcept override { return message.c_str(); }
|
|
19
|
-
|
|
20
|
-
private:
|
|
21
|
-
std::string message;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
explicit Topic(std::string topic) : _value(std::move(topic)) {}
|
|
25
|
-
|
|
26
|
-
std::string value() const { return _value; }
|
|
27
|
-
|
|
28
|
-
virtual Topic match(const std::string &topic) const {
|
|
29
|
-
if (_value == topic) {
|
|
30
|
-
return Topic(topic);
|
|
31
|
-
} else {
|
|
32
|
-
return Topic("");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
std::string _value;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
class RegularTopic : public Topic {
|
|
40
|
-
public:
|
|
41
|
-
explicit RegularTopic(const std::string &pattern) : Topic(pattern) {}
|
|
42
|
-
|
|
43
|
-
static int is_match(const std::string &topic, const std::string &pattern) {
|
|
44
|
-
std::regex regex(pattern);
|
|
45
|
-
if (std::regex_match(topic, regex)) {
|
|
46
|
-
return 1;
|
|
47
|
-
} else {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Topic match(const std::string &topic) const override {
|
|
53
|
-
int result = is_match(topic, _value);
|
|
54
|
-
if (result == 1) {
|
|
55
|
-
Topic match(topic);
|
|
56
|
-
match["pattern"] = _value;
|
|
57
|
-
return match;
|
|
58
|
-
} else {
|
|
59
|
-
return Topic("");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
class PatternTopic : public Topic {
|
|
65
|
-
public:
|
|
66
|
-
explicit PatternTopic(const std::string &pattern) : Topic(pattern) {}
|
|
67
|
-
|
|
68
|
-
Topic format_map(const std::unordered_map<std::string, std::string> &mapping) const {
|
|
69
|
-
std::string result = _value;
|
|
70
|
-
|
|
71
|
-
std::vector<std::string> contentVec = keys();
|
|
72
|
-
|
|
73
|
-
for (const auto &content: contentVec) {
|
|
74
|
-
auto it = mapping.find(content);
|
|
75
|
-
if (it != mapping.end()) {
|
|
76
|
-
std::string replacement = it->second;
|
|
77
|
-
std::string searchStr = "{" + content + "}";
|
|
78
|
-
size_t startPos = result.find(searchStr);
|
|
79
|
-
while (startPos != std::string::npos) {
|
|
80
|
-
result.replace(startPos, searchStr.length(), replacement);
|
|
81
|
-
startPos = result.find(searchStr, startPos + replacement.length());
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return Topic(result);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
std::vector<std::string> keys() const {
|
|
90
|
-
std::vector<std::string> contentVec;
|
|
91
|
-
std::vector<std::string> keys;
|
|
92
|
-
|
|
93
|
-
size_t startPos = _value.find('{');
|
|
94
|
-
size_t endPos;
|
|
95
|
-
|
|
96
|
-
while (startPos != std::string::npos) {
|
|
97
|
-
endPos = _value.find('}', startPos + 1);
|
|
98
|
-
if (endPos == std::string::npos)
|
|
99
|
-
break;
|
|
100
|
-
|
|
101
|
-
std::string content = _value.substr(startPos + 1, endPos - startPos - 1);
|
|
102
|
-
keys.push_back(content);
|
|
103
|
-
|
|
104
|
-
startPos = _value.find('{', endPos + 1);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return keys;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
Topic match(const std::string &topic) const override {
|
|
111
|
-
std::unordered_map<std::string, std::string> keyword_dict = extract_mapping(topic, _value);
|
|
112
|
-
if (keyword_dict.empty()) {
|
|
113
|
-
return Topic("");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
Topic match(topic);
|
|
117
|
-
match.insert(keyword_dict.begin(), keyword_dict.end());
|
|
118
|
-
return match;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
static std::unordered_map<std::string, std::string> extract_mapping(const std::string &target, const std::string &pattern) {
|
|
122
|
-
std::unordered_map<std::string, std::string> dictionary;
|
|
123
|
-
|
|
124
|
-
std::vector<std::string> resultParts;
|
|
125
|
-
std::vector<std::string> patternParts;
|
|
126
|
-
|
|
127
|
-
// Split the result string by '.'
|
|
128
|
-
size_t startPos = 0;
|
|
129
|
-
size_t dotPos = target.find('.');
|
|
130
|
-
while (dotPos != std::string::npos) {
|
|
131
|
-
std::string part = target.substr(startPos, dotPos - startPos);
|
|
132
|
-
resultParts.push_back(part);
|
|
133
|
-
startPos = dotPos + 1;
|
|
134
|
-
dotPos = target.find('.', startPos);
|
|
135
|
-
}
|
|
136
|
-
std::string lastPart = target.substr(startPos);
|
|
137
|
-
resultParts.push_back(lastPart);
|
|
138
|
-
|
|
139
|
-
// Split the pattern string by '.'
|
|
140
|
-
startPos = 0;
|
|
141
|
-
dotPos = pattern.find('.');
|
|
142
|
-
while (dotPos != std::string::npos) {
|
|
143
|
-
std::string part = pattern.substr(startPos, dotPos - startPos);
|
|
144
|
-
patternParts.push_back(part);
|
|
145
|
-
startPos = dotPos + 1;
|
|
146
|
-
dotPos = pattern.find('.', startPos);
|
|
147
|
-
}
|
|
148
|
-
lastPart = pattern.substr(startPos);
|
|
149
|
-
patternParts.push_back(lastPart);
|
|
150
|
-
|
|
151
|
-
// Check if the number of parts in result and pattern are the same
|
|
152
|
-
if (resultParts.size() != patternParts.size()) {
|
|
153
|
-
return dictionary;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Generate the mapping dictionary
|
|
157
|
-
size_t numParts = resultParts.size();
|
|
158
|
-
for (size_t i = 0; i < numParts; ++i) {
|
|
159
|
-
std::string resultPart = resultParts[i];
|
|
160
|
-
std::string patternPart = patternParts[i];
|
|
161
|
-
|
|
162
|
-
if (patternPart.front() == '{' && patternPart.back() == '}') {
|
|
163
|
-
std::string content = patternPart.substr(1, patternPart.length() - 2);
|
|
164
|
-
dictionary[content] = resultPart;
|
|
165
|
-
} else {
|
|
166
|
-
if (resultPart != patternPart) {
|
|
167
|
-
dictionary.clear();
|
|
168
|
-
return dictionary;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return dictionary;
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
extern "C" {
|
|
177
|
-
Topic *create_topic(const char *topic) {
|
|
178
|
-
return new Topic(topic);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
void get_topic_value(const Topic *topic, char *buffer, size_t bufferSize) {
|
|
182
|
-
std::string value = topic->value();
|
|
183
|
-
strncpy(buffer, value.c_str(), bufferSize - 1);
|
|
184
|
-
buffer[bufferSize - 1] = '\0';
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const char *get_topic_value_no_buffer(const Topic *topic) {
|
|
188
|
-
return topic->_value.c_str();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
void delete_topic(Topic *topic) {
|
|
192
|
-
delete topic;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
Topic *match_topic(const Topic *topic, const char *match_topic) {
|
|
196
|
-
return new Topic(topic->match(match_topic));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
RegularTopic *create_regular_topic(const char *pattern) {
|
|
200
|
-
return new RegularTopic(pattern);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
Topic *match_regular_topic(const RegularTopic *topic, const char *match_topic) {
|
|
204
|
-
return new Topic(topic->match(match_topic));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
PatternTopic *create_pattern_topic(const char *pattern) {
|
|
208
|
-
return new PatternTopic(pattern);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
Topic *match_pattern_topic(const PatternTopic *topic, const char *match_topic) {
|
|
212
|
-
return new Topic(topic->match(match_topic));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
std::vector<std::string> *get_pattern_topic_keys(const PatternTopic *topic) {
|
|
216
|
-
return new std::vector<std::string>(topic->keys());
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
int is_regular_match(const char *topic, const char *pattern) {
|
|
220
|
-
std::string topicStr(topic);
|
|
221
|
-
std::string patternStr(pattern);
|
|
222
|
-
int result = RegularTopic::is_match(topicStr, patternStr);
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
void extract_mapping(const char *target, const char *pattern, std::vector<std::string> *keys, std::vector<std::string> *values) {
|
|
227
|
-
std::string target_str(target);
|
|
228
|
-
std::string pattern_str(pattern);
|
|
229
|
-
|
|
230
|
-
std::unordered_map<std::string, std::string> mapping = PatternTopic::extract_mapping(target_str, pattern_str);
|
|
231
|
-
|
|
232
|
-
// Populate the keys and values vectors
|
|
233
|
-
for (const auto &entry: mapping) {
|
|
234
|
-
keys->push_back(entry.first);
|
|
235
|
-
values->push_back(entry.second);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const char *get_vector_value(const std::vector<std::string> *vec, int index) {
|
|
240
|
-
if (index >= 0 && index < static_cast<int>(vec->size()))
|
|
241
|
-
return vec->at(index).c_str();
|
|
242
|
-
else
|
|
243
|
-
return "";
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
int vector_size(const std::vector<std::string> *vec) {
|
|
247
|
-
return vec->size();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
void delete_vector(const std::vector<std::string> *vec) {
|
|
251
|
-
delete vec;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
int main() {
|
|
256
|
-
Topic topic("TickData.002410.SZ.Realtime");
|
|
257
|
-
std::cout << topic.value() << std::endl;
|
|
258
|
-
|
|
259
|
-
RegularTopic regularTopic("TickData.(.+).((SZ)|(SH)).((Realtime)|(History))");
|
|
260
|
-
Topic match1 = regularTopic.match("TickData.1234.SZ.Realtime");
|
|
261
|
-
Topic match2 = regularTopic.match("OtherData.5678.SH.History");
|
|
262
|
-
std::cout << match1.value() << std::endl;
|
|
263
|
-
std::cout << match2.value() << std::endl;
|
|
264
|
-
|
|
265
|
-
PatternTopic patternTopic("TickData.{symbol}.{market}.{flag}");
|
|
266
|
-
for (const std::string &i: patternTopic.keys())
|
|
267
|
-
std::cout << i << std::endl;
|
|
268
|
-
|
|
269
|
-
Topic formatted = patternTopic.format_map({{"symbol", "AAPL"},
|
|
270
|
-
{"market", "NASDAQ"},
|
|
271
|
-
{"flag", "Realtime"}});
|
|
272
|
-
std::cout << formatted.value() << std::endl;
|
|
273
|
-
|
|
274
|
-
Topic match3 = patternTopic.match("TickData.ABC.NYSE.Realtime");
|
|
275
|
-
Topic match4 = patternTopic.match("OtherData.XYZ.LSE.History");
|
|
276
|
-
|
|
277
|
-
std::cout << "topic: " << match3.value() << std::endl;
|
|
278
|
-
for (const auto &entry: match3) {
|
|
279
|
-
std::cout << entry.first << " : " << entry.second << std::endl;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
std::cout << "topic: " << match4.value() << std::endl;
|
|
283
|
-
for (const auto &entry: match4) {
|
|
284
|
-
std::cout << entry.first << " : " << entry.second << std::endl;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return 0;
|
|
288
|
-
}
|
|
File without changes
|
{PyEventEngine-0.3.0.post5 → pyeventengine-0.3.2}/PyEventEngine.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|