Skip to content

Commit

Permalink
Remove invalid path detection for leading slash, updated examples, ad…
Browse files Browse the repository at this point in the history
…d srpc alias for rpc + .get()
  • Loading branch information
alex-sherman committed Feb 3, 2017
1 parent 69e2048 commit c8d1d9c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 56 deletions.
24 changes: 0 additions & 24 deletions examples/class_service.py

This file was deleted.

25 changes: 25 additions & 0 deletions examples/rpc_calling_styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python
from __future__ import print_function
import mrpc
import time

MRPC = mrpc.MRPC(broadcast = "192.168.1.255")

# RPC style
print(MRPC.rpc("LivingRoom.relay").get())
print(MRPC.srpc("LivingRoom.relay")) # Alias to call .get()

# Async RPC style
MRPC.rpc("LivingRoom.relay").when(lambda value: print(value))

# Proxy style
LivingRoom = MRPC.Proxy("LivingRoom")
print(LivingRoom.relay().get())

# Async proxy style
LivingRoom.relay().when(lambda value: print(value))

# Argument conversions
LED = MRPC.Proxy("LED")
LED.color(255, 255, 255) # Same as LED.color([255, 255, 255])
LED.color(r = 255, g = 255, b = 255) # Same as LED.color({r: 255, g: 255, b: 255})
10 changes: 0 additions & 10 deletions examples/simple_client.py

This file was deleted.

17 changes: 0 additions & 17 deletions examples/simple_service.py

This file was deleted.

7 changes: 4 additions & 3 deletions mrpc/MRPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def event(self, delay, callback):
self.events.append((time.time() + delay, callback))
self.events = sorted(self.events)

def rpc(self, path, value = None, sync = True, timeout = 3, resend_delay = 0.5):
def rpc(self, path, value = None, timeout = 3, resend_delay = 0.5):
msg = Message(
id = self.request_id(),
src = self.guid.hex,
Expand All @@ -89,10 +89,11 @@ def rpc(self, path, value = None, sync = True, timeout = 3, resend_delay = 0.5):
output.send()
self.path_cache[path].on_send()
self.requests[msg.id] = output
if sync:
return output.get()
return output

def srpc(self, path, value = None, timeout = 3, resend_delay = 0.5):
return self.rpc(path, value, timeout, resend_delay).get()

def close(self):
self.transport.close()
for service in self.services.values():
Expand Down
3 changes: 1 addition & 2 deletions mrpc/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def __init__(self, path):
self.is_wildcard = self.name == "*"
else:
self.name = self.path
# Ignore leading slashes for backwards compatibility
if self.name[0] == '/':
self.name = self.name[1:]
elif (not self.name == "*") and (not self.guid):
raise InvalidPath("Invalid path: " + path)
else:
raise InvalidPath("Invalid path: " + path)

Expand Down

0 comments on commit c8d1d9c

Please sign in to comment.