Skip to content

Commit 6d4e57a

Browse files
committed
Refactor on_get_connections method and add test_dispatch_on_get_connections test
1 parent da9a91b commit 6d4e57a

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/grongier/cls/Grongier/PEX/Common.cls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,12 @@ ClassMethod OnGetConnections(
189189
set class = builtins.getattr(module, tClassname)
190190
set tClass = class."__new__"(class)
191191

192-
set tPythonList = tClass."_dispatch_on_get_connections"()
192+
set tPythonList = tClass."on_get_connections"()
193193
set tPythonListLen = tPythonList."__len__"()
194194
for i=0:1:(tPythonListLen-1) {
195195
set tPythonItem = tPythonList."__getitem__"(i)
196196
set pArray(tPythonItem) = ""
197+
#; set ^AALog(pItem.Name,tPythonItem) = ""
197198
}
198199

199200
quit

src/grongier/pex/_business_host.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def get_adapter_type():
354354
"""
355355
return
356356

357-
def _dispatch_on_get_connections(self) -> list:
357+
def on_get_connections(self) -> list:
358358
"""
359359
The OnGetConnections() method returns all of the targets of any SendRequestSync or SendRequestAsync
360360
calls for the class. Implement this method to allow connections between components to show up in
@@ -369,19 +369,42 @@ def _dispatch_on_get_connections(self) -> list:
369369
# get the source code of the class
370370
source = getsource(self.__class__)
371371
# find all invocations of send_request_sync and send_request_async
372-
for method in ['send_request_sync','send_request_async']:
372+
for method in ['send_request_sync','send_request_async','SendRequestSync','SendRequestAsync']:
373373
i = source.find(method)
374374
while i != -1:
375375
j = source.find("(",i)
376376
if j != -1:
377377
k = source.find(",",j)
378378
if k != -1:
379379
target = source[j+1:k]
380-
# trim " and ' from target
381-
target = target.strip('\'').strip('\"')
380+
if target.find("=") != -1:
381+
# it's a keyword argument, remove the keyword
382+
target = target[target.find("=")+1:].strip()
382383
if target not in targer_list:
383384
targer_list.append(target)
384385
i = source.find(method,i+1)
386+
387+
for target in targer_list:
388+
# if target is a string, remove the quotes
389+
if target[0] == "'" and target[-1] == "'":
390+
targer_list[targer_list.index(target)] = target[1:-1]
391+
elif target[0] == '"' and target[-1] == '"':
392+
targer_list[targer_list.index(target)] = target[1:-1]
393+
# if target is a variable, try to find the value of the variable
394+
else:
395+
self.on_init()
396+
try:
397+
if target.find("self.") != -1:
398+
# it's a class variable
399+
targer_list[targer_list.index(target)] = getattr(self,target[target.find(".")+1:])
400+
elif target.find(".") != -1:
401+
# it's a class variable
402+
targer_list[targer_list.index(target)] = getattr(getattr(self,target[:target.find(".")]),target[target.find(".")+1:])
403+
else:
404+
targer_list[targer_list.index(target)] = getattr(self,target)
405+
except Exception as e:
406+
pass
407+
385408
return targer_list
386409

387410
# It's a subclass of the standard JSONEncoder class that knows how to encode date/time, decimal types,

src/tests/test_business_host.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from registerFiles.obj import PostClass
1313

14+
from registerFiles.bs import RedditService
15+
1416
def test_dispatch_serializer():
1517
bh = _BusinessHost()
1618

@@ -118,4 +120,12 @@ def test_fullmessage():
118120
assert result.datetime == datetime(2020, 1, 1, 1, 1, 1)
119121
assert result.time == time(1, 1, 1)
120122

121-
123+
def test_dispatch_on_get_connections():
124+
bs = RedditService()
125+
bs.Limit = 1
126+
bs.on_init()
127+
_list = bs._dispatch_on_get_connections()
128+
_list_len = _list.__len__()
129+
for i in range(0, _list_len):
130+
print(_list.__getitem__(i))
131+
assert len(_list) == 1

0 commit comments

Comments
 (0)