Skip to content

Commit

Permalink
works now
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Jun 30, 2023
1 parent 8e2af2a commit e5472b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
37 changes: 20 additions & 17 deletions jord/qlive_utilities/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,27 @@ def __init__(self, addr: str = "tcp://localhost:5555"):
self.socket = self.context.socket(zmq.REQ)
self.addr = addr

def __enter__(self):
self.socket.connect(self.addr)
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.socket.close()

def send(self, *args) -> Any:
self.socket.send(*args)
return self.socket.recv()


class AutoQliveClient(QliveClient):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

for method in QliveRPCMethodEnum:
actual_callable = QliveRPCMethodMap[method]

if False:
partial_build_package = partial(build_package, method.value)
partial_build_package = partial(build_package, method)
if False and partial_satisfied(
partial_build_package
): # TODO: RESOLVE PARTIAL APPLICATION SATISFACTION.
Expand Down Expand Up @@ -79,35 +95,22 @@ def a(*args, **kwargs):
rpc_method = lambda *args: self.send(build_package(method, *args))
else:

def a(*args):
def wrapped(method, *args) -> Callable:
return self.send(build_package(method, *args))

rpc_method = a
rpc_method = partial(wrapped, method)

rpc_method.__doc__ = actual_callable.__doc__
print(method.value, rpc_method)
setattr(self, method.value, rpc_method)

def __enter__(self):
self.socket.connect(self.addr)
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.socket.close()

def send(self, *args) -> Any:
self.socket.send(*args)
return self.socket.recv()


if __name__ == "__main__":
# QliveClient().clear_all()
# QliveClient().remove_layers()
# print(QliveClient().clear_all.__doc__)
# print(QliveClient().__dict__)
def uahdsuh():
with QliveClient() as qlive:
print("calling", qlive.add_wkts)
with AutoQliveClient() as qlive:
qlive.add_wkts({"a": "POINT (-66.86 10.48)"})

# QliveClient().add_dataframe(None)
Expand Down
6 changes: 3 additions & 3 deletions jord/qlive_utilities/serialisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import pickle
from enum import Enum
from typing import Tuple, Sequence
from typing import Tuple, Sequence, Any

__all__ = ["build_package", "read_package"]

Expand All @@ -16,10 +16,10 @@ class SerialisationMethodEnum(Enum):


SERIALISATION_METHOD = SerialisationMethodEnum.pickle
VERBOSE = True
VERBOSE = False


def build_package(method: QliveRPCMethodEnum, *args) -> bytes:
def build_package(method: QliveRPCMethodEnum, *args: Any) -> bytes:
"""
:param method:
Expand Down

0 comments on commit e5472b5

Please sign in to comment.