easycoder 260108.1__py2.py3-none-any.whl → 260110.1__py2.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.

Potentially problematic release.


This version of easycoder might be problematic. Click here for more details.

easycoder/__init__.py CHANGED
@@ -9,10 +9,9 @@ from .ec_gclasses import *
9
9
  from .ec_graphics import *
10
10
  from .ec_handler import *
11
11
  from .ec_keyboard import *
12
- from .ec_mqtt import *
13
12
  from .ec_program import *
14
13
  from .ec_psutil import *
15
14
  from .ec_timestamp import *
16
15
  from .ec_value import *
17
16
 
18
- __version__ = "260108.1"
17
+ __version__ = "260110.1"
easycoder/ec_classes.py CHANGED
@@ -421,19 +421,13 @@ class ECList(ECValueHolder):
421
421
 
422
422
  # Set the value to an ECValue
423
423
  def setValue(self, value):
424
- varType = value.getType()
425
- if type_in(varType, (str, 'list')):
426
- content = value.getContent()
427
- if types_equal(varType, str):
428
- try:
429
- if content in ('', [], None): content = []
430
- else: content = json.loads(content)
431
- except:
432
- raise RuntimeError(None, 'ECList string value is not valid JSON') # type: ignore
433
- elif varType == None:
434
- content = []
424
+ content = value.getContent()
425
+ if content in ('', None): content = []
435
426
  else:
436
- raise RuntimeError(None, 'ECList can only hold list values or None') # type: ignore
427
+ try:
428
+ content = json.loads(content) # type: ignore
429
+ except:
430
+ pass
437
431
  super().setValue(content)
438
432
 
439
433
  def getValue(self):
easycoder/ec_core.py CHANGED
@@ -515,7 +515,7 @@ class Core(Handler):
515
515
  self.run(label)
516
516
  return next
517
517
 
518
- # get {variable) from {url} [or {command}]
518
+ # get {variable) from url {url} [or {command}]
519
519
  def k_get(self, command):
520
520
  if self.nextIsSymbol():
521
521
  record = self.getSymbolRecord()
easycoder/ec_handler.py CHANGED
@@ -76,4 +76,4 @@ class Handler:
76
76
 
77
77
  # Get the value of an unknown item (domain-specific)
78
78
  def getUnknownValue(self, value):
79
- return None # Unable to get value
79
+ return value
easycoder/ec_program.py CHANGED
@@ -119,15 +119,6 @@ class Program:
119
119
  self.useClass(Graphics)
120
120
  return True
121
121
 
122
- # Use the mqtt module
123
- def useMQTT(self):
124
- if self.psutil == None:
125
- print('Loading mqtt module')
126
- from .ec_mqtt import MQTT
127
- self.psutil = MQTT
128
- self.useClass(MQTT)
129
- return True
130
-
131
122
  # Use the psutil module
132
123
  def usePSUtil(self):
133
124
  if self.psutil == None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: easycoder
3
- Version: 260108.1
3
+ Version: 260110.1
4
4
  Summary: Rapid scripting in English
5
5
  Keywords: compiler,scripting,prototyping,programming,coding,python,low code,hypertalk,computer language,learn to code
6
6
  Author-email: Graham Trott <gtanyware@gmail.com>
@@ -1,15 +1,14 @@
1
- easycoder/__init__.py,sha256=oW8ul-SgIxWPDeKSUYVPmMz7dNoLbFU0bAMTZ3Co70E,416
1
+ easycoder/__init__.py,sha256=BGeDPezNlTrRuE_hKj-gFXQPiDOgUbJYjSM10Bi-7Ak,393
2
2
  easycoder/ec_border.py,sha256=2qgGYxB-tIk_ZM0CmW3Yt7TotlUwxwrN9fL3cCvn8eE,2599
3
- easycoder/ec_classes.py,sha256=52WQcx7eZMZUCgghtSggCToWoDt0MqTxBrGv_blm9Xc,17244
3
+ easycoder/ec_classes.py,sha256=LWxB8T2n8KYmVdmz9uqRJWfZ8gcwHg-UsledXz0PHTA,16869
4
4
  easycoder/ec_compiler.py,sha256=nAWaWvswTZpzNB_J--UWNVP7s7i7XuUnjKw8ZQ3ZHy4,7706
