caniusethat package

thing module

class caniusethat.thing.Thing(name: str, server_address: str)[source]

A representation of a remote object, or thing, that has methods that can be called.

name

The unique name of the remote object.

server_address

The address of the server that is hosting the remote object.

Example

>>> from caniusethat import thing
>>> my_thing = thing.Thing("remote_calculator", "tcp://127.0.0.1:6555")
>>> my_thing.add(2, 3)
5
available_methods() List[SharedMethodDescriptor][source]

Returns a list of the available methods of this object.

close_this_thing() None[source]

Closes the connection to the remote object and server, releasing any locks if any are still held.

shareable module

class caniusethat.shareable.Server(router_address: str)[source]

The Server takes care of sharing the objects on the network, handling the remote procedure calls from multiple users and their locks.

router_address

The address that the server will listen on.

Type

str

Example

>>> server = Server("tcp://127.0.0.1:6555")
>>> server.start()
>>> server.add_object("mobile_phone_interface", mobile_phone_interface)
add_object(name: str, obj: Any)[source]

Add an object to the server.

Parameters
  • name – A unique name that will be used to refer to the object.

  • obj – The object to add to the server.

get_object_list() List[str][source]

Returns a list of the names of the objects in the server.

Returns

A list of strings.

get_object_methods(name: str) List[SharedMethodDescriptor][source]

Returns a list of methods of the object with the given name.

Parameters

name – The name of the object to get the methods of.

Returns

A list of SharedMethodDescriptors.

caniusethat.shareable.acquire_lock(f: Callable) Callable[source]

A decorator that acquires the lock of the object before calling the method.

Example

>>> @acquire_lock
... @you_can_use_this
... def start_phone_call(self, phone_number: str) -> None:
...     self._make_phone_call(phone_number)
caniusethat.shareable.release_lock(f: Callable) Callable[source]

A decorator that releases the lock of the object after calling the method.

Example

>>> @release_lock
... @you_can_use_this
... def stop_phone_call(self) -> None:
...     self._hang_up()
caniusethat.shareable.you_can_use_this(f: Callable) Callable[source]

A decorator that marks a method as a shared method.

Example

>>> @you_can_use_this
... def get_name(self) -> str:
...     return self.name