id
int64 0
843k
| repository_name
stringlengths 7
55
| file_path
stringlengths 9
332
| class_name
stringlengths 3
290
| human_written_code
stringlengths 12
4.36M
| class_skeleton
stringlengths 19
2.2M
| total_program_units
int64 1
9.57k
| total_doc_str
int64 0
4.2k
| AvgCountLine
float64 0
7.89k
| AvgCountLineBlank
float64 0
300
| AvgCountLineCode
float64 0
7.89k
| AvgCountLineComment
float64 0
7.89k
| AvgCyclomatic
float64 0
130
| CommentToCodeRatio
float64 0
176
| CountClassBase
float64 0
48
| CountClassCoupled
float64 0
589
| CountClassCoupledModified
float64 0
581
| CountClassDerived
float64 0
5.37k
| CountDeclInstanceMethod
float64 0
4.2k
| CountDeclInstanceVariable
float64 0
299
| CountDeclMethod
float64 0
4.2k
| CountDeclMethodAll
float64 0
4.2k
| CountLine
float64 1
115k
| CountLineBlank
float64 0
9.01k
| CountLineCode
float64 0
94.4k
| CountLineCodeDecl
float64 0
46.1k
| CountLineCodeExe
float64 0
91.3k
| CountLineComment
float64 0
27k
| CountStmt
float64 1
93.2k
| CountStmtDecl
float64 0
46.1k
| CountStmtExe
float64 0
90.2k
| MaxCyclomatic
float64 0
759
| MaxInheritanceTree
float64 0
16
| MaxNesting
float64 0
34
| SumCyclomatic
float64 0
6k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
500 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget/client.py
|
client.DemoWidget
|
class DemoWidget(xbahn.api.Widget):
pass
|
class DemoWidget(xbahn.api.Widget):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
501 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/client.py
|
client.DemoWidget
|
class DemoWidget(xbahn.api.Widget):
_slapped = False
@xbahn.api.expose
def slapped(self):
"""
Returns self._slapped
"""
return self._slapped
@xbahn.api.expose
def slap(self):
"""
Something for the server widget to call
"""
self._slapped = True
|
class DemoWidget(xbahn.api.Widget):
@xbahn.api.expose
def slapped(self):
'''
Returns self._slapped
'''
pass
@xbahn.api.expose
def slapped(self):
'''
Something for the server widget to call
'''
pass
| 5 | 2 | 5 | 0 | 2 | 3 | 1 | 0.75 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 11 | 17 | 3 | 8 | 6 | 3 | 6 | 6 | 4 | 3 | 1 | 3 | 0 | 2 |
502 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api_twoway_comm.py
|
test_api_twoway_comm.Base
|
class Base(object):
class TestAPI2Way(XbahnTestCase):
def setUp(self):
# set up the server link, which will be able to
# receive requests from the client and respond
# to them
self.link_server = link.Link()
self.link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
# set up the client link
self.link_client = link.Link()
# first client link wire allows it to send requests
# to the server and receive server responses
self.link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0],
# we will send a meta variable called "remote"
# with every message that will let the server know
# how initiated two-way communication
meta={"remote": self.listeners[1].remote}
)
# second client link wire allows it to receive
# requests from the server and respond to them
self.link_client.wire(
"responder",
receive=self.listeners[1],
respond=self.listeners[1]
)
@pytest.mark.timeout(2)
def test_dispatch(self):
server = Server(link=self.link_server)
client_a = Client(link=self.link_client)
self.assertEqual(client_a.hello(), "hello")
self.assertIn(client_a.id, server.clients)
self.assertEqual(server[client_a.id].test(),
"%s reporting" % client_a.id)
@pytest.mark.timeout(5)
def test_inactivity_timeout(self):
"""
Tests that clients that havent been active will be closed and
removed
"""
server = Server(link=self.link_server, inactive_timeout=2)
client_a = Client(link=self.link_client)
self.assertEqual(client_a.hello(), "hello")
time.sleep(1)
self.assertIn(client_a.id, server.clients)
time.sleep(2.5)
self.assertNotIn(client_a.id, server.clients)
|
class Base(object):
class TestAPI2Way(XbahnTestCase):
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_dispatch(self):
pass
@pytest.mark.timeout(5)
def test_inactivity_timeout(self):
'''
Tests that clients that havent been active will be closed and
removed
'''
pass
| 7 | 1 | 19 | 3 | 11 | 5 | 1 | 0.41 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 65 | 13 | 37 | 13 | 30 | 15 | 22 | 11 | 17 | 1 | 1 | 0 | 3 |
503 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api.py
|
test_api.Base.APITestCase
|
class APITestCase(XbahnTestCase):
def setUp(self):
self.server_link = link.Link()
self.server_link.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
self.client_link = link.Link()
self.client_link.wire(
"main",
receive=self.connections[0],
send=self.connections[0]
)
@pytest.mark.timeout(2)
def test_dispatch(self):
"""
tests dispatching function call from api client to api server
"""
server = Server(link=self.server_link)
client = api.Client(link=self.client_link)
self.assertEqual(client.action_a(), "a")
self.assertEqual(client.action_b("test"), "b:test")
self.assertEqual(client.action_c(
"test", extra="more"), "c (test) extra=more")
self.assertEqual(client.action_d(), "d")
with self.assertRaises(exceptions.APIError) as inst:
client.action_forbidden()
with self.assertRaises(exceptions.APIError) as inst:
client.action_error()
self.assertEqual(str(inst), "Abandon ship!")
@pytest.mark.timeout(2)
def test_dispatch_routing(self):
"""
tests xbahn routing in api
"""
server_a = Server(link=self.server_link, path="route_a")
server_b = Server(link=self.server_link, path="route_b")
client_a = api.Client(link=self.client_link, path="route_a")
client_b = api.Client(link=self.client_link, path="route_b")
self.assertEqual(client_a.my_route(), client_a.path)
self.assertEqual(client_b.my_route(), client_b.path)
@pytest.mark.timeout(2)
def test_auth_handler(self):
server = Server(link=self.server_link, handlers=[
api.AuthHandler("secretkey")])
client_a = api.Client(link=self.client_link, handlers=[
api.AuthHandler("secretkey")])
self.assertEqual(client_a.action_a(), "a")
with self.assertRaises(exceptions.APIError) as inst:
client_b = api.Client(link=self.client_link)
self.assertEqual(str(inst), "Athentication failed.")
|
class APITestCase(XbahnTestCase):
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_dispatch(self):
'''
tests dispatching function call from api client to api server
'''
pass
@pytest.mark.timeout(2)
def test_dispatch_routing(self):
'''
tests xbahn routing in api
'''
pass
@pytest.mark.timeout(2)
def test_auth_handler(self):
pass
| 8 | 2 | 14 | 3 | 10 | 2 | 1 | 0.14 | 1 | 6 | 5 | 1 | 4 | 2 | 4 | 79 | 63 | 14 | 43 | 21 | 35 | 6 | 32 | 16 | 27 | 1 | 3 | 1 | 4 |
504 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api.py
|
test_api.Base
|
class Base(object):
"""
Keep the base test case in here so pytest does not
pick it up
"""
class APITestCase(XbahnTestCase):
def setUp(self):
self.server_link = link.Link()
self.server_link.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
self.client_link = link.Link()
self.client_link.wire(
"main",
receive=self.connections[0],
send=self.connections[0]
)
@pytest.mark.timeout(2)
def test_dispatch(self):
"""
tests dispatching function call from api client to api server
"""
server = Server(link=self.server_link)
client = api.Client(link=self.client_link)
self.assertEqual(client.action_a(), "a")
self.assertEqual(client.action_b("test"), "b:test")
self.assertEqual(client.action_c(
"test", extra="more"), "c (test) extra=more")
self.assertEqual(client.action_d(), "d")
with self.assertRaises(exceptions.APIError) as inst:
client.action_forbidden()
with self.assertRaises(exceptions.APIError) as inst:
client.action_error()
self.assertEqual(str(inst), "Abandon ship!")
@pytest.mark.timeout(2)
def test_dispatch_routing(self):
"""
tests xbahn routing in api
"""
server_a = Server(link=self.server_link, path="route_a")
server_b = Server(link=self.server_link, path="route_b")
client_a = api.Client(link=self.client_link, path="route_a")
client_b = api.Client(link=self.client_link, path="route_b")
self.assertEqual(client_a.my_route(), client_a.path)
self.assertEqual(client_b.my_route(), client_b.path)
@pytest.mark.timeout(2)
def test_auth_handler(self):
server = Server(link=self.server_link, handlers=[
api.AuthHandler("secretkey")])
client_a = api.Client(link=self.client_link, handlers=[
api.AuthHandler("secretkey")])
self.assertEqual(client_a.action_a(), "a")
with self.assertRaises(exceptions.APIError) as inst:
client_b = api.Client(link=self.client_link)
self.assertEqual(str(inst), "Athentication failed.")
|
class Base(object):
'''
Keep the base test case in here so pytest does not
pick it up
'''
class APITestCase(XbahnTestCase):
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_dispatch(self):
'''
tests dispatching function call from api client to api server
'''
pass
@pytest.mark.timeout(2)
def test_dispatch_routing(self):
'''
tests xbahn routing in api
'''
pass
@pytest.mark.timeout(2)
def test_auth_handler(self):
pass
| 9 | 3 | 14 | 3 | 10 | 2 | 1 | 0.23 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 70 | 16 | 44 | 22 | 35 | 10 | 33 | 17 | 27 | 1 | 1 | 1 | 4 |
505 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/engineer/server.py
|
server.Server
|
class Server(api.Server):
status = "ok"
def do(self, what):
return "did %s" % what
|
class Server(api.Server):
def do(self, what):
pass
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
506 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/engineer/server.py
|
server.Server
|
class Server(api.Server):
status = "ok"
def do(self, what):
return "did %s" % what
|
class Server(api.Server):
def do(self, what):
pass
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
507 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/engineer/server.py
|
server.Server
|
class Server(api.Server):
status = "ok"
def do(self, what):
return "did %s" % what
|
class Server(api.Server):
def do(self, what):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
508 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget/server.py
|
server.DemoWidget
|
class DemoWidget(xbahn.api.Widget):
num = 0
@xbahn.api.expose
def set_number(self, num):
"""
Something for our client widget to call
"""
self.num = num
@xbahn.api.expose
def get_number(self):
"""
Returns the value in self.num
"""
return self.num
|
class DemoWidget(xbahn.api.Widget):
@xbahn.api.expose
def set_number(self, num):
'''
Something for our client widget to call
'''
pass
@xbahn.api.expose
def get_number(self):
'''
Returns the value in self.num
'''
pass
| 5 | 2 | 5 | 0 | 2 | 3 | 1 | 0.75 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 11 | 17 | 3 | 8 | 6 | 3 | 6 | 6 | 4 | 3 | 1 | 3 | 0 | 2 |
509 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/server.py
|
server.Server
|
class Server(xbahn.api.WidgetAwareServer):
pass
|
class Server(xbahn.api.WidgetAwareServer):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
510 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/server.py
|
server.Server
|
class Server(xbahn.api.WidgetAwareServer):
pass
|
class Server(xbahn.api.WidgetAwareServer):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
511 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/server.py
|
server.Server
|
class Server(xbahn.api.WidgetAwareServer):
pass
|
class Server(xbahn.api.WidgetAwareServer):
pass
| 1 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
512 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget/server.py
|
server.Server
|
class Server(xbahn.api.Server):
pass
|
class Server(xbahn.api.Server):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
513 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget/server.py
|
server.Server
|
class Server(xbahn.api.Server):
pass
|
class Server(xbahn.api.Server):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
514 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget/server.py
|
server.Server
|
class Server(xbahn.api.Server):
pass
|
class Server(xbahn.api.Server):
pass
| 1 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
515 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/widget_aware_server/server.py
|
server.DemoWidget
|
class DemoWidget(xbahn.api.Widget):
_poked = False
@xbahn.api.expose
def poked(self):
"""
Returns self._poked
"""
return self._poked
@xbahn.api.expose
def poke(self):
"""
Something for the client widget to call
"""
self._poked = True
# now call slap() on the client
self.slap()
|
class DemoWidget(xbahn.api.Widget):
@xbahn.api.expose
def poked(self):
'''
Returns self._poked
'''
pass
@xbahn.api.expose
def poked(self):
'''
Something for the client widget to call
'''
pass
| 5 | 2 | 7 | 1 | 3 | 4 | 1 | 0.78 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 11 | 20 | 4 | 9 | 6 | 4 | 7 | 7 | 4 | 4 | 1 | 3 | 0 | 2 |
516 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/one_way/server.py
|
server.Server
|
class Server(xbahn.api.Server):
@xbahn.api.expose
def ping(self):
"""
Something to call for our client
"""
return "pong!"
@xbahn.api.expose
def multiply(self, a, b):
"""
Multiply a with b and return result to client
"""
return int(a) * int(b)
|
class Server(xbahn.api.Server):
@xbahn.api.expose
def ping(self):
'''
Something to call for our client
'''
pass
@xbahn.api.expose
def multiply(self, a, b):
'''
Multiply a with b and return result to client
'''
pass
| 5 | 2 | 5 | 0 | 2 | 3 | 1 | 0.86 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 30 | 15 | 2 | 7 | 5 | 2 | 6 | 5 | 3 | 2 | 1 | 5 | 0 | 2 |
517 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/engineer/server.py
|
server.Engineer
|
class Engineer(engineer.ServerWidget):
@engineer.expose()
def status(self):
return self.comm.status
@engineer.argument("what")
@engineer.expose()
def do_something(self, what):
"""
Do the task specified in [WHAT]
"""
return self.comm.do(what)
@engineer.option("--extra/--no-extra", default=False, help="include extra info")
@engineer.expose()
def show(self, extra=False):
rv = ["Basic"]
if extra:
rv.append("Extra!!")
return rv
|
class Engineer(engineer.ServerWidget):
@engineer.expose()
def status(self):
pass
@engineer.argument("what")
@engineer.expose()
def do_something(self, what):
'''
Do the task specified in [WHAT]
'''
pass
@engineer.option("--extra/--no-extra", default=False, help="include extra info")
@engineer.expose()
def show(self, extra=False):
pass
| 9 | 1 | 4 | 0 | 3 | 1 | 1 | 0.2 | 1 | 0 | 0 | 0 | 3 | 0 | 3 | 14 | 20 | 2 | 15 | 8 | 6 | 3 | 10 | 5 | 6 | 2 | 4 | 1 | 4 |
518 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api_twoway_comm.py
|
test_api_twoway_comm.Base.TestAPI2Way
|
class TestAPI2Way(XbahnTestCase):
def setUp(self):
# set up the server link, which will be able to
# receive requests from the client and respond
# to them
self.link_server = link.Link()
self.link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
# set up the client link
self.link_client = link.Link()
# first client link wire allows it to send requests
# to the server and receive server responses
self.link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0],
# we will send a meta variable called "remote"
# with every message that will let the server know
# how initiated two-way communication
meta={"remote": self.listeners[1].remote}
)
# second client link wire allows it to receive
# requests from the server and respond to them
self.link_client.wire(
"responder",
receive=self.listeners[1],
respond=self.listeners[1]
)
@pytest.mark.timeout(2)
def test_dispatch(self):
server = Server(link=self.link_server)
client_a = Client(link=self.link_client)
self.assertEqual(client_a.hello(), "hello")
self.assertIn(client_a.id, server.clients)
self.assertEqual(server[client_a.id].test(),
"%s reporting" % client_a.id)
@pytest.mark.timeout(5)
def test_inactivity_timeout(self):
"""
Tests that clients that havent been active will be closed and
removed
"""
server = Server(link=self.link_server, inactive_timeout=2)
client_a = Client(link=self.link_client)
self.assertEqual(client_a.hello(), "hello")
time.sleep(1)
self.assertIn(client_a.id, server.clients)
time.sleep(2.5)
self.assertNotIn(client_a.id, server.clients)
|
class TestAPI2Way(XbahnTestCase):
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_dispatch(self):
pass
@pytest.mark.timeout(5)
def test_inactivity_timeout(self):
'''
Tests that clients that havent been active will be closed and
removed
'''
pass
| 6 | 1 | 19 | 3 | 11 | 5 | 1 | 0.42 | 1 | 3 | 3 | 1 | 3 | 2 | 3 | 78 | 63 | 12 | 36 | 12 | 30 | 15 | 21 | 10 | 17 | 1 | 3 | 0 | 3 |
519 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/examples/api/two_way/server.py
|
server.Server
|
class Server(xbahn.api.ClientAwareServer):
@xbahn.api.expose
def ping(self):
"""
Something to call for our client
"""
return "pong!"
|
class Server(xbahn.api.ClientAwareServer):
@xbahn.api.expose
def ping(self):
'''
Something to call for our client
'''
pass
| 3 | 1 | 5 | 0 | 2 | 3 | 1 | 0.75 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 35 | 8 | 1 | 4 | 3 | 1 | 3 | 3 | 2 | 1 | 1 | 6 | 0 | 1 |
520 |
20c/xbahn
|
20c_xbahn/tests/test_engineer.py
|
test_engineer.Server
|
class Server(api.Server):
status = "ok"
|
class Server(api.Server):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 5 | 0 | 0 |
521 |
20c/xbahn
|
20c_xbahn/tests/test_engineer.py
|
test_engineer.TestEngineerZMQ
|
class TestEngineerZMQ(Base.EngineerTestCase):
def setUp(self):
self.setUpConnections(
[("REP", 0)],
[]
)
super(TestEngineerZMQ, self).setUp();
|
class TestEngineerZMQ(Base.EngineerTestCase):
def setUp(self):
pass
| 2 | 0 | 6 | 0 | 6 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 79 | 8 | 1 | 7 | 2 | 5 | 0 | 4 | 2 | 2 | 1 | 4 | 0 | 1 |
522 |
20c/xbahn
|
20c_xbahn/examples/api/widget_aware_server/client.py
|
client.Client
|
class Client(xbahn.api.Client):
pass
|
class Client(xbahn.api.Client):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
523 |
20c/xbahn
|
20c_xbahn/examples/api/widget_aware_server/client.py
|
client.Client
|
class Client(xbahn.api.Client):
pass
|
class Client(xbahn.api.Client):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
524 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api_widget.py
|
test_api_widget.Base.TestAPIWidget
|
class TestAPIWidget(XbahnTestCase):
def setUp(self):
pass
def test_widget_registry(self):
self.assertEqual(Server.widget.widgets["test"], ServerWidget)
self.assertEqual(Client.widget.widgets["test"], ClientWidget)
self.assertEqual(Client.widget.widgets["test2"], ClientWidgetB)
self.assertEqual(ClientWidgetB.remote_name, "test")
def _test_unaware_comm(self, server, client):
"""
Test widget communicating with widget unware server.
"""
widget = ClientWidget(client, "test_widget")
self.assertEqual(widget.hello(), "world")
widget.set_value(1)
self.assertEqual(widget.get_value(), 1)
widget_b = ClientWidget(client, "test_widget")
self.assertEqual(widget_b.get_value(), 1)
def _test_comm(self, server, client):
# instantiate client side widget
widget = ClientWidget(client, "test_widget")
# widget aware server should have created an instance of it's own
self.assertEqual(isinstance(
server.widgets["test"][widget.id], ServerWidget), True)
self.assertEqual(widget.path, "widgets.%s.%s" %
(ClientWidget.name, widget.id))
self.assertEqual(
widget.path, server.widgets["test"][widget.id].path)
# instnatiate another client side widget
widget_b = ClientWidgetB(client, "test_widget_b")
widget_b.hello()
# widget aware server should have created an instance of it's own (using remote_name
# to identify the widget class)
self.assertEqual(isinstance(
server.widgets["test"][widget_b.id], ServerWidget), True)
# client widget calling server widget method
self.assertEqual(widget.hello(), "world")
# server widget calling client widget method
self.assertEqual(server.widgets["test"][widget.id].ping(), "pong")
# ping doesnt exist on the second client
with self.assertRaises(exceptions.APIError) as inst:
server.widgets["test"][widget_b.id].ping()
# another instance of widget b
widget_b2 = ClientWidgetB(client, "test_widget_b")
widget.set_value("A")
widget_b.set_value("B")
self.assertEqual(widget.get_value(), "A")
self.assertEqual(widget_b.get_value(), "B")
self.assertEqual(widget_b2.get_value(), "B")
def _test_widget_timeout(self, server, client):
widget = ClientWidget(client, "test_widget")
self.assertEqual(isinstance(
server.widgets["test"][widget.id], ServerWidget), True)
time.sleep(1)
self.assertIn(widget.id, server.widgets["test"])
time.sleep(1.5)
self.assertNotIn(widget.id, server.widgets["test"])
widget.hello()
# server.clients[client.id].request_widget(widget.name, widget.id)
self.assertIn(widget.id, server.widgets["test"])
def _test_widget_routes(self, server_a, server_b, client_a, client_b):
widget_a = ClientWidget(client_a, "test_widget")
widget_b = ClientWidget(client_b, "test_widget")
self.assertEqual(widget_a.server_route(), "route_a")
self.assertEqual(widget_b.server_route(), "route_b")
server_a.widgets["test"][widget_a.id].set_number(10)
server_b.widgets["test"][widget_b.id].set_number(20)
self.assertEqual(widget_a.number, 10)
self.assertEqual(widget_b.number, 20)
def _test_widget_groups(self, server, client):
widget_a = ClientWidget(client, "widget_a", group="a")
widget_b = ClientWidget(client, "widget_b", group="a")
widget_c = ClientWidget(client, "widget_c")
group = client.widgets["test"].filter(group="a")
self.assertEqual(len(group), 2)
self.assertIn(widget_a.id, group)
self.assertIn(widget_b.id, group)
self.assertNotIn(widget_c.id, group)
group.set_value("testing")
self.assertEqual(
server.widgets["test"][widget_a.id].value, "testing")
self.assertEqual(
server.widgets["test"][widget_b.id].value, "testing")
self.assertEqual(server.widgets["test"][widget_c.id].value, None)
group = server.widgets["test"].filter(group="a")
self.assertEqual(len(group), 2)
self.assertIn(widget_a.id, group)
self.assertIn(widget_b.id, group)
self.assertNotIn(widget_c.id, group)
group.set_number(10)
self.assertEqual(widget_a.number, 10)
self.assertEqual(widget_b.number, 10)
self.assertEqual(widget_c.number, 0)
|
class TestAPIWidget(XbahnTestCase):
def setUp(self):
pass
def test_widget_registry(self):
pass
def _test_unaware_comm(self, server, client):
'''
Test widget communicating with widget unware server.
'''
pass
def _test_comm(self, server, client):
pass
def _test_widget_timeout(self, server, client):
pass
def _test_widget_routes(self, server_a, server_b, client_a, client_b):
pass
def _test_widget_groups(self, server, client):
pass
| 8 | 1 | 16 | 4 | 10 | 2 | 1 | 0.18 | 1 | 6 | 6 | 1 | 7 | 0 | 7 | 82 | 128 | 42 | 73 | 21 | 65 | 13 | 73 | 20 | 65 | 1 | 3 | 1 | 7 |
525 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api_widget.py
|
test_api_widget.TestAPIWidgetZMQ
|
class TestAPIWidgetZMQ(Base.TestAPIWidget):
def setUp(self):
self.setUpConnections(
[("REP", 0), ("REP", 1)],
[("REQ", 0), ("REQ", 0)]
)
@pytest.mark.timeout(2)
def test_unaware_comm_reqrep(self):
link_server = link.Link()
link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_client = link.Link()
link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0]
)
server = UnawareServer(link=link_server)
client = Client(link=link_client)
self._test_unaware_comm(server, client)
@pytest.mark.timeout(2)
def test_comm_reqrep(self):
link_server = link.Link()
link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_client = link.Link()
link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0],
meta={"remote": self.listeners[1].remote}
)
link_client.wire(
"responder",
receive=self.listeners[1],
respond=self.listeners[1]
)
server = Server(link=link_server)
client = Client(link=link_client)
self._test_comm(server, client)
@pytest.mark.timeout(4)
def test_widget_timeout(self):
link_server = link.Link()
link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_client = link.Link()
link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0],
meta={"remote": self.listeners[1].remote}
)
link_client.wire(
"responder",
receive=self.listeners[1],
respond=self.listeners[1]
)
server = Server(link=link_server, inactive_timeout=1.5)
client = Client(link=link_client)
self._test_widget_timeout(server, client)
@pytest.mark.timeout(2)
def test_widget_groups(self):
link_server = link.Link()
link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_client = link.Link()
link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0],
meta={"remote": self.listeners[1].remote}
)
link_client.wire(
"responder",
receive=self.listeners[1],
respond=self.listeners[1]
)
server = Server(link=link_server)
client = Client(link=link_client)
self._test_widget_groups(server, client)
@pytest.mark.timeout(2)
def test_widget_routes(self):
link_server = link.Link()
link_server.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_client = link.Link()
link_client.wire(
"main",
receive=self.connections[0],
send=self.connections[0],
meta={"remote": self.listeners[1].remote}
)
link_client.wire(
"responder",
receive=self.listeners[1],
respond=self.listeners[1]
)
server_a = Server(link=link_server, path="route_a")
server_b = Server(link=link_server, path="route_b")
client_a = Client(link=link_client, path="route_a")
client_b = Client(link=link_client, path="route_b")
self._test_widget_routes(server_a, server_b, client_a, client_b)
|
class TestAPIWidgetZMQ(Base.TestAPIWidget):
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_unaware_comm_reqrep(self):
pass
@pytest.mark.timeout(2)
def test_comm_reqrep(self):
pass
@pytest.mark.timeout(4)
def test_widget_timeout(self):
pass
@pytest.mark.timeout(2)
def test_widget_groups(self):
pass
@pytest.mark.timeout(2)
def test_widget_routes(self):
pass
| 12 | 0 | 20 | 2 | 19 | 0 | 1 | 0 | 1 | 4 | 4 | 0 | 6 | 0 | 6 | 88 | 136 | 19 | 117 | 34 | 105 | 0 | 49 | 29 | 42 | 1 | 4 | 0 | 6 |
526 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_api_widget.py
|
test_api_widget.UnawareServer.widget
|
class widget(api.Server.widget):
widgets = {}
|
class widget(api.Server.widget):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 1 | 0 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
527 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_connection_link.py
|
test_connection_link.Base
|
class Base(object):
"""
We keep the base test case in here, so it doesn't
get picked up by py.test
"""
class LinkTestCase(XbahnTestCase):
@pytest.mark.timeout(2)
def test_link_wire_cut(self):
"""
Test cutting and disconnecting wires
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0]
)
link_rep.wire(
"send_wire",
send=self.connections[0]
)
link_rep.cut("main")
self.assertEqual(getattr(link_rep, "main", None),
link_rep.send_wire)
link_rep.cut("send_wire")
self.assertEqual(getattr(link_rep, "main", None), None)
self.assertEqual(getattr(link_rep, "send_wire", None), None)
@pytest.mark.timeout(2)
def test_link_disconnect(self):
"""
Test cutting and disconnecting wires
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0]
)
link_rep.disconnect()
self.assertEqual(link_rep.main, None)
self.assertEqual(self.listeners[0].close_when_ready, True)
@pytest.mark.timeout(2)
def test_link_send_and_receive(self):
"""
Test sending and receiving via links (one connection each)
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0]
)
link_req = link.Link()
link_req.wire(
"main",
send=self.connections[0]
)
self.assertEqual(isinstance(link_req.main, link.Wire), True)
self.assertEqual(isinstance(link_rep.main, link.Wire), True)
status = {}
def rep_receive(**kwargs):
message = kwargs.get("message")
status[message.data] = True
link_rep.on("receive", rep_receive, once=True)
link_req.main.send("test", Message("Ping!"))
while status.get("Ping!") != True:
time.sleep(0.01)
@pytest.mark.timeout(2)
def test_link_receive_multiple(self):
"""
Test receiving from multiple connections
"""
link_rep = link.Link()
link_rep.wire(
"first",
receive=self.listeners[0]
)
link_rep.wire(
"second",
receive=self.listeners[1]
)
link_req = link.Link()
link_req.wire(
"first",
send=self.connections[0]
)
link_req.wire(
"second",
send=self.connections[1]
)
self.assertEqual(isinstance(link_req.first, link.Wire), True)
self.assertEqual(isinstance(link_req.second, link.Wire), True)
self.assertEqual(isinstance(link_rep.first, link.Wire), True)
self.assertEqual(isinstance(link_rep.second, link.Wire), True)
status = {}
def rep_receive(**kwargs):
message = kwargs.get("message")
status[message.data] = True
link_rep.on("receive", rep_receive)
link_req.first.send("test", Message("First!"))
link_req.second.send("test", Message("Second!"))
while status.get("First!") != True or status.get("Second!") != True:
time.sleep(0.01)
@pytest.mark.timeout(2)
def test_link_send_receive_respond(self):
"""
Tests responding to a received message
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_req = link.Link()
link_req.wire(
"main",
receive=self.connections[0],
send=self.connections[0]
)
self.assertEqual(isinstance(link_req.main, link.Wire), True)
self.assertEqual(isinstance(link_rep.main, link.Wire), True)
status = {}
def rep_receive_ping(**kwargs):
message = kwargs.get("message")
wire = kwargs.get("wire")
wire.respond(message, Message("Pong!"))
status[message.data] = True
def msg_response(message, **kwargs):
status[message.data] = True
ping_message = Message("Ping!")
ping_message.on("response", msg_response)
link_rep.on("receive_ping", rep_receive_ping, once=True)
link_req.main.send("ping", ping_message)
while status.get("Ping!") != True or status.get("Pong!") != True:
time.sleep(0.01)
|
class Base(object):
'''
We keep the base test case in here, so it doesn't
get picked up by py.test
'''
class LinkTestCase(XbahnTestCase):
@pytest.mark.timeout(2)
def test_link_wire_cut(self):
'''
Test cutting and disconnecting wires
'''
pass
@pytest.mark.timeout(2)
def test_link_disconnect(self):
'''
Test cutting and disconnecting wires
'''
pass
@pytest.mark.timeout(2)
def test_link_send_and_receive(self):
'''
Test sending and receiving via links (one connection each)
'''
pass
def rep_receive(**kwargs):
pass
@pytest.mark.timeout(2)
def test_link_receive_multiple(self):
'''
Test receiving from multiple connections
'''
pass
def rep_receive(**kwargs):
pass
@pytest.mark.timeout(2)
def test_link_send_receive_respond(self):
'''
Tests responding to a received message
'''
pass
def rep_receive_ping(**kwargs):
pass
def msg_response(message, **kwargs):
pass
| 16 | 6 | 18 | 3 | 13 | 2 | 1 | 0.17 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 172 | 40 | 113 | 32 | 97 | 19 | 73 | 27 | 62 | 2 | 1 | 1 | 12 |
528 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_connection_link.py
|
test_connection_link.Base.LinkTestCase
|
class LinkTestCase(XbahnTestCase):
@pytest.mark.timeout(2)
def test_link_wire_cut(self):
"""
Test cutting and disconnecting wires
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0]
)
link_rep.wire(
"send_wire",
send=self.connections[0]
)
link_rep.cut("main")
self.assertEqual(getattr(link_rep, "main", None),
link_rep.send_wire)
link_rep.cut("send_wire")
self.assertEqual(getattr(link_rep, "main", None), None)
self.assertEqual(getattr(link_rep, "send_wire", None), None)
@pytest.mark.timeout(2)
def test_link_disconnect(self):
"""
Test cutting and disconnecting wires
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0]
)
link_rep.disconnect()
self.assertEqual(link_rep.main, None)
self.assertEqual(self.listeners[0].close_when_ready, True)
@pytest.mark.timeout(2)
def test_link_send_and_receive(self):
"""
Test sending and receiving via links (one connection each)
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0]
)
link_req = link.Link()
link_req.wire(
"main",
send=self.connections[0]
)
self.assertEqual(isinstance(link_req.main, link.Wire), True)
self.assertEqual(isinstance(link_rep.main, link.Wire), True)
status = {}
def rep_receive(**kwargs):
message = kwargs.get("message")
status[message.data] = True
link_rep.on("receive", rep_receive, once=True)
link_req.main.send("test", Message("Ping!"))
while status.get("Ping!") != True:
time.sleep(0.01)
@pytest.mark.timeout(2)
def test_link_receive_multiple(self):
"""
Test receiving from multiple connections
"""
link_rep = link.Link()
link_rep.wire(
"first",
receive=self.listeners[0]
)
link_rep.wire(
"second",
receive=self.listeners[1]
)
link_req = link.Link()
link_req.wire(
"first",
send=self.connections[0]
)
link_req.wire(
"second",
send=self.connections[1]
)
self.assertEqual(isinstance(link_req.first, link.Wire), True)
self.assertEqual(isinstance(link_req.second, link.Wire), True)
self.assertEqual(isinstance(link_rep.first, link.Wire), True)
self.assertEqual(isinstance(link_rep.second, link.Wire), True)
status = {}
def rep_receive(**kwargs):
message = kwargs.get("message")
status[message.data] = True
link_rep.on("receive", rep_receive)
link_req.first.send("test", Message("First!"))
link_req.second.send("test", Message("Second!"))
while status.get("First!") != True or status.get("Second!") != True:
time.sleep(0.01)
@pytest.mark.timeout(2)
def test_link_send_receive_respond(self):
"""
Tests responding to a received message
"""
link_rep = link.Link()
link_rep.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
link_req = link.Link()
link_req.wire(
"main",
receive=self.connections[0],
send=self.connections[0]
)
self.assertEqual(isinstance(link_req.main, link.Wire), True)
self.assertEqual(isinstance(link_rep.main, link.Wire), True)
status = {}
def rep_receive_ping(**kwargs):
message = kwargs.get("message")
wire = kwargs.get("wire")
wire.respond(message, Message("Pong!"))
status[message.data] = True
def msg_response(message, **kwargs):
status[message.data] = True
ping_message = Message("Ping!")
ping_message.on("response", msg_response)
link_rep.on("receive_ping", rep_receive_ping, once=True)
link_req.main.send("ping", ping_message)
while status.get("Ping!") != True or status.get("Pong!") != True:
time.sleep(0.01)
|
class LinkTestCase(XbahnTestCase):
@pytest.mark.timeout(2)
def test_link_wire_cut(self):
'''
Test cutting and disconnecting wires
'''
pass
@pytest.mark.timeout(2)
def test_link_disconnect(self):
'''
Test cutting and disconnecting wires
'''
pass
@pytest.mark.timeout(2)
def test_link_send_and_receive(self):
'''
Test sending and receiving via links (one connection each)
'''
pass
def rep_receive(**kwargs):
pass
@pytest.mark.timeout(2)
def test_link_receive_multiple(self):
'''
Test receiving from multiple connections
'''
pass
def rep_receive(**kwargs):
pass
@pytest.mark.timeout(2)
def test_link_send_receive_respond(self):
'''
Tests responding to a received message
'''
pass
def rep_receive_ping(**kwargs):
pass
def msg_response(message, **kwargs):
pass
| 15 | 5 | 18 | 3 | 13 | 2 | 1 | 0.13 | 1 | 3 | 3 | 1 | 5 | 0 | 5 | 80 | 165 | 38 | 112 | 31 | 97 | 15 | 72 | 26 | 62 | 2 | 3 | 1 | 12 |
529 |
20c/xbahn
|
20c_xbahn/examples/api/widget/client.py
|
client.DemoWidget
|
class DemoWidget(xbahn.api.Widget):
pass
|
class DemoWidget(xbahn.api.Widget):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
530 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_connection_zmq.py
|
test_connection_zmq.TestCasePUBSUB
|
class TestCasePUBSUB(XbahnTestCase):
"""
Tests PUB / SUB connection
"""
def setUp(self):
self.setUpConnections(
[("PUB", 0)],
[("SUB", 0), ("SUB", 0)]
)
@pytest.mark.timeout(2)
def test_pub_sub(self):
"""
Tests a pub / sub exchange
"""
tester = self
counter = []
def handle_receive_connection(**kwargs):
message = kwargs.get("message")
event_origin = kwargs.get("event_origin")
tester.assertEqual(message.data, "Ping!")
counter.append(event_origin)
for conn in self.connections:
conn.on("receive", handle_receive_connection, once=True)
self.listeners[0].send(Message("Ping!"))
while len(counter) < len(self.connections):
time.sleep(0.01)
|
class TestCasePUBSUB(XbahnTestCase):
'''
Tests PUB / SUB connection
'''
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_pub_sub(self):
'''
Tests a pub / sub exchange
'''
pass
def handle_receive_connection(**kwargs):
pass
| 5 | 2 | 11 | 2 | 8 | 1 | 2 | 0.3 | 1 | 1 | 1 | 0 | 2 | 0 | 2 | 77 | 35 | 9 | 20 | 10 | 15 | 6 | 16 | 9 | 12 | 3 | 3 | 1 | 5 |
531 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_connection_zmq.py
|
test_connection_zmq.TestCaseREQREP
|
class TestCaseREQREP(XbahnTestCase):
"""
Tests REQ / REP connection
"""
def setUp(self):
self.setUpConnections(
[("REP", 0)],
[("REQ", 0)]
)
@pytest.mark.timeout(2)
def test_rep_req(self):
"""
Tests a rep / req exchange with a manually manufactored
response
"""
tester = self
counter = []
def handle_receive_listener(**kwargs):
message = kwargs.get("message")
event_origin = kwargs.get("event_origin")
self.assertEqual(message.data, "Hello")
event_origin.respond(message, Message("World"))
counter.append(event_origin)
def handle_receive_connection(**kwargs):
message = kwargs.get("message")
event_origin = kwargs.get("event_origin")
self.assertEqual(message.data, "World")
counter.append(event_origin)
self.listeners[0].on("receive", handle_receive_listener, once=True)
self.connections[0].on("receive", handle_receive_connection, once=True)
self.connections[0].send(Message("Hello"))
while len(counter) != 2:
time.sleep(0.01)
@pytest.mark.timeout(2)
def test_rep_req_auto_response(self):
"""
Tests a rep / req exchange with an automatically manufactured
null response from the rep connection
"""
tester = self
counter = []
def handle_receive_listener(**kwargs):
message = kwargs.get("message")
event_origin = kwargs.get("event_origin")
self.assertEqual(message.data, "Hello")
counter.append(event_origin)
def handle_receive_connection(**kwargs):
message = kwargs.get("message")
event_origin = kwargs.get("event_origin")
self.assertEqual(message.data, None)
counter.append(event_origin)
self.listeners[0].on("receive", handle_receive_listener, once=True)
self.connections[0].on("receive", handle_receive_connection, once=True)
self.connections[0].send(Message("Hello"))
while len(counter) != 2:
time.sleep(0.01)
|
class TestCaseREQREP(XbahnTestCase):
'''
Tests REQ / REP connection
'''
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_rep_req(self):
'''
Tests a rep / req exchange with a manually manufactored
response
'''
pass
def handle_receive_listener(**kwargs):
pass
def handle_receive_connection(**kwargs):
pass
@pytest.mark.timeout(2)
def test_rep_req_auto_response(self):
'''
Tests a rep / req exchange with an automatically manufactured
null response from the rep connection
'''
pass
def handle_receive_listener(**kwargs):
pass
def handle_receive_connection(**kwargs):
pass
| 10 | 3 | 12 | 2 | 9 | 1 | 1 | 0.24 | 1 | 1 | 1 | 0 | 3 | 0 | 3 | 78 | 76 | 20 | 45 | 22 | 35 | 11 | 40 | 20 | 32 | 2 | 3 | 1 | 9 |
532 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_engineer.py
|
test_engineer.Base.EngineerTestCase
|
class EngineerTestCase(XbahnTestCase):
def setUp(self):
self.server_link = link.Link()
self.server_link.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
self.cli = CliRunner()
self.host = self.listeners[0].remote.split("->")[1]
def mimic_output(self, command, result):
return "%s: %s> %s\n" % (self.host, command, result)
def test_engineer(self):
server = Server(link=self.server_link)
# Test status command
args = [self.host, "status"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output("status", "ok"))
# Test multiply command
args = [self.host, "multiply", "5", "2"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(
str(r.output), self.mimic_output("multiply", "10"))
# Test info command (without --extra)
args = [self.host, "info"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output("info", "ok"))
# Test info command (with --extra)
args = [self.host, "info", "--extra"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output(
"info", "status: ok, color: green"))
# Test help
args = [self.host, "multiply", "--help"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
expected = "\n".join([
"Usage: engineer zmq://addr1/req?transport=inproc multiply [OPTIONS] B A",
"",
" take a number and multiply it with another number",
"",
"Options:",
" --debug / --no-debug Show debug information",
" --help Show this message and exit.",
""
])
self.assertEqual(r.output, expected)
|
class EngineerTestCase(XbahnTestCase):
def setUp(self):
pass
def mimic_output(self, command, result):
pass
def test_engineer(self):
pass
| 4 | 0 | 24 | 4 | 18 | 2 | 1 | 0.09 | 1 | 3 | 2 | 1 | 3 | 3 | 3 | 78 | 75 | 16 | 54 | 11 | 50 | 5 | 31 | 11 | 27 | 1 | 3 | 0 | 3 |
533 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_engineer.py
|
test_engineer.Engineer
|
class Engineer(engineer.ServerWidget):
@engineer.expose()
def status(self):
return self.comm.status
@engineer.expose()
@engineer.argument("a", nargs=1)
@engineer.argument("b", nargs=1)
def multiply(self, a, b):
""" take a number and multiply it with another number """
return int(a) * int(b)
@engineer.expose()
@engineer.option("--extra/--no-extra", default=False, help="return extra information")
def info(self, extra):
if extra:
return "status: ok, color: green"
else:
return "ok"
|
class Engineer(engineer.ServerWidget):
@engineer.expose()
def status(self):
pass
@engineer.expose()
@engineer.argument("a", nargs=1)
@engineer.argument("b", nargs=1)
def multiply(self, a, b):
''' take a number and multiply it with another number '''
pass
@engineer.expose()
@engineer.option("--extra/--no-extra", default=False, help="return extra information")
def info(self, extra):
pass
| 10 | 1 | 3 | 0 | 3 | 0 | 1 | 0.06 | 1 | 1 | 0 | 0 | 3 | 0 | 3 | 14 | 20 | 3 | 16 | 7 | 6 | 1 | 9 | 4 | 5 | 2 | 4 | 1 | 4 |
534 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/xbahn/api.py
|
xbahn.api.Client.widget
|
class widget(Comm.widget):
"""
Decorator to register a widget for this Client class
"""
widgets = {}
def __init__(self, name, remote_name=None):
"""
Keyword Arguments:
- remote_name (str): name of the widget (server side), defaults to <name>
"""
Comm.widget.__init__(self, name)
self.remote_name = remote_name or name
def __call__(self, fn):
Comm.widget.__call__(self, fn)
fn.remote_name = self.remote_name
return fn
|
class widget(Comm.widget):
'''
Decorator to register a widget for this Client class
'''
def __init__(self, name, remote_name=None):
'''
Keyword Arguments:
- remote_name (str): name of the widget (server side), defaults to <name>
'''
pass
def __call__(self, fn):
pass
| 3 | 2 | 6 | 0 | 4 | 2 | 1 | 0.78 | 1 | 1 | 1 | 0 | 2 | 1 | 2 | 5 | 20 | 4 | 9 | 5 | 6 | 7 | 9 | 5 | 6 | 1 | 2 | 0 | 2 |
535 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/xbahn/api.py
|
xbahn.api.Comm.widget
|
class widget(object):
"""
Decorator to register a widget for this Communicator class
Attributes:
- widgets (dict): holds widgets registered to this communicator
via it's widget decorator
"""
widgets = {}
path = "widgets"
def __init__(self, name):
"""
Arguments:
- name (str): name of the widget
"""
self.name = name
def __call__(self, fn):
self.widgets[self.name] = fn
fn.name = self.name
return fn
def __getitem__(self, k):
return self.widgets.get(k)
|
class widget(object):
'''
Decorator to register a widget for this Communicator class
Attributes:
- widgets (dict): holds widgets registered to this communicator
via it's widget decorator
'''
def __init__(self, name):
'''
Arguments:
- name (str): name of the widget
'''
pass
def __call__(self, fn):
pass
def __getitem__(self, k):
pass
| 4 | 2 | 4 | 0 | 3 | 1 | 1 | 0.91 | 1 | 0 | 0 | 1 | 3 | 1 | 3 | 3 | 26 | 5 | 11 | 7 | 7 | 10 | 11 | 7 | 7 | 1 | 1 | 0 | 3 |
536 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.Engineer
|
class Engineer(click.Group):
"""
Extended click group that allows to fetch command information
from remote xbahn.api endpoint
"""
def connect(self, ctx):
"""
establish xbahn connection and store on click context
"""
if hasattr(ctx, "conn") or "host" not in ctx.params:
return
ctx.conn = conn = connect(ctx.params["host"])
lnk = link.Link()
lnk.wire("main", receive=conn, send=conn)
ctx.client = api.Client(link=lnk)
ctx.widget = ClientWidget(ctx.client, "engineer")
def list_commands(self, ctx):
"""
list all commands exposed to engineer
"""
self.connect(ctx)
if not hasattr(ctx, "widget"):
return super(Engineer, self).list_commands(ctx)
return ctx.widget.engineer_list_commands() + super(Engineer, self).list_commands(ctx)
def get_command(self, ctx, name):
"""
get click command from engineer exposed xbahn command specs
"""
# connect to xbahn
self.connect(ctx)
if not hasattr(ctx, "widget") or name in ["shell"]:
return super(Engineer, self).get_command(ctx, name)
if name == "--help":
return None
# get the command specs (description, arguments and options)
info = ctx.widget.engineer_info(name)
# make command from specs
return self.make_command(ctx, name, info)
def make_command(self, ctx, name, info):
"""
make click sub-command from command info
gotten from xbahn engineer
"""
@self.command()
@click.option("--debug/--no-debug", default=False, help="Show debug information")
@doc(info.get("description"))
def func(*args, **kwargs):
if "debug" in kwargs:
del kwargs["debug"]
fn = getattr(ctx.widget, name)
result = fn(*args, **kwargs)
click.echo("%s: %s> %s" % (ctx.params["host"], name, result))
ctx.conn.close()
ctx.info_name = "%s %s" % (ctx.info_name, ctx.params["host"])
for a in info.get("arguments", []):
deco = click.argument(*a["args"], **a["kwargs"])
func = deco(func)
for o in info.get("options", []):
deco = click.option(*o["args"], **o["kwargs"])
func = deco(func)
return func
|
class Engineer(click.Group):
'''
Extended click group that allows to fetch command information
from remote xbahn.api endpoint
'''
def connect(self, ctx):
'''
establish xbahn connection and store on click context
'''
pass
def list_commands(self, ctx):
'''
list all commands exposed to engineer
'''
pass
def get_command(self, ctx, name):
'''
get click command from engineer exposed xbahn command specs
'''
pass
def make_command(self, ctx, name, info):
'''
make click sub-command from command info
gotten from xbahn engineer
'''
pass
@self.command()
@click.option("--debug/--no-debug", default=False, help="Show debug information")
@doc(info.get("description"))
def func(*args, **kwargs):
pass
| 9 | 5 | 16 | 4 | 9 | 3 | 2 | 0.49 | 1 | 5 | 4 | 0 | 4 | 0 | 4 | 4 | 86 | 25 | 41 | 15 | 32 | 20 | 38 | 13 | 32 | 3 | 1 | 1 | 12 |
537 |
20c/xbahn
|
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/20c_xbahn/tests/test_connection_zmq.py
|
test_connection_zmq.TestCasePUSHPULL
|
class TestCasePUSHPULL(XbahnTestCase):
"""
Tests PUSH / PULL connection
"""
def setUp(self):
self.setUpConnections(
[("PUSH", 0)],
[("PULL", 0), ("PULL", 0)]
)
@pytest.mark.timeout(2)
def test_push_pull(self):
tester = self
status = {}
def handle_receive_connection(**kwargs):
message = kwargs.get("message")
event_origin = kwargs.get("event_origin")
self.assertIn(message.data, ["first", "second"])
status[message.data] = True
for conn in self.connections:
conn.on("receive", handle_receive_connection, once=True)
self.listeners[0].send(Message("first"))
self.listeners[0].send(Message("second"))
while "first" not in status or "second" not in status:
time.sleep(0.01)
|
class TestCasePUSHPULL(XbahnTestCase):
'''
Tests PUSH / PULL connection
'''
def setUp(self):
pass
@pytest.mark.timeout(2)
def test_push_pull(self):
pass
def handle_receive_connection(**kwargs):
pass
| 5 | 1 | 10 | 2 | 8 | 0 | 2 | 0.14 | 1 | 1 | 1 | 0 | 2 | 0 | 2 | 77 | 32 | 8 | 21 | 10 | 16 | 3 | 17 | 9 | 13 | 3 | 3 | 1 | 5 |
538 |
20c/xbahn
|
20c_xbahn/tests/test_path.py
|
test_path.PathTestCase
|
class PathTestCase(unittest.TestCase):
def test_append(self):
self.assertEqual(xbahn.path.append("a","b","c"), "a.b.c")
self.assertEqual(xbahn.path.append(".a.",".b","c."), "a.b.c")
self.assertEqual(xbahn.path.append("a","b","","c"), "a.b.c")
def test_split(self):
self.assertEqual(xbahn.path.split("a.b.c"), ["a","b","c"])
def test_walk(self):
r = [a for a in xbahn.path.walk("a.b.c")]
self.assertEqual(r, ["a", "a.b", "a.b.c"])
def test_match(self):
self.assertEqual(xbahn.path.match("a", "a.b.c"), True)
self.assertEqual(xbahn.path.match("a.b", "a.b.c"), True)
self.assertEqual(xbahn.path.match("a.b.c", "a.b.c"), True)
self.assertEqual(xbahn.path.match("a.c", "a.b.c"), False)
self.assertEqual(xbahn.path.match("a.b.d", "a.b.c"), False)
self.assertEqual(xbahn.path.match("b", "a.b.c"), False)
def test_tail(self):
r = xbahn.path.tail("part.1", "part.1.part.2.part.3")
self.assertEqual(r, ["part","2","part","3"])
r = xbahn.path.tail("part.2", "part.1.part.2.part.3")
self.assertEqual(r, [])
|
class PathTestCase(unittest.TestCase):
def test_append(self):
pass
def test_split(self):
pass
def test_walk(self):
pass
def test_match(self):
pass
def test_tail(self):
pass
| 6 | 0 | 6 | 1 | 4 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 5 | 0 | 5 | 77 | 34 | 12 | 22 | 8 | 16 | 0 | 22 | 8 | 16 | 1 | 2 | 0 | 5 |
539 |
20c/xbahn
|
20c_xbahn/tests/conftest.py
|
conftest.XbahnTestCase
|
class XbahnTestCase(unittest.TestCase):
def setUpConnections(self, listeners, connections, tmpl=URL_ZMQ):
self.listeners = []
self.connections = []
for typ, n in listeners:
self.listeners.append(listen(tmpl[n][typ]))
for typ, n in connections:
self.connections.append(connect(tmpl[n][typ]))
def tearDownConnections(self):
for connection in self.connections:
connection.destroy()
for listener in self.listeners:
listener.destroy()
def tearDown(self):
self.tearDownConnections()
|
class XbahnTestCase(unittest.TestCase):
def setUpConnections(self, listeners, connections, tmpl=URL_ZMQ):
pass
def tearDownConnections(self):
pass
def tearDownConnections(self):
pass
| 4 | 0 | 5 | 0 | 5 | 0 | 2 | 0 | 1 | 0 | 0 | 9 | 3 | 2 | 3 | 75 | 20 | 5 | 15 | 9 | 11 | 0 | 15 | 9 | 11 | 3 | 2 | 1 | 7 |
540 |
20c/xbahn
|
20c_xbahn/examples/api/widget_aware_server/server.py
|
server.Server
|
class Server(xbahn.api.WidgetAwareServer):
pass
|
class Server(xbahn.api.WidgetAwareServer):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
541 |
20c/xbahn
|
20c_xbahn/examples/api/widget_aware_server/server.py
|
server.Server
|
class Server(xbahn.api.WidgetAwareServer):
pass
|
class Server(xbahn.api.WidgetAwareServer):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
542 |
20c/xbahn
|
20c_xbahn/examples/api/widget_aware_server/server.py
|
server.Server
|
class Server(xbahn.api.WidgetAwareServer):
pass
|
class Server(xbahn.api.WidgetAwareServer):
pass
| 1 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
543 |
20c/xbahn
|
20c_xbahn/tests/test_engineer.py
|
test_engineer.Base
|
class Base(object):
class EngineerTestCase(XbahnTestCase):
def setUp(self):
self.server_link = link.Link()
self.server_link.wire(
"main",
receive=self.listeners[0],
respond=self.listeners[0]
)
self.cli = CliRunner()
self.host = self.listeners[0].remote.split("->")[1]
def mimic_output(self, command, result):
return "%s: %s> %s\n" % (self.host, command, result)
def test_engineer(self):
server = Server(link=self.server_link)
# Test status command
args = [self.host, "status"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output("status", "ok"))
# Test multiply command
args = [self.host, "multiply", "5", "2"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output("multiply", "10"))
# Test info command (without --extra)
args = [self.host, "info"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output("info", "ok"))
# Test info command (with --extra)
args = [self.host, "info", "--extra"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
self.assertEqual(str(r.output), self.mimic_output("info", "status: ok, color: green"))
# Test help
args = [self.host, "multiply", "--help"]
r = self.cli.invoke(
engineer.engineer, args
)
self.assertEqual(r.exit_code, 0)
expected = "\n".join([
"Usage: engineer zmq://addr1/req?transport=inproc multiply [OPTIONS] B A",
"",
" take a number and multiply it with another number",
"",
"Options:",
" --debug / --no-debug Show debug information",
" --help Show this message and exit.",
""
])
self.assertEqual(r.output, expected)
|
class Base(object):
class EngineerTestCase(XbahnTestCase):
def setUp(self):
pass
def mimic_output(self, command, result):
pass
def test_engineer(self):
pass
| 5 | 0 | 24 | 4 | 18 | 2 | 1 | 0.09 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 76 | 16 | 55 | 12 | 50 | 5 | 32 | 12 | 27 | 1 | 1 | 0 | 3 |
544 |
20c/xbahn
|
20c_xbahn/tests/test_connection_link.py
|
test_connection_link.TestLinkZMQ
|
class TestLinkZMQ(Base.LinkTestCase):
def setUp(self):
self.setUpConnections(
[("REP",0),("REP",1)],
[("REQ",0),("REQ",1)]
)
|
class TestLinkZMQ(Base.LinkTestCase):
def setUp(self):
pass
| 2 | 0 | 5 | 0 | 5 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 81 | 7 | 1 | 6 | 2 | 4 | 0 | 3 | 2 | 1 | 1 | 4 | 0 | 1 |
545 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.UnawareServerWidget
|
class UnawareServerWidget(ServerWidget):
pass
|
class UnawareServerWidget(ServerWidget):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
546 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.ServerWidget
|
class ServerWidget(api.Widget):
value = None
@api.expose
def hello(self):
return "world"
@api.expose
def server_route(self):
return self.comm.path
@api.expose
def set_value(self, v):
self.value = v
@api.expose
def get_value(self):
return self.value
|
class ServerWidget(api.Widget):
@api.expose
def hello(self):
pass
@api.expose
def server_route(self):
pass
@api.expose
def set_value(self, v):
pass
@api.expose
def get_value(self):
pass
| 9 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 4 | 0 | 4 | 13 | 19 | 5 | 14 | 10 | 5 | 0 | 10 | 6 | 5 | 1 | 3 | 0 | 4 |
547 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.Server
|
class Server(api.WidgetAwareServer):
pass
|
class Server(api.WidgetAwareServer):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
548 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.ClientWidgetB
|
class ClientWidgetB(api.Widget):
pass
|
class ClientWidgetB(api.Widget):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
549 |
20c/xbahn
|
20c_xbahn/examples/api/widget/server.py
|
server.Server
|
class Server(xbahn.api.Server):
pass
|
class Server(xbahn.api.Server):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
550 |
20c/xbahn
|
20c_xbahn/examples/api/widget/server.py
|
server.Server
|
class Server(xbahn.api.Server):
pass
|
class Server(xbahn.api.Server):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
551 |
20c/xbahn
|
20c_xbahn/examples/api/widget/server.py
|
server.Server
|
class Server(xbahn.api.Server):
pass
|
class Server(xbahn.api.Server):
pass
| 1 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
552 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.ClientWidget
|
class ClientWidget(api.Widget):
number = 0
@api.expose
def ping(self):
return "pong"
@api.expose
def client_route(self):
return self.comm.path
@api.expose
def set_number(self, n):
self.number = n
|
class ClientWidget(api.Widget):
@api.expose
def ping(self):
pass
@api.expose
def client_route(self):
pass
@api.expose
def set_number(self, n):
pass
| 7 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 3 | 0 | 3 | 12 | 15 | 4 | 11 | 8 | 4 | 0 | 8 | 5 | 4 | 1 | 3 | 0 | 3 |
553 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.Base
|
class Base(object):
class TestAPIWidget(XbahnTestCase):
def setUp(self):
pass
def test_widget_registry(self):
self.assertEqual(Server.widget.widgets["test"], ServerWidget)
self.assertEqual(Client.widget.widgets["test"], ClientWidget)
self.assertEqual(Client.widget.widgets["test2"], ClientWidgetB)
self.assertEqual(ClientWidgetB.remote_name, "test")
def _test_unaware_comm(self, server, client):
"""
Test widget communicating with widget unware server.
"""
widget = ClientWidget(client, "test_widget")
self.assertEqual(widget.hello(), "world")
widget.set_value(1)
self.assertEqual(widget.get_value(), 1)
widget_b = ClientWidget(client, "test_widget")
self.assertEqual(widget_b.get_value(), 1)
def _test_comm(self, server, client):
# instantiate client side widget
widget = ClientWidget(client, "test_widget")
# widget aware server should have created an instance of it's own
self.assertEqual(isinstance(server.widgets["test"][widget.id], ServerWidget), True)
self.assertEqual(widget.path, "widgets.%s.%s" % (ClientWidget.name, widget.id))
self.assertEqual(widget.path, server.widgets["test"][widget.id].path)
# instnatiate another client side widget
widget_b = ClientWidgetB(client, "test_widget_b")
widget_b.hello()
# widget aware server should have created an instance of it's own (using remote_name
# to identify the widget class)
self.assertEqual(isinstance(server.widgets["test"][widget_b.id], ServerWidget), True)
# client widget calling server widget method
self.assertEqual(widget.hello(), "world")
# server widget calling client widget method
self.assertEqual(server.widgets["test"][widget.id].ping(), "pong")
# ping doesnt exist on the second client
with self.assertRaises(exceptions.APIError) as inst:
server.widgets["test"][widget_b.id].ping()
# another instance of widget b
widget_b2 = ClientWidgetB(client, "test_widget_b")
widget.set_value("A")
widget_b.set_value("B")
self.assertEqual(widget.get_value(), "A")
self.assertEqual(widget_b.get_value(), "B")
self.assertEqual(widget_b2.get_value(), "B")
def _test_widget_timeout(self, server, client):
widget = ClientWidget(client, "test_widget")
self.assertEqual(isinstance(server.widgets["test"][widget.id], ServerWidget), True)
time.sleep(1)
self.assertIn(widget.id, server.widgets["test"])
time.sleep(1.5)
self.assertNotIn(widget.id, server.widgets["test"])
widget.hello()
#server.clients[client.id].request_widget(widget.name, widget.id)
self.assertIn(widget.id, server.widgets["test"])
def _test_widget_routes(self, server_a, server_b, client_a, client_b):
widget_a = ClientWidget(client_a, "test_widget")
widget_b = ClientWidget(client_b, "test_widget")
self.assertEqual(widget_a.server_route(), "route_a")
self.assertEqual(widget_b.server_route(), "route_b")
server_a.widgets["test"][widget_a.id].set_number(10)
server_b.widgets["test"][widget_b.id].set_number(20)
self.assertEqual(widget_a.number, 10)
self.assertEqual(widget_b.number, 20)
def _test_widget_groups(self, server, client):
widget_a = ClientWidget(client, "widget_a", group="a")
widget_b = ClientWidget(client, "widget_b", group="a")
widget_c = ClientWidget(client, "widget_c")
group = client.widgets["test"].filter(group="a")
self.assertEqual(len(group), 2)
self.assertIn(widget_a.id, group)
self.assertIn(widget_b.id, group)
self.assertNotIn(widget_c.id, group)
group.set_value("testing")
self.assertEqual(server.widgets["test"][widget_a.id].value, "testing")
self.assertEqual(server.widgets["test"][widget_b.id].value, "testing")
self.assertEqual(server.widgets["test"][widget_c.id].value, None)
group = server.widgets["test"].filter(group="a")
self.assertEqual(len(group), 2)
self.assertIn(widget_a.id, group)
self.assertIn(widget_b.id, group)
self.assertNotIn(widget_c.id, group)
group.set_number(10)
self.assertEqual(widget_a.number, 10)
self.assertEqual(widget_b.number, 10)
self.assertEqual(widget_c.number, 0)
|
class Base(object):
class TestAPIWidget(XbahnTestCase):
def setUp(self):
pass
def test_widget_registry(self):
pass
def _test_unaware_comm(self, server, client):
'''
Test widget communicating with widget unware server.
'''
pass
def _test_comm(self, server, client):
pass
def _test_widget_timeout(self, server, client):
pass
def _test_widget_routes(self, server_a, server_b, client_a, client_b):
pass
def _test_widget_groups(self, server, client):
pass
| 9 | 1 | 16 | 4 | 10 | 2 | 1 | 0.18 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 130 | 43 | 74 | 22 | 65 | 13 | 74 | 21 | 65 | 1 | 1 | 1 | 7 |
554 |
20c/xbahn
|
20c_xbahn/tests/test_api_twoway_comm.py
|
test_api_twoway_comm.TestAPI2WayZMQ
|
class TestAPI2WayZMQ(Base.TestAPI2Way):
def setUp(self):
self.setUpConnections(
[("REP",0),("REP",1)],
[("REQ",0)]
)
super(TestAPI2WayZMQ, self).setUp()
|
class TestAPI2WayZMQ(Base.TestAPI2Way):
def setUp(self):
pass
| 2 | 0 | 6 | 0 | 6 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 79 | 8 | 1 | 7 | 2 | 5 | 0 | 4 | 2 | 2 | 1 | 4 | 0 | 1 |
555 |
20c/xbahn
|
20c_xbahn/tests/test_api_twoway_comm.py
|
test_api_twoway_comm.Server
|
class Server(api.ClientAwareServer):
@api.expose
def hello(self):
return "hello"
|
class Server(api.ClientAwareServer):
@api.expose
def hello(self):
pass
| 3 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 35 | 4 | 0 | 4 | 3 | 1 | 0 | 3 | 2 | 1 | 1 | 6 | 0 | 1 |
556 |
20c/xbahn
|
20c_xbahn/tests/test_api_twoway_comm.py
|
test_api_twoway_comm.Client
|
class Client(api.Client):
@api.expose
def test(self):
return "%s reporting" % self.id
|
class Client(api.Client):
@api.expose
def test(self):
pass
| 3 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 4 | 0 | 4 | 3 | 1 | 0 | 3 | 2 | 1 | 1 | 5 | 0 | 1 |
557 |
20c/xbahn
|
20c_xbahn/tests/test_api.py
|
test_api.TestAPIZMQ
|
class TestAPIZMQ(Base.APITestCase):
def setUp(self):
self.setUpConnections(
[("REP",0)],
[("REQ",0)]
)
super(TestAPIZMQ, self).setUp()
|
class TestAPIZMQ(Base.APITestCase):
def setUp(self):
pass
| 2 | 0 | 6 | 0 | 6 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 80 | 8 | 1 | 7 | 2 | 5 | 0 | 4 | 2 | 2 | 1 | 4 | 0 | 1 |
558 |
20c/xbahn
|
20c_xbahn/tests/test_api.py
|
test_api.Server
|
class Server(api.Server):
@api.expose
def action_a(self):
return "a"
@api.expose
def action_b(self, arg):
return "b:%s" % arg
@api.expose
def action_c(self, arg, extra=None):
return "c (%s) extra=%s" % (arg, extra)
@api.expose
def action_d(self):
return message.Message("d")
@api.expose
def action_error(self):
raise Exception("Abandon ship!")
@api.expose
def my_route(self):
return self.path
def action_forbidden(self):
return "not allowed"
|
class Server(api.Server):
@api.expose
def action_a(self):
pass
@api.expose
def action_b(self, arg):
pass
@api.expose
def action_c(self, arg, extra=None):
pass
@api.expose
def action_d(self):
pass
@api.expose
def action_error(self):
pass
@api.expose
def my_route(self):
pass
def action_forbidden(self):
pass
| 14 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 2 | 1 | 0 | 7 | 0 | 7 | 35 | 28 | 7 | 21 | 14 | 7 | 0 | 15 | 8 | 7 | 1 | 5 | 0 | 7 |
559 |
20c/xbahn
|
20c_xbahn/tests/test_api_widget.py
|
test_api_widget.Client
|
class Client(api.Client):
pass
|
class Client(api.Client):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
560 |
20c/xbahn
|
20c_xbahn/examples/engineer/server.py
|
server.Server
|
class Server(api.Server):
status = "ok"
def do(self, what):
return "did %s" % what
|
class Server(api.Server):
def do(self, what):
pass
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 28 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 5 | 0 | 0 |
561 |
20c/xbahn
|
20c_xbahn/examples/engineer/server.py
|
server.Server
|
class Server(api.Server):
status = "ok"
def do(self, what):
return "did %s" % what
|
class Server(api.Server):
def do(self, what):
pass
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 7 | 0 | 0 |
562 |
20c/xbahn
|
20c_xbahn/examples/engineer/server.py
|
server.Server
|
class Server(api.Server):
status = "ok"
def do(self, what):
return "did %s" % what
|
class Server(api.Server):
def do(self, what):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 29 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
563 |
20c/xbahn
|
20c_xbahn/xbahn/api.py
|
xbahn.api.Dispatcher
|
class Dispatcher(Base):
"""
API dispatcher
Will dispatch function calls from one communicator to
another
Attributes:
- comm (Comm): the comm instance that spawned this dispatcher
- name (str): name of the function targeted by this dispatcher
Events:
- api_error: triggers when self.comm.blocking = True and the api
returns with an error message.
Payload:
* message (Message)
* error_status (dict):
- retry (bool) : set to True in order to retry the call
"""
def __init__(self, comm, name, **kwargs):
"""
Arguments:
- comm (Comm): the comm instance that spawned this dispatcher
- name (str): name of the function to be dispatched
"""
self.path = kwargs.get("path","")
Base.__init__(self, **kwargs)
self.comm = comm
self.name = name
def __call__(self, *args, **kwargs):
message = self.comm.prepare_message(Message(self.name, *args, **kwargs))
path = xbahn.path.append("call", self.path)
if self.comm.blocking:
# comm is set to blocking, so we want to block until
# a response is received from the server
m = self.link.main.send_and_wait(path, message, timeout=self.comm.timeout)
if "error" in m.meta:
# an error occured, trigger api_error event, which may
# set retry to True, in which case try once more before
# finally failing
error_status = { "retry" : False }
self.trigger("api_error", error_status=error_status, message=m)
if error_status.get("retry") == True:
message = self.comm.prepare_message(Message(self.name, *args, **kwargs))
m = self.link.main.send_and_wait(path, message, timeout=self.comm.timeout)
if "error" in m.meta:
raise APIError(m.meta.get("error"))
return m.data
else:
# otherwise send and immediatly return
return self.link.main.send("call", message)
|
class Dispatcher(Base):
'''
API dispatcher
Will dispatch function calls from one communicator to
another
Attributes:
- comm (Comm): the comm instance that spawned this dispatcher
- name (str): name of the function targeted by this dispatcher
Events:
- api_error: triggers when self.comm.blocking = True and the api
returns with an error message.
Payload:
* message (Message)
* error_status (dict):
- retry (bool) : set to True in order to retry the call
'''
def __init__(self, comm, name, **kwargs):
'''
Arguments:
- comm (Comm): the comm instance that spawned this dispatcher
- name (str): name of the function to be dispatched
'''
pass
def __call__(self, *args, **kwargs):
pass
| 3 | 2 | 20 | 4 | 11 | 6 | 3 | 1.18 | 1 | 2 | 2 | 0 | 2 | 3 | 2 | 15 | 63 | 15 | 22 | 10 | 19 | 26 | 21 | 10 | 18 | 5 | 3 | 3 | 6 |
564 |
20c/xbahn
|
20c_xbahn/xbahn/api.py
|
xbahn.api.Base
|
class Base(LogMixin, EventMixin):
"""
API object base, both server and client extend this
Keyword arguments:
- link (connection.Link) - wire api object to this link
- path (str): xbahn path prefix
"""
path_default = "base"
def __init__(self, **kwargs):
EventMixin.__init__(self)
self.link = None
if "link" in kwargs:
self.wire(kwargs.get("link"))
def wire(self, link):
""" wire api to a link """
self.link = link
def close(self):
""" close api object and disconnect the link it's wired to """
if self.link:
self.link.close()
|
class Base(LogMixin, EventMixin):
'''
API object base, both server and client extend this
Keyword arguments:
- link (connection.Link) - wire api object to this link
- path (str): xbahn path prefix
'''
def __init__(self, **kwargs):
pass
def wire(self, link):
''' wire api to a link '''
pass
def close(self):
''' close api object and disconnect the link it's wired to '''
pass
| 4 | 3 | 4 | 0 | 3 | 1 | 2 | 0.67 | 2 | 0 | 0 | 2 | 3 | 1 | 3 | 13 | 27 | 7 | 12 | 6 | 8 | 8 | 12 | 6 | 8 | 2 | 2 | 1 | 5 |
565 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.SUB_Connection
|
class SUB_Connection(REP_Connection):
"""
ZMQ SUB connection handler, can only receive
"""
def finalize_connection(self):
if self.topic:
self.log_debug("Subscribing to '%s'" % self.topic)
self.socket.setsockopt_string(zmq.SUBSCRIBE, self.topic)
def send(self, message):
pass
def respond(self, to_message, message):
pass
|
class SUB_Connection(REP_Connection):
'''
ZMQ SUB connection handler, can only receive
'''
def finalize_connection(self):
pass
def send(self, message):
pass
def respond(self, to_message, message):
pass
| 4 | 1 | 3 | 0 | 3 | 0 | 1 | 0.33 | 1 | 0 | 0 | 1 | 3 | 0 | 3 | 77 | 16 | 4 | 9 | 4 | 5 | 3 | 9 | 4 | 5 | 2 | 5 | 1 | 4 |
566 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.Sender
|
class Sender(BaseSender):
pass
|
class Sender(BaseSender):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
567 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.ClientWidget
|
class ClientWidget(api.Widget):
pass
|
class ClientWidget(api.Widget):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
568 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.EngineerDecorator
|
class EngineerDecorator(object):
"""
Base class for engineer decorators
"""
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def __call__(self, fn):
if not hasattr(fn, "engineer"):
fn.engineer = {
"description" : "",
"arguments" : [],
"options" : []
}
return fn
|
class EngineerDecorator(object):
'''
Base class for engineer decorators
'''
def __init__(self, *args, **kwargs):
pass
def __call__(self, fn):
pass
| 3 | 1 | 6 | 0 | 6 | 0 | 2 | 0.25 | 1 | 0 | 0 | 3 | 2 | 2 | 2 | 2 | 18 | 3 | 12 | 5 | 9 | 3 | 8 | 5 | 5 | 2 | 1 | 1 | 3 |
569 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.ServerWidget
|
class ServerWidget(api.Widget):
"""
Base Engineer server-side widget
"""
@api.expose
def engineer_list_commands(self):
"""
Returns a list of all api end points (commands) exposed
to engineer
"""
rv = []
for k in dir(self):
attr = getattr(self,k)
if type(getattr(attr, "engineer", None)) == dict:
rv.append(k)
return rv
@api.expose
def engineer_info(self, action):
"""
Returns:
dict: engineer command information
- arguments (list<dict>): command arguments
- args (list): args to pass through to click.argument
- kwargs (dict): keyword arguments to pass through to click.argument
- options (list<dict>): command options
- args (list): args to pass through to click.option
- kwargs (dict): keyword options to pass through to click.option
"""
fn = getattr(self, action, None)
if not fn:
raise AttributeError("Engineer action not found: %s" % action)
if not hasattr(fn, "engineer"):
raise AttributeError("Engineer action not exposed: %s" % action)
return fn.engineer
|
class ServerWidget(api.Widget):
'''
Base Engineer server-side widget
'''
@api.expose
def engineer_list_commands(self):
'''
Returns a list of all api end points (commands) exposed
to engineer
'''
pass
@api.expose
def engineer_info(self, action):
'''
Returns:
dict: engineer command information
- arguments (list<dict>): command arguments
- args (list): args to pass through to click.argument
- kwargs (dict): keyword arguments to pass through to click.argument
- options (list<dict>): command options
- args (list): args to pass through to click.option
- kwargs (dict): keyword options to pass through to click.option
'''
pass
| 5 | 3 | 17 | 3 | 7 | 7 | 3 | 1 | 1 | 3 | 0 | 2 | 2 | 0 | 2 | 11 | 42 | 8 | 17 | 9 | 12 | 17 | 15 | 7 | 12 | 3 | 3 | 2 | 6 |
570 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.argument
|
class argument(EngineerDecorator):
"""
Decorator to describe an argument for an exposed
engineer api endpoint (mimics @click.argument)
"""
def __call__(self, fn):
fn = super(argument, self).__call__(fn)
fn.engineer["arguments"].append({"args":self.args,"kwargs":self.kwargs})
return fn
|
class argument(EngineerDecorator):
'''
Decorator to describe an argument for an exposed
engineer api endpoint (mimics @click.argument)
'''
def __call__(self, fn):
pass
| 2 | 1 | 4 | 0 | 4 | 0 | 1 | 0.8 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 3 | 11 | 2 | 5 | 2 | 3 | 4 | 5 | 2 | 3 | 1 | 2 | 0 | 1 |
571 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.doc
|
class doc(object):
"""
decorator that lets you change docstring of
a function.
needed to pass a dynamic docstring to
click decorated remote xbahn api functions
"""
def __init__(self, text):
self.text = text
def __call__(self, fn):
fn.__doc__ = self.text
return fn
|
class doc(object):
'''
decorator that lets you change docstring of
a function.
needed to pass a dynamic docstring to
click decorated remote xbahn api functions
'''
def __init__(self, text):
pass
def __call__(self, fn):
pass
| 3 | 1 | 3 | 0 | 3 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 16 | 4 | 6 | 4 | 3 | 6 | 6 | 4 | 3 | 1 | 1 | 0 | 2 |
572 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.Receiver
|
class Receiver(BaseReceiver):
pass
|
class Receiver(BaseReceiver):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
573 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.expose
|
class expose(EngineerDecorator):
"""
Decorator to expose a function to engineer
Calls api.expose automatically
"""
def __call__(self, fn):
fn = api.expose(super(expose, self).__call__(fn))
fn.engineer["description"] = fn.__doc__
return fn
|
class expose(EngineerDecorator):
'''
Decorator to expose a function to engineer
Calls api.expose automatically
'''
def __call__(self, fn):
pass
| 2 | 1 | 4 | 0 | 4 | 0 | 1 | 0.8 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 3 | 12 | 3 | 5 | 2 | 3 | 4 | 5 | 2 | 3 | 1 | 2 | 0 | 1 |
574 |
20c/xbahn
|
20c_xbahn/xbahn/exceptions.py
|
xbahn.exceptions.APIError
|
class APIError(IOError):
pass
|
class APIError(IOError):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 1 | 0 | 0 |
575 |
20c/xbahn
|
20c_xbahn/xbahn/exceptions.py
|
xbahn.exceptions.SchemeNotFound
|
class SchemeNotFound(KeyError):
def __init__(self, scheme):
super(KeyError, self).__init__("'%s' is not a known scheme" % scheme)
|
class SchemeNotFound(KeyError):
def __init__(self, scheme):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 14 | 3 | 0 | 3 | 2 | 1 | 0 | 3 | 2 | 1 | 1 | 5 | 0 | 1 |
576 |
20c/xbahn
|
20c_xbahn/xbahn/api.py
|
xbahn.api.AuthHandler
|
class AuthHandler(Handler):
"""
Very simple auth handler that sends and asks for a plain key
"""
def setup(self, key, **kwargs):
if len(key) < 8:
raise ValueError("Key should be at least 8 characters long")
self.key = key
def outgoing(self, message, comm):
comm.log_debug("AUTH (sending): %s... (truncated)" % self.key[:3])
message.meta.update(auth=self.key)
def incoming(self, message, comm):
comm.log_debug("AUTH (requiring): %s... (truncated)" % self.key[:3])
if message.meta.get("auth") != self.key:
raise APIError("Authentication failed.")
|
class AuthHandler(Handler):
'''
Very simple auth handler that sends and asks for a plain key
'''
def setup(self, key, **kwargs):
pass
def outgoing(self, message, comm):
pass
def incoming(self, message, comm):
pass
| 4 | 1 | 4 | 0 | 4 | 0 | 2 | 0.25 | 1 | 2 | 1 | 0 | 3 | 1 | 3 | 17 | 19 | 4 | 12 | 5 | 8 | 3 | 12 | 5 | 8 | 2 | 3 | 1 | 5 |
577 |
20c/xbahn
|
20c_xbahn/xbahn/exceptions.py
|
xbahn.exceptions.TimeoutError
|
class TimeoutError(IOError):
def __init__(self, action, timeout):
super(IOError, self).__init__("timeout of %.2f seconds exceeded for '%s'" % (timeout, action))
|
class TimeoutError(IOError):
def __init__(self, action, timeout):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 3 | 0 | 3 | 2 | 1 | 0 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
578 |
20c/xbahn
|
20c_xbahn/xbahn/message.py
|
xbahn.message.ErrorMessage
|
class ErrorMessage(Message):
def __init__(self, errmsg):
Message.__init__(self, None)
self.meta.update(error=errmsg)
|
class ErrorMessage(Message):
def __init__(self, errmsg):
pass
| 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 15 | 4 | 0 | 4 | 2 | 2 | 0 | 4 | 2 | 2 | 1 | 3 | 0 | 1 |
579 |
20c/xbahn
|
20c_xbahn/xbahn/message.py
|
xbahn.message.Message
|
class Message(EventMixin, object):
"""
Base Message class
data <mixed> - the main content of the message
Any additional argument or keyword argument will also stored in
the args and kwargs properties.
"""
def __init__(self, data, *args, **kwargs):
EventMixin.__init__(self)
self.meta = {}
self.data = data
self.args = args
self.kwargs = kwargs
self.meta.update(id=str(uuid.uuid4()))
self.responder = None
self.response_received = False
self.response_message = None
self.responded = False
def __repr__(self):
return "MSG %s: %s (-> %s)" % (self.id, self.path, self.response_id)
def __dict__(self):
return {
"meta" : self.meta,
"data" : self.data,
"args" : self.args,
"kwargs" : self.kwargs
}
@property
def path(self):
"""
Return the xbahn path of this message
"""
return self.meta.get("path", "")
@property
def id(self):
"""
Return the id of this message, automatically assigned on
creation
"""
return self.meta.get("id")
@property
def response_id(self):
"""
Return the response id of this message, this is only set
when the message is intended to be a response to an earlier
message
"""
return self.meta.get("response_id")
def export(self, contentType):
"""
Export message to specified contentType via munge
contentType <str> - eg. "json", "yaml"
"""
cls = munge.get_codec(contentType)
codec = cls()
return codec.dumps(self.__dict__())
def response(self, message=None, event_origin=None):
self.trigger("response", message, source=event_origin)
def attach_response(self, message=None, event_origin=None):
self.response_received = True
self.response_message = message
|
class Message(EventMixin, object):
'''
Base Message class
data <mixed> - the main content of the message
Any additional argument or keyword argument will also stored in
the args and kwargs properties.
'''
def __init__(self, data, *args, **kwargs):
pass
def __repr__(self):
pass
def __dict__(self):
pass
@property
def path(self):
'''
Return the xbahn path of this message
'''
pass
@property
def id(self):
'''
Return the id of this message, automatically assigned on
creation
'''
pass
@property
def response_id(self):
'''
Return the response id of this message, this is only set
when the message is intended to be a response to an earlier
message
'''
pass
def export(self, contentType):
'''
Export message to specified contentType via munge
contentType <str> - eg. "json", "yaml"
'''
pass
def response_id(self):
pass
def attach_response(self, message=None, event_origin=None):
pass
| 13 | 5 | 6 | 0 | 4 | 2 | 1 | 0.56 | 2 | 1 | 0 | 1 | 9 | 8 | 9 | 14 | 74 | 13 | 39 | 23 | 26 | 22 | 31 | 20 | 21 | 1 | 2 | 0 | 9 |
580 |
20c/xbahn
|
20c_xbahn/xbahn/mixins.py
|
xbahn.mixins.EventMixin
|
class EventMixin(object):
"""
Adds event triggering / listening functionality
"""
def __init__(self):
self.event_listeners = {}
def has_callbacks(self, name):
"""
Returns True if there are callbacks attached to the specified
event name.
Returns False if not
"""
r = self.event_listeners.get(name)
if not r:
return False
return len(r) > 0
def on(self, name, callback, once=False):
"""
Adds a callback to the event specified by name
once <bool> if True the callback will be removed once it's been
triggered
"""
if name not in self.event_listeners:
self.event_listeners[name] = []
self.event_listeners[name].append((callback, once))
def off(self, name, callback, once=False):
"""
Removes callback to the event specified by name
"""
if name not in self.event_listeners:
return
self.event_listeners[name].remove((callback, once))
def trigger(self, name, *args, **kwargs):
"""
Triggers the event specified by name and passes
self in keyword argument "event_origin"
All additional arguments and keyword arguments are passed
through as well
"""
mark_remove = []
for callback, once in self.event_listeners.get(name, []):
callback(event_origin=self, *args, **kwargs)
if once:
mark_remove.append( (callback, once) )
for callback, once in mark_remove:
self.off(name, callback, once=once)
|
class EventMixin(object):
'''
Adds event triggering / listening functionality
'''
def __init__(self):
pass
def has_callbacks(self, name):
'''
Returns True if there are callbacks attached to the specified
event name.
Returns False if not
'''
pass
def on(self, name, callback, once=False):
'''
Adds a callback to the event specified by name
once <bool> if True the callback will be removed once it's been
triggered
'''
pass
def off(self, name, callback, once=False):
'''
Removes callback to the event specified by name
'''
pass
def trigger(self, name, *args, **kwargs):
'''
Triggers the event specified by name and passes
self in keyword argument "event_origin"
All additional arguments and keyword arguments are passed
through as well
'''
pass
| 6 | 5 | 10 | 2 | 5 | 4 | 2 | 0.92 | 1 | 0 | 0 | 11 | 5 | 1 | 5 | 5 | 60 | 14 | 24 | 10 | 18 | 22 | 24 | 10 | 18 | 4 | 1 | 2 | 11 |
581 |
20c/xbahn
|
20c_xbahn/xbahn/engineer.py
|
xbahn.engineer.option
|
class option(EngineerDecorator):
"""
Decorator to describe an option for an exposed
engineer api endpoint (mimics @click.option)
"""
def __call__(self, fn):
fn = super(option, self).__call__(fn)
fn.engineer["options"].append({"args":self.args,"kwargs":self.kwargs})
return fn
|
class option(EngineerDecorator):
'''
Decorator to describe an option for an exposed
engineer api endpoint (mimics @click.option)
'''
def __call__(self, fn):
pass
| 2 | 1 | 4 | 0 | 4 | 0 | 1 | 0.8 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 3 | 11 | 2 | 5 | 2 | 3 | 4 | 5 | 2 | 3 | 1 | 2 | 0 | 1 |
582 |
20c/xbahn
|
20c_xbahn/xbahn/mixins.py
|
xbahn.mixins.LogMixin
|
class LogMixin(object):
@property
def log(self):
return logging.getLogger("xbahn")
@property
def log_component_name(self):
return "[%s]" % str(self)
def log_message(self, msg, level="debug"):
fn = getattr(self.log, level)
fn("%s%s" % (self.log_component_name, msg))
def log_debug(self, msg):
self.log_message(msg)
def log_error(self, msg):
self.log_message(msg, level="error")
|
class LogMixin(object):
@property
def log(self):
pass
@property
def log_component_name(self):
pass
def log_message(self, msg, level="debug"):
pass
def log_debug(self, msg):
pass
def log_error(self, msg):
pass
| 8 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 1 | 0 | 5 | 5 | 0 | 5 | 5 | 18 | 4 | 14 | 9 | 6 | 0 | 12 | 7 | 6 | 1 | 1 | 0 | 5 |
583 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.REQ_Connection
|
class REQ_Connection(Connection):
"""
REQ zmq connection handler
Can initiate send, then has to wait for response
before it can send again
Attributes:
- waiting (bool): if true, is currently waiting on response
from previous call to send()
"""
def __init__(self, **kwargs):
super(REQ_Connection, self).__init__(**kwargs)
self._waiting = False
connection_type = "client"
def send(self, data):
self._waiting = True
super(REQ_Connection, self).send(data)
self.receive()
self._waiting = False
if self.close_when_ready:
self.destroy()
|
class REQ_Connection(Connection):
'''
REQ zmq connection handler
Can initiate send, then has to wait for response
before it can send again
Attributes:
- waiting (bool): if true, is currently waiting on response
from previous call to send()
'''
def __init__(self, **kwargs):
pass
def send(self, data):
pass
| 3 | 1 | 5 | 0 | 5 | 0 | 2 | 0.67 | 1 | 1 | 0 | 0 | 2 | 1 | 2 | 72 | 27 | 7 | 12 | 5 | 9 | 8 | 12 | 5 | 9 | 2 | 4 | 1 | 3 |
584 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.PUSH_Connection
|
class PUSH_Connection(PUB_Connection):
connection_type = "server"
def send(self, data):
Connection.send(self, data)
|
class PUSH_Connection(PUB_Connection):
def send(self, data):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 72 | 6 | 2 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 5 | 0 | 1 |
585 |
20c/xbahn
|
20c_xbahn/xbahn/connection/__init__.py
|
xbahn.connection.Connection
|
class Connection(EventMixin, LogMixin, threading.Thread):
"""
Base connection class
Attributes:
- close_when_ready (bool): if True, connection will attempt
to close itself the next time it is idle.
- transport_content_type (str, default="json"): content type
for message date (munge codec)
Events:
- receive: triggered when connection receives a message
- data (str): raw data
- message (Message): xbahn message object
- event_origin (EventMixin): object that triggered
the event
- send: triggered when connection has sent a message
- message (Message): xbahn message object
"""
def __init__(self, transport_content_type="json"):
threading.Thread.__init__(self)
EventMixin.__init__(self)
self.close_when_ready = False
self.transport_content_type = transport_content_type
# munge codec instance from transport_content_type
self.codecClass = munge.get_codec(transport_content_type)
self.codec = self.codecClass()
@property
def connected(self):
"""
Should return True if connection is currently connected
to a host
"""
return False
@property
def bound(self):
"""
Should return True if connection is currently bound/listening
on an address
"""
return False
@property
def active(self):
"""
Returns True if either connected or bound are True
"""
return self.bound or self.connected
@property
def remote(self):
"""
Should return a string representation of the xbahn url
that can be used to connect to this listener
"""
return None
@property
def connection_type(self):
"""
Should return either CONNECTION_TYPE_SERVER or
CONNECTION_TYPE_CLIENT
"""
return 0
@property
def can_receive(self):
"""
Should return whether or not this connection can receive
data
"""
return True
@property
def can_respond(self):
"""
Should return whether or not this connection can respond
to incoming data
"""
return True
@property
def can_send(self):
"""
Should return whether or not this connection can initiate
requests
"""
return True
def make_data(self, message):
"""
make data string from message according to transport_content_type
Returns:
str: message data
"""
if not isinstance(message, Message):
return message
return message.export(self.transport_content_type)
def make_message(self, data):
"""
Create a Message instance from data, data will be loaded
via munge according to the codec specified in the
transport_content_type attribute
Returns:
Message: message object
"""
data = self.codec.loads(data)
msg = Message(
data.get("data"),
*data.get("args",[]),
**data.get("kwargs",{})
)
msg.meta.update(data.get("meta"))
self.trigger("make_message", data, msg)
return msg
def start(self):
self.run_level = 1
super(Connection, self).start()
def listen(self):
"""
Should bind the connection
"""
pass
def connect(self):
"""
Should establish connection to host
"""
pass
def send(self, message):
"""
Should send message
Arguments:
- message (Message or dict): message to send
"""
pass
def close(self):
"""
Close the connection at the next possible opportunity
"""
self.close_when_ready = True
def run(self):
return
def stop(self):
self.run_level = 0
def finalize_connection(self):
"""
Finalize your connection in here, called after connect()
and listen()
"""
pass
def receive(self, data):
"""
Create and return a message from data, also triggers the
**receive** event
Returns:
- Message: message object
"""
self.log_debug("Received: %s" % (data))
message = self.make_message(data)
self.trigger("receive", data=data, message=message)
return message
def wait_for_signal(self, *signals):
conn = self
def shutdown(signal, frame):
conn.close()
for s in signals:
signal.signal(s, shutdown)
while self.active:
time.sleep(0.1)
|
class Connection(EventMixin, LogMixin, threading.Thread):
'''
Base connection class
Attributes:
- close_when_ready (bool): if True, connection will attempt
to close itself the next time it is idle.
- transport_content_type (str, default="json"): content type
for message date (munge codec)
Events:
- receive: triggered when connection receives a message
- data (str): raw data
- message (Message): xbahn message object
- event_origin (EventMixin): object that triggered
the event
- send: triggered when connection has sent a message
- message (Message): xbahn message object
'''
def __init__(self, transport_content_type="json"):
pass
@property
def connected(self):
'''
Should return True if connection is currently connected
to a host
'''
pass
@property
def bound(self):
'''
Should return True if connection is currently bound/listening
on an address
'''
pass
@property
def active(self):
'''
Returns True if either connected or bound are True
'''
pass
@property
def remote(self):
'''
Should return a string representation of the xbahn url
that can be used to connect to this listener
'''
pass
@property
def connection_type(self):
'''
Should return either CONNECTION_TYPE_SERVER or
CONNECTION_TYPE_CLIENT
'''
pass
@property
def can_receive(self):
'''
Should return whether or not this connection can receive
data
'''
pass
@property
def can_respond(self):
'''
Should return whether or not this connection can respond
to incoming data
'''
pass
@property
def can_send(self):
'''
Should return whether or not this connection can initiate
requests
'''
pass
def make_data(self, message):
'''
make data string from message according to transport_content_type
Returns:
str: message data
'''
pass
def make_message(self, data):
'''
Create a Message instance from data, data will be loaded
via munge according to the codec specified in the
transport_content_type attribute
Returns:
Message: message object
'''
pass
def start(self):
pass
def listen(self):
'''
Should bind the connection
'''
pass
def connected(self):
'''
Should establish connection to host
'''
pass
def send(self, message):
'''
Should send message
Arguments:
- message (Message or dict): message to send
'''
pass
def close(self):
'''
Close the connection at the next possible opportunity
'''
pass
def run(self):
pass
def stop(self):
pass
def finalize_connection(self):
'''
Finalize your connection in here, called after connect()
and listen()
'''
pass
def receive(self, data):
'''
Create and return a message from data, also triggers the
**receive** event
Returns:
- Message: message object
'''
pass
def wait_for_signal(self, *signals):
pass
def shutdown(signal, frame):
pass
| 31 | 17 | 7 | 1 | 3 | 3 | 1 | 1.11 | 3 | 2 | 1 | 1 | 21 | 5 | 21 | 56 | 202 | 42 | 76 | 40 | 45 | 84 | 64 | 32 | 41 | 3 | 2 | 1 | 25 |
586 |
20c/xbahn
|
20c_xbahn/xbahn/connection/__init__.py
|
xbahn.connection.Receiver
|
class Receiver(EventMixin):
"""
Base Receiver class
"""
def __init__(self, connection):
super(Receiver, self).__init__()
self.connection = connection
self.connection.on("receive", self.receive)
def receive(self, data, event_origin=None, responder=None):
self.trigger("receive", data, responder=responder)
|
class Receiver(EventMixin):
'''
Base Receiver class
'''
def __init__(self, connection):
pass
def receive(self, data, event_origin=None, responder=None):
pass
| 3 | 1 | 3 | 0 | 3 | 0 | 1 | 0.43 | 1 | 1 | 0 | 3 | 2 | 1 | 2 | 7 | 13 | 3 | 7 | 4 | 4 | 3 | 7 | 4 | 4 | 1 | 2 | 0 | 2 |
587 |
20c/xbahn
|
20c_xbahn/xbahn/connection/__init__.py
|
xbahn.connection.Sender
|
class Sender(EventMixin):
"""
Base Sender class
"""
def __init__(self, connection):
super(Sender, self).__init__()
self.connection = connection
def send(self, data):
self.connection.send(data)
self.trigger("send", data)
|
class Sender(EventMixin):
'''
Base Sender class
'''
def __init__(self, connection):
pass
def send(self, data):
pass
| 3 | 1 | 3 | 0 | 3 | 0 | 1 | 0.43 | 1 | 1 | 0 | 3 | 2 | 1 | 2 | 7 | 13 | 3 | 7 | 4 | 4 | 3 | 7 | 4 | 4 | 1 | 2 | 0 | 2 |
588 |
20c/xbahn
|
20c_xbahn/xbahn/connection/link.py
|
xbahn.connection.link.Link
|
class Link(LogMixin, EventMixin):
"""
Manages receiving and sending to one or more connection
Attributes:
- name (str): the links name
- main (Wire): the main wire, is set automatically during the
first wire() call or by passing "main" as the name during wire()
"""
def __init__(self, name=None, **kwargs):
"""
Keyword Arguments:
- name (str): name for this link, if not provided a unique
default value will be used
- receive (Connection): if supplied a "main" wire will be
established using this connection as a receiver
- send (Connection): if supplied a "main" wire will be
established using this connection as a sender
- respond (Connection): if supplied a "main" wire will be
established using this connection as a responder
"""
EventMixin.__init__(self)
self.name = name or get_link_name()
self.main = None
if "receive" in kwargs or "send" in kwargs or "respond" in kwargs:
self.wire(
"main",
receive=kwargs.get("receive"),
send=kwargs.get("send"),
respond=kwargs.get("respond")
)
def __repr__(self):
return "LINK: %s" % self.name
def wire(self, name, receive=None, send=None, respond=None, **kwargs):
"""
Wires the link to a connection. Can be called multiple
times to set up wires to different connections
After creation wire will be accessible on the link via its name
as an attribute.
You can undo this action with the cut() method
Arguments:
- name (str): unique name for the wire
Keyword Arguments:
- receive (Connection): wire receiver to this connection
- respond (Connection): wire responder to this connection
- send (Connection): wire sender to this connection
- meta (dict): attach these meta variables to any message
sent from this wire
Returns:
- Wire: the created wire instance
"""
if hasattr(self, name) and name != "main":
raise AttributeError("cannot use '%s' as name for wire, attribute already exists")
if send:
self.log_debug("Wiring '%s'.send: %s" % (name, send))
if respond:
self.log_debug("Wiring '%s'.respond: %s" % (name, respond))
if receive:
self.log_debug("Wiring '%s'.receive: %s" % (name, receive))
wire = Wire(receive=receive, send=send, respond=respond)
wire.name = "%s.%s" % (self.name, name)
wire.meta = kwargs.get("meta",{})
wire.on("receive", self.on_receive)
setattr(self, name, wire)
if not self.main:
self.main = wire
return wire
def cut(self, name, disconnect=False):
"""
Cut a wire (undo a wire() call)
Arguments:
- name (str): name of the wire
Keyword Arguments:
- disconnect (bool): if True also disconnect all connections on the
specified wire
"""
wire = getattr(self, name, None)
if wire and isinstance(wire, Wire):
if name != "main":
delattr(self, name)
if disconnect:
wire.disconnect()
wire.off("receive", self.on_receive)
if self.main == wire:
self.main = None
self.set_main_wire()
def set_main_wire(self, wire=None):
"""
Sets the specified wire as the link's main wire
This is done automatically during the first wire() call
Keyword Arguments:
- wire (Wire): if None, use the first wire instance found
Returns:
- Wire: the new main wire instance
"""
if not wire:
for k in dir(self):
if isinstance(getattr(self, k), Wire):
wire = getattr(self, k)
break
elif not isinstance(wire, Wire):
raise ValueError("wire needs to be a Wire instance")
if not isinstance(wire, Wire):
wire = None
self.main = wire
return wire
def wires(self):
"""
Yields name (str), wire (Wire) for all wires on
this link
"""
for k in dir(self):
if isinstance(getattr(self, k), Wire):
yield k, getattr(self, k)
def disconnect(self):
"""
Cut all wires and disconnect all connections established on this link
"""
for name, wire in self.wires():
self.cut(name, disconnect=True)
def on_receive(self, message=None, event_origin=None):
# trigger events for message received
self.trigger("receive", message=message, wire=event_origin)
for p in xbahn.path.walk(message.path):
self.trigger("receive_%s" % p, message=message, wire=event_origin)
if message.response_id:
# trigger events for response received
self.trigger("response", message=message, wire=event_origin)
self.trigger("response_%s" % message.response_id, message=message, wire=event_origin)
|
class Link(LogMixin, EventMixin):
'''
Manages receiving and sending to one or more connection
Attributes:
- name (str): the links name
- main (Wire): the main wire, is set automatically during the
first wire() call or by passing "main" as the name during wire()
'''
def __init__(self, name=None, **kwargs):
'''
Keyword Arguments:
- name (str): name for this link, if not provided a unique
default value will be used
- receive (Connection): if supplied a "main" wire will be
established using this connection as a receiver
- send (Connection): if supplied a "main" wire will be
established using this connection as a sender
- respond (Connection): if supplied a "main" wire will be
established using this connection as a responder
'''
pass
def __repr__(self):
pass
def wire(self, name, receive=None, send=None, respond=None, **kwargs):
'''
Wires the link to a connection. Can be called multiple
times to set up wires to different connections
After creation wire will be accessible on the link via its name
as an attribute.
You can undo this action with the cut() method
Arguments:
- name (str): unique name for the wire
Keyword Arguments:
- receive (Connection): wire receiver to this connection
- respond (Connection): wire responder to this connection
- send (Connection): wire sender to this connection
- meta (dict): attach these meta variables to any message
sent from this wire
Returns:
- Wire: the created wire instance
'''
pass
def cut(self, name, disconnect=False):
'''
Cut a wire (undo a wire() call)
Arguments:
- name (str): name of the wire
Keyword Arguments:
- disconnect (bool): if True also disconnect all connections on the
specified wire
'''
pass
def set_main_wire(self, wire=None):
'''
Sets the specified wire as the link's main wire
This is done automatically during the first wire() call
Keyword Arguments:
- wire (Wire): if None, use the first wire instance found
Returns:
- Wire: the new main wire instance
'''
pass
def wires(self):
'''
Yields name (str), wire (Wire) for all wires on
this link
'''
pass
def disconnect(self):
'''
Cut all wires and disconnect all connections established on this link
'''
pass
def on_receive(self, message=None, event_origin=None):
pass
| 9 | 7 | 20 | 5 | 8 | 7 | 4 | 0.88 | 2 | 3 | 1 | 0 | 8 | 2 | 8 | 18 | 177 | 49 | 68 | 17 | 59 | 60 | 62 | 17 | 53 | 6 | 2 | 3 | 28 |
589 |
20c/xbahn
|
20c_xbahn/xbahn/connection/link.py
|
xbahn.connection.link.Wire
|
class Wire(LogMixin, EventMixin):
def __init__(self, receive=None, send=None, respond=None):
EventMixin.__init__(self)
self.connection_receive = receive
self.connection_respond = respond
self.connection_send = send
self.meta = {}
self.name = ""
if receive:
receive.on("receive", self.on_receive)
def __repr__(self):
return "WIRE-%s" % self.name
def disconnect(self):
"""
Close all connections that are set on this wire
"""
if self.connection_receive:
self.connection_receive.close()
if self.connection_respond:
self.connection_respond.close()
if self.connection_send:
self.connection_send.close()
def send(self, path, message):
if message.path:
message.meta.update(path=xbahn.path.append(message.path, path))
else:
message.meta.update(path=path)
if self.meta:
message.meta.update(**self.meta)
if message.has_callbacks("response"):
#message is expecting response
self.on("response_%s" % message.id, message.attach_response, once=True)
self.on("response_%s" % message.id, message.response, once=True)
self.connection_send.send(message)
def send_and_wait(self, path, message, timeout=0, responder=None):
"""
Send a message and block until a response is received. Return response message
"""
message.on("response", lambda x,event_origin,source:None, once=True)
if timeout > 0:
ts = time.time()
else:
ts = 0
sent = False
while not message.response_received:
if not sent:
self.send(path, message)
sent = True
if ts:
if time.time() - ts > timeout:
raise exceptions.TimeoutError("send_and_wait(%s)"%path, timeout)
return message.response_message
def respond(self, to_message, message, path=None):
if not path:
path = "xbahn.response.%s" % to_message.id
message.meta.update(response_id=to_message.id, path=path)
if self.meta:
message.meta.update(**self.meta)
self.connection_respond.respond(to_message, message)
def on_receive(self, message=None, data=None, event_origin=None):
# trigger events for message received
self.trigger("receive", message=message)
for p in xbahn.path.walk(message.path):
self.trigger("receive_%s" % p, message=message)
if message.response_id:
# trigger events for response received
self.trigger("response", message=message)
self.trigger("response_%s" % message.response_id, message=message)
|
class Wire(LogMixin, EventMixin):
def __init__(self, receive=None, send=None, respond=None):
pass
def __repr__(self):
pass
def disconnect(self):
'''
Close all connections that are set on this wire
'''
pass
def send(self, path, message):
pass
def send_and_wait(self, path, message, timeout=0, responder=None):
'''
Send a message and block until a response is received. Return response message
'''
pass
def respond(self, to_message, message, path=None):
pass
def on_receive(self, message=None, data=None, event_origin=None):
pass
| 8 | 2 | 12 | 2 | 8 | 1 | 3 | 0.15 | 2 | 0 | 0 | 0 | 7 | 5 | 7 | 17 | 92 | 24 | 59 | 16 | 51 | 9 | 57 | 16 | 49 | 6 | 2 | 3 | 23 |
590 |
20c/xbahn
|
20c_xbahn/xbahn/connection/memory.py
|
xbahn.connection.memory.Poller
|
class Poller(BasePoller):
def __init__(self, name):
super(Poller, self).__init__()
self.name = name
|
class Poller(BasePoller):
def __init__(self, name):
pass
| 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 4 | 0 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 1 | 0 | 1 |
591 |
20c/xbahn
|
20c_xbahn/xbahn/connection/memory.py
|
xbahn.connection.memory.Receiver
|
class Receiver(BaseReceiver):
can_send = True
def __init__(self, name):
super(Receiver, self).__init__()
receivers[name] = self
self.name = name
def send(self, data):
for sender in senders.get(self.name, []):
sender.receive(data, eventOrigin=self)
def close(self):
try:
del senders[self.name]
del receivers[self.name]
except KeyError:
pass
|
class Receiver(BaseReceiver):
def __init__(self, name):
pass
def send(self, data):
pass
def close(self):
pass
| 4 | 0 | 4 | 0 | 4 | 0 | 2 | 0 | 1 | 2 | 0 | 0 | 3 | 1 | 3 | 10 | 18 | 3 | 15 | 7 | 11 | 0 | 15 | 7 | 11 | 2 | 3 | 1 | 5 |
592 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.REP_Connection
|
class REP_Connection(Connection):
"""
REP zmq connection handler
Can only send in response to incoming messages
Attributes:
- waiting (bool): if True, is currently waiting for messages and
not ready to send
"""
def __init__(self, **kwargs):
super(REP_Connection, self).__init__(**kwargs)
self._waiting = True
def run(self):
self.log_debug("Poller starting!")
self.poller = zmq.Poller()
self.poller.register(self.socket, zmq.POLLIN)
while self.run_level==1:
if not self.active:
break
try:
socks = dict(self.poller.poll(timeout=250))
except zmq.ZMQError as inst:
if str(inst).find("operation on non-socket"):
if not self.socket.closed:
self.destroy()
self.stop()
return
else:
raise
if self.socket in socks and socks[self.socket] == zmq.POLLIN:
try:
self.receive()
except Exception as inst: #FIXME
self.log_debug("Poller error: %s" % str(inst))
pass
if self.close_when_ready:
self.destroy()
def receive(self):
message = super(REP_Connection, self).receive()
self._waiting = False
if not message.responded:
self.respond(message, Message(None))
self._waiting = True
return message
def respond(self, to_message, message):
self.send(message)
to_message.responded = True
|
class REP_Connection(Connection):
'''
REP zmq connection handler
Can only send in response to incoming messages
Attributes:
- waiting (bool): if True, is currently waiting for messages and
not ready to send
'''
def __init__(self, **kwargs):
pass
def run(self):
pass
def receive(self):
pass
def respond(self, to_message, message):
pass
| 5 | 1 | 10 | 1 | 10 | 0 | 3 | 0.21 | 1 | 5 | 1 | 1 | 4 | 3 | 4 | 74 | 56 | 10 | 39 | 11 | 34 | 8 | 38 | 9 | 33 | 9 | 4 | 4 | 13 |
593 |
20c/xbahn
|
20c_xbahn/xbahn/connection/memory.py
|
xbahn.connection.memory.Sender
|
class Sender(BaseSender):
can_receive = True
responder = True
def __init__(self, name):
super(Sender, self).__init__()
if name not in senders:
senders[name] = []
senders[name].append(self)
self.name = name
@property
def receiver(self):
return receivers.get(self.name)
def send(self, data):
self.receiver.receive(data, eventOrigin=self)
def respond(self, data):
self.receive(data, eventOrigin=self)
def close(self):
senders[self.name].remove(self)
|
class Sender(BaseSender):
def __init__(self, name):
pass
@property
def receiver(self):
pass
def send(self, data):
pass
def respond(self, data):
pass
def close(self):
pass
| 7 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 5 | 1 | 5 | 12 | 23 | 5 | 18 | 10 | 11 | 0 | 17 | 9 | 11 | 2 | 3 | 1 | 6 |
594 |
20c/xbahn
|
20c_xbahn/xbahn/connection/tcp.py
|
xbahn.connection.tcp.Handler
|
class Handler(EventMixin, asynchat.async_chat):
"""
This will be instantiated by the server when a connection
is made. Since this is a direct connection responses
will be sent through this object
"""
# direct connection, responses are handled through
# this, so we flag this as a responder
responder = True
def __init__(self, host, port, sock=None, temporary=False):
EventMixin.__init__(self)
asynchat.async_chat.__init__(self, sock, map=make_map(host, port))
self.set_terminator(TERMINATOR)
self.received_data = ""
self.temporary = temporary
self.sock = sock
self.dispatcher = None
self.time = 0
def is_active(self, t, delay, close=True):
if t - self.time > delay:
print("closing", self, "because inactive", delay)
if close:
self.close_when_done()
return False
return True
def collect_incoming_data(self, data):
"""
Collect incoming data into self.received_data
"""
self.received_data += data
def found_terminator(self):
"""
Terminator has been found, process data
"""
self.process_data()
def process_data(self):
"""
Process data
Triggers raw-data-received event
"""
self.trigger("process-data", self.received_data)
self.received_data = ""
if self.dispatcher:
self.time = self.dispatcher.time
def respond(self, data):
"""
Respond to the connection accepted in this object
"""
self.push("%s%s" % (data, TERMINATOR))
if self.temporary:
self.close_when_done()
|
class Handler(EventMixin, asynchat.async_chat):
'''
This will be instantiated by the server when a connection
is made. Since this is a direct connection responses
will be sent through this object
'''
def __init__(self, host, port, sock=None, temporary=False):
pass
def is_active(self, t, delay, close=True):
pass
def collect_incoming_data(self, data):
'''
Collect incoming data into self.received_data
'''
pass
def found_terminator(self):
'''
Terminator has been found, process data
'''
pass
def process_data(self):
'''
Process data
Triggers raw-data-received event
'''
pass
def respond(self, data):
'''
Respond to the connection accepted in this object
'''
pass
| 7 | 5 | 8 | 1 | 5 | 2 | 2 | 0.65 | 2 | 0 | 0 | 0 | 6 | 5 | 6 | 58 | 67 | 16 | 31 | 13 | 24 | 20 | 31 | 13 | 24 | 3 | 2 | 2 | 10 |
595 |
20c/xbahn
|
20c_xbahn/xbahn/connection/tcp.py
|
xbahn.connection.tcp.Poller
|
class Poller(BasePoller):
def __init__(self, host, port):
super(Poller, self).__init__()
self.host = host
self.port = port
def run(self):
asyncore.loop(map=make_map(self.host, self.port), timeout=0.5)
try:
del pollers[(self.host, self.port)]
except KeyError:
pass
|
class Poller(BasePoller):
def __init__(self, host, port):
pass
def run(self):
pass
| 3 | 0 | 5 | 0 | 5 | 0 | 2 | 0 | 1 | 2 | 0 | 0 | 2 | 2 | 2 | 2 | 12 | 1 | 11 | 5 | 8 | 0 | 11 | 5 | 8 | 2 | 1 | 1 | 3 |
596 |
20c/xbahn
|
20c_xbahn/xbahn/connection/tcp.py
|
xbahn.connection.tcp.Receiver
|
class Receiver(BaseReceiver, asyncore.dispatcher):
"""
Receiver, in the case of TCP this can be seen as a server instance
It is bound to the specified address and listening for incoming
connections and data
"""
can_send = True
def __init__(self, host, port):
BaseReceiver.__init__(self)
asyncore.dispatcher.__init__(self, map=make_map(host, port))
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.bind( (host, port) )
self.listen(1)
self.connections = []
self.host = host
self.port = port
def handle_accept(self):
conn, addr = self.accept()
handler = Handler(self.host, self.port, sock=conn)
handler.dispatcher = self
handler.on("process-data", self.receive)
self.connections.append(handler)
def readable(self):
self.time = time.time()
return True
def send(self, data):
for handler in self.connections:
handler.push("%s%s" % (data, TERMINATOR))
def close(self):
asyncore.dispatcher.close(self)
for conn in self.connections:
conn.close()
self.connections = []
def close_inactive(self, delay=60):
self.connections = [c for c in self.connections if c.is_active(self.time, delay)]
|
class Receiver(BaseReceiver, asyncore.dispatcher):
'''
Receiver, in the case of TCP this can be seen as a server instance
It is bound to the specified address and listening for incoming
connections and data
'''
def __init__(self, host, port):
pass
def handle_accept(self):
pass
def readable(self):
pass
def send(self, data):
pass
def close(self):
pass
def close_inactive(self, delay=60):
pass
| 7 | 1 | 5 | 0 | 5 | 0 | 1 | 0.16 | 2 | 1 | 1 | 0 | 6 | 4 | 6 | 43 | 44 | 8 | 31 | 16 | 24 | 5 | 31 | 16 | 24 | 2 | 3 | 1 | 8 |
597 |
20c/xbahn
|
20c_xbahn/xbahn/connection/tcp.py
|
xbahn.connection.tcp.Sender
|
class Sender(BaseSender):
# direct connection, meaning sender can receive responses
# directly, so we flag it that it can_receive data
can_receive = True
def __init__(self, host, port):
BaseSender.__init__(self)
self.handler = Handler(host, port)
self.handler.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.handler.connect( (host, port) )
if self.can_receive:
self.handler.on("process-data", self.receive)
def send(self, data):
self.handler.push("%s%s" % (data, TERMINATOR))
def close(self):
self.handler.close()
|
class Sender(BaseSender):
def __init__(self, host, port):
pass
def send(self, data):
pass
def close(self):
pass
| 4 | 0 | 4 | 0 | 4 | 0 | 1 | 0.15 | 1 | 1 | 1 | 0 | 3 | 1 | 3 | 10 | 20 | 5 | 13 | 6 | 9 | 2 | 13 | 6 | 9 | 2 | 3 | 1 | 4 |
598 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.Connection
|
class Connection(BaseConnection):
sender_types = [zmq.PUB, zmq.REQ, zmq.PUSH]
responder_types = [zmq.REP]
def __init__(self, **kwargs):
super(Connection, self).__init__()
for k,v in list(kwargs.items()):
if k in ["id","typ","typ_str","url","topic","transport"]:
setattr(self, k, v)
self.context = context()
self.socket = None
self._waiting = False
def __repr__(self):
return "CONN %s" % (self.id)
@property
def waiting(self):
return self._waiting
@property
def connected(self):
return self.socket and not self.socket.closed
@property
def bound(self):
return self.socket and not self.socket.closed
@property
def can_respond(self):
return self.typ in self.responder_types
@property
def can_send(self):
return self.typ in self.sender_types
@property
def remote(self):
if self.topic:
t = "/%s" % self.topic
else:
t = ""
if self.typ == zmq.PUB:
typ_str = "sub"
elif self.typ == zmq.SUB:
typ_str = "pub"
elif self.typ == zmq.PUSH:
typ_str = "pull"
elif self.typ == zmq.PULL:
typ_str = "push"
elif self.typ == zmq.REP:
typ_str = "req"
elif self.typ == zmq.REQ:
typ_str = "rep"
if self.bound:
conn_type = "connect"
else:
conn_type = "listen"
return "%s->zmq://%s/%s%s?transport=%s" % (
conn_type,
self.url.split("//")[1], typ_str, t, self.transport
)
def connect(self):
self.log_debug("Connecting ...")
if self.connected:
raise AssertionError("connection is already established")
self.socket = self.context.socket(self.typ)
self.socket.connect(self.url)
self.finalize_connection()
self.log_debug("Connected!")
self.start()
def listen(self):
self.log_debug("Binding listener ...")
if self.bound:
raise AssertionError("connection is already listening")
self.socket = self.context.socket(self.typ)
self.socket.bind(self.url)
self.finalize_connection()
self.log_debug("Bound!")
self.start()
def receive(self):
self.log_debug("Attempting to receive ...")
try:
data = self.socket.recv_string()
except zmq.ZMQError as inst:
if str(inst).find("operation on non-socket") > -1:
self.destroy()
return Message(None)
raise
if self.topic:
data = data.lstrip("%s "%self.topic)
return super(Connection, self).receive(data)
def send(self, message):
data = self.make_data(message)
if self.topic:
data = "%s %s" % (self.topic, data)
self.log_debug("Attempting to send ...")
self.socket.send_string(data)
self.trigger("send", data)
self.log_debug("Sent: %s" % (data))
def close(self):
if not self.connected and not self.bound:
return
if not self.waiting:
self.destroy()
else:
self.close_when_ready = True
def destroy(self):
self.log_debug("Destroying connection")
if not self.socket.closed:
self.socket.close()
self.stop()
try:
del connections[self.id]
except KeyError as inst:
pass
|
class Connection(BaseConnection):
def __init__(self, **kwargs):
pass
def __repr__(self):
pass
@property
def waiting(self):
pass
@property
def connected(self):
pass
@property
def bound(self):
pass
@property
def can_respond(self):
pass
@property
def can_send(self):
pass
@property
def remote(self):
pass
def connected(self):
pass
def listen(self):
pass
def receive(self):
pass
def send(self, message):
pass
def close(self):
pass
def destroy(self):
pass
| 21 | 0 | 8 | 1 | 7 | 0 | 2 | 0 | 1 | 6 | 1 | 3 | 14 | 5 | 14 | 70 | 140 | 32 | 108 | 36 | 87 | 0 | 91 | 27 | 76 | 9 | 3 | 2 | 34 |
599 |
20c/xbahn
|
20c_xbahn/xbahn/connection/zmq.py
|
xbahn.connection.zmq.PUB_Connection
|
class PUB_Connection(Connection):
def close(self):
self.destroy()
|
class PUB_Connection(Connection):
def close(self):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 71 | 4 | 1 | 3 | 2 | 1 | 0 | 3 | 2 | 1 | 1 | 4 | 0 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.