5
5
  easycoder/ec_condition.py,sha256=BU59phivUDEAjmhBZTVziJ510MswXAPV1kMTa2I8QoQ,785
6
- easycoder/ec_core.py,sha256=mhwxz4i9_3EKw5Izw50YOH6yEj8wCZMlNZdbMbVRoPo,103162
6
+ easycoder/ec_core.py,sha256=1T8duclQVnGmQOtwstt6J3SkRjDASm1YxEGYDAGDpsg,103166
7
7
  easycoder/ec_gclasses.py,sha256=MQumyaZp0WFcEXOlhKvLV-RjO2osFpZ-ja-EPw8Qsgg,6808
8
8
  easycoder/ec_graphics.py,sha256=7rbn2HBAbS6r88jCnwOo9svGfMLs-pBV0Hnj2QHEDrI,67371
9
- easycoder/ec_handler.py,sha256=d3IJq6zEiXYEQUz_sNxtuIM-VKfn6ESyUD4mGr2Ptpo,2680
9
+ easycoder/ec_handler.py,sha256=K_Md0SRx3AzzDD7PEaBs9FkA4qXSTL59tzhgv8CVuHE,2659
10
10
  easycoder/ec_keyboard.py,sha256=R6JvgUwvgj4pJiGwXbPrFmhC-DSxJbZQnPQ9pzabrMM,19705
11
- easycoder/ec_mqtt.py,sha256=sBz69QWXeCSMzllghzPZm_Z_2F-GFKgFVFCK2VXMK_c,8613
12
- easycoder/ec_program.py,sha256=zZ3utezhcaDJYGHeWjPShiqWSOhErj7wHoSHoMpE_vU,16354
11
+ easycoder/ec_program.py,sha256=0Hl3mSGBUfPVImy5dCQSWog_nel-iySpOWEfNPx2yBA,16163
13
12
  easycoder/ec_psutil.py,sha256=4rs6BT4gzzNsD3VZP4-p1B55HiOVK6rASyPYylUU8bI,1543
14
13
  easycoder/ec_timestamp.py,sha256=z-HonUY7BDjgVVf2W_qQynnFjwGc_dAYultFjAmrXpg,307
15
14
  easycoder/ec_value.py,sha256=EbWNhvK4PNX-1rW0ky8TLS4krQS5NDkwsJ7aJ4iZxx4,3554
@@ -52,8 +51,8 @@ easycoder/pre/icons/run.png,sha256=5hDyMPMlY9ypA_rR5gqM5hb4vGIg2A4_pcEmPCq0iaM,3
52
51
  easycoder/pre/icons/step.png,sha256=r4XW-2GBVrYm7kb-xvth7jHMX3g9Ge-3onfpdOHyhyE,8224
53
52
  easycoder/pre/icons/stop.png,sha256=MoK6EbWFxDBdCH_ojTehjb7ty_Ax27n-8fKK_yBonfs,1832
54
53
  easycoder/pre/icons/tick.png,sha256=OedASXJJTYvnza4J6Kv5m5lz6DrBfy667zX_WGgtbmM,9127
55
- easycoder-260108.1.dist-info/entry_points.txt,sha256=JXAZbenl0TnsIft2FcGJbJ-4qoztVu2FuT8PFmWFexM,44
56
- easycoder-260108.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
- easycoder-260108.1.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
58
- easycoder-260108.1.dist-info/METADATA,sha256=TE3DyArYVxVehFgAEEOmDyPMHbaYjD-TSie6MiAZfxc,7210
59
- easycoder-260108.1.dist-info/RECORD,,
54
+ easycoder-260110.1.dist-info/entry_points.txt,sha256=JXAZbenl0TnsIft2FcGJbJ-4qoztVu2FuT8PFmWFexM,44
55
+ easycoder-260110.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
56
+ easycoder-260110.1.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
57
+ easycoder-260110.1.dist-info/METADATA,sha256=tBSYXvSYFniI81bT0GZ02cSpWWDjJCLn672BGvZMu-U,7210
58
+ easycoder-260110.1.dist-info/RECORD,,
easycoder/ec_mqtt.py DELETED
@@ -1,249 +0,0 @@
1
- from easycoder import Handler, ECObject, ECValue, ECDictionary, FatalError, RuntimeError
2
- import paho.mqtt.client as mqtt
3
- import time
4
-
5
- #############################################################################
6
- # MQTT client class
7
- class MQTTClient():
8
- def __init__(self):
9
- super().__init__()
10
-
11
- def create(self, program, clientID, broker, port, topics):
12
- self.program = program
13
- self.clientID = clientID
14
- self.broker = broker
15
- self.port = port
16
- self.topics = topics
17
- self.onMessagePC = None
18
- self.client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id=self.clientID) # type: ignore
19
-
20
- # Setup callbacks
21
- self.client.on_connect = self.on_connect
22
- self.client.on_message = self.on_message
23
-
24
- def on_connect(self, client, userdata, flags, reason_code, properties):
25
- print(f"Client {self.clientID} connected")
26
- for item in self.topics:
27
- topic = self.program.getObject(self.program.getVariable(item))
28
- self.client.subscribe(topic.getName(), qos=topic.getQOS())
29
- print(f"Subscribed to topic: {topic.getName()} with QoS {topic.getQOS()}")
30
-
31
- def on_message(self, client, userdata, msg):
32
- # print(f"Message received on topic {msg.topic}: {msg.payload.decode()}")
33
- if self.onMessagePC is not None:
34
- self.message = msg
35
- self.program.run(self.onMessagePC)
36
- self.program.flushCB()
37
-
38
- def getMessageTopic(self):
39
- return self.message.topic
40
-
41
- def getMessagePayload(self):
42
- return self.message.payload.decode('utf-8')
43
-
44
- def onMessage(self, pc):
45
- self.onMessagePC = pc
46
-
47
- def sendMessage(self, topic, message, qos):
48
- self.client.publish(topic, message, qos=qos)
49
-
50
- def run(self):
51
- self.client.connect(self.broker, int(self.port), 60)
52
- self.client.loop_start()
53
-
54
- ###############################################################################
55
- # An MQTT topic
56
- class ECTopic(ECObject):
57
- def __init__(self):
58
- super().__init__()
59
-
60
- def create(self, name, qos=1):
61
- super().__init__()
62
- self.name = name
63
- self.qos = qos
64
-
65
- def getName(self):
66
- return self.name
67
-
68
- def getQOS(self):
69
- return self.qos
70
-
71
- ###############################################################################
72
- # The MQTT compiler and rutime handlers
73
- class MQTT(Handler):
74
-
75
- def __init__(self, compiler):
76
- Handler.__init__(self, compiler)
77
- self.spoke = None
78
-
79
- def getName(self):
80
- return 'mqtt'
81
-
82
- #############################################################################
83
- # Keyword handlers
84
-
85
- # init {topic} name {name} qos {qos}
86
- def k_init(self, command):
87
- if self.nextIsSymbol():
88
- record = self.getSymbolRecord()
89
- self.checkObjectType(record, ECTopic)
90
- command['topic'] = record['name']
91
- self.skip('name')
92
- command['name'] = self.nextValue()
93
- self.skip('qos')
94
- command['qos'] = self.nextValue()
95
- self.add(command)
96
- return True
97
- return False
98
-
99
- def r_init(self, command):
100
- record = self.getVariable(command['topic'])
101
- topic = ECTopic()
102
- topic.create(self.textify(command['name']), qos=int(self.textify(command['qos'])))
103
- record['object'] = topic
104
- return self.nextPC()
105
-
106
- # mqtt id {clientID} broker {broker} port {port} topics {topic} [and {topic} ...]
107
- def k_mqtt(self, command):
108
- while True:
109
- token = self.peek()
110
- if token == 'id':
111
- self.nextToken()
112
- command['clientID'] = self.nextValue()
113
- elif token == 'broker':
114
- self.nextToken()
115
- command['broker'] = self.nextValue()
116
- elif token == 'port':
117
- self.nextToken()
118
- command['port'] = self.nextValue()
119
- elif token == 'topics':
120
- self.nextToken()
121
- topics = []
122
- while self.nextIsSymbol():
123
- record = self.getSymbolRecord()
124
- self.checkObjectType(record, ECTopic())
125
- topics.append(record['name'])
126
- if self.peek() == 'and': self.nextToken()
127
- else:break
128
- command['topics'] = topics
129
- else:
130
- self.add(command)
131
- return True
132
- return False
133
-
134
- def r_mqtt(self, command):
135
- if hasattr(self.program, 'mqttClient'):
136
- raise RuntimeError(self.program, 'MQQT client already defined')
137
- clientID = self.textify(command['clientID'])
138
- broker = self.textify(command['broker'])
139
- port = self.textify(command['port'])
140
- topics = command['topics']
141
- client = MQTTClient()
142
- client.create(self.program, clientID, broker, port, topics)
143
- client.run()
144
- self.program.mqttClient = client
145
- return self.nextPC()
146
-
147
- # on mqtt message {action}
148
- def k_on(self, command):
149
- token = self.peek()
150
- if token == 'mqtt':
151
- self.nextToken()
152
- if self.nextIs('message'):
153
- self.nextToken()
154
- command['goto'] = 0
155
- self.add(command)
156
- cmd = {}
157
- cmd['domain'] = 'core'
158
- cmd['lino'] = command['lino']
159
- cmd['keyword'] = 'gotoPC'
160
- cmd['goto'] = 0
161
- cmd['debug'] = False
162
- self.add(cmd)
163
- # Add the action and a 'stop'
164
- self.compileOne()
165
- cmd = {}
166
- cmd['domain'] = 'core'
167
- cmd['lino'] = command['lino']
168
- cmd['keyword'] = 'stop'
169
- cmd['debug'] = False
170
- self.add(cmd)
171
- # Fixup the link
172
- command['goto'] = self.getCodeSize()
173
- return True
174
- return False
175
-
176
- def r_on(self, command):
177
- self.program.mqttClient.onMessage(self.nextPC()+1)
178
- return command['goto']
179
-
180
- # send {message} to {topic}
181
- def k_send(self, command):
182
- if self.nextIs('mqtt'):
183
- command['message'] = self.nextValue()
184
- self.skip('from')
185
- if self.nextIsSymbol():
186
- record = self.getSymbolRecord()
187
- self.checkObjectType(record, MQTTClient)
188
- command['from'] = record['name']
189
- self.skip('to')
190
- if self.nextIsSymbol():
191
- record = self.getSymbolRecord()
192
- self.checkObjectType(record, MQTTClient)
193
- command['to'] = record['name']
194
- self.add(command)
195
- return True
196
- return False
197
-
198
- def r_send(self, command):
199
- if not hasattr(self.program, 'mqttClient'):
200
- raise RuntimeError(self.program, 'No MQTT client defined')
201
- topic = self.getObject(self.getVariable(command['to']))
202
- message = self.textify(command['message'])
203
- self.program.mqttClient.sendMessage(topic.getName(), message, topic.getQOS())
204
- return self.nextPC()
205
-
206
- # Declare a topic variable
207
- def k_topic(self, command):
208
- self.compiler.addValueType()
209
- return self.compileVariable(command, 'ECTopic')
210
-
211
- def r_topic(self, command):
212
- return self.nextPC()
213
-
214
- #############################################################################
215
- # Compile a value in this domain
216
- def compileValue(self):
217
- token = self.nextToken()
218
- if token == 'mqtt':
219
- value = ECValue(domain=self.getName())
220
- token = self.nextToken()
221
- if token in ['topic', 'message']:
222
- value.setType(token)
223
- return value
224
- else:
225
- return self.getValue()
226
- return None
227
-
228
- #############################################################################
229
- # Modify a value or leave it unchanged.
230
- def modifyValue(self, value):
231
- return value
232
-
233
- #############################################################################
234
- # Value handlers
235
-
236
- def v_message(self, v):
237
- return self.program.mqttClient.getMessagePayload()
238
-
239
- def v_topic(self, v):
240
- return self.program.mqttClient.getMessageTopic()
241
-
242
- #############################################################################
243
- # Compile a condition
244
- def compileCondition(self):
245
- condition = {}
246
- return condition
247
-
248
- #############################################################################
249
- # Condition handlers