Skip to content

Commit

Permalink
fix: PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Apr 11, 2024
1 parent 263fd4c commit 79a045d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
5 changes: 0 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ Subscriber
.. autoclass:: zenoh.Subscriber
:members:

PullSubscriber
--------------
.. autoclass:: zenoh.PullSubscriber
:members:

Reliability
-----------
.. autoclass:: zenoh.Reliability
Expand Down
2 changes: 1 addition & 1 deletion examples/z_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import argparse
import json
import zenoh
from zenoh import config, Value
from zenoh import config

# --- Command line argument parsing --- --- --- --- --- ---
parser = argparse.ArgumentParser(
Expand Down
4 changes: 2 additions & 2 deletions zenoh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from .zenoh import init_logger, scout as _scout
from .keyexpr import IntoKeyExpr, IntoSelector, KeyExpr, Selector
from .config import Config
from .session import Session, Publisher, Subscriber, PullSubscriber, Info
from .session import Session, Publisher, Subscriber, Info
from .enums import CongestionControl, Encoding, Priority, QueryConsolidation, QueryTarget, Reliability, SampleKind
from .value import into_payload, from_payload, Hello, Sample, IntoSample, ZenohId, Timestamp, Reply
from .value import into_payload, from_payload, Hello, Sample, ZenohId, Timestamp, Reply
from .closures import Closure, IClosure, IntoClosure, Handler, IHandler, IntoHandler, ListCollector, Queue
from .queryable import Queryable, Query
from typing import Any
Expand Down
5 changes: 3 additions & 2 deletions zenoh/queryable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

from .zenoh import _Query, _Queryable
from .keyexpr import KeyExpr, Selector
from .value import Sample, Value, IntoValue, IntoSample
from .value import Sample, Value, IntoPayload, into_payload
from .enums import Encoding

class Queryable:
"""
Expand Down Expand Up @@ -80,4 +81,4 @@ def reply_err(self, payload: IntoPayload, encoding: Encoding = None):
You may send any amount of replies to a single query, including 0.
Sending error responses does not exclude sending other responses.
"""
super().reply_err(payload, encoding)
super().reply_err(into_payload(payload), encoding)
2 changes: 1 addition & 1 deletion zenoh/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .config import Config
from .closures import IntoHandler, Handler, Receiver
from .enums import *
from .value import into_payload, IntoValue, Value, Sample, Reply, ZenohId
from .value import into_payload, IntoPayload, Sample, Reply, ZenohId
from .queryable import Queryable, Query


Expand Down
38 changes: 37 additions & 1 deletion zenoh/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,43 @@ def from_payload(tp: Type[T], payload: bytes) -> T:
return json.loads(payload)
raise NotImplementedError()

class Value(_Value):
"""
A Value is a pair of a binary payload, and a mime-type-like encoding string.
When constructed with ``encoding==None``, the encoding will be selected depending on the payload's type.
"""
def __new__(cls, payload: IntoPayload, encoding: Encoding=None):
return Value.new(into_payload(payload), encoding)

@staticmethod
def new(payload: bytes, encoding: Encoding = None) -> 'Value':
return Value._upgrade_(_Value.new(payload, encoding))

@property
def payload(self) -> bytes:
return super().payload

@payload.setter
def payload(self, payload: bytes):
super().with_payload(payload)

@property
def encoding(self) -> Encoding:
return Encoding(super().encoding)

@encoding.setter
def encoding(self, encoding: Encoding):
super().with_encoding(encoding)

@staticmethod
def _upgrade_(inner: _Value) -> 'Value':
if inner is None:
return None
if isinstance(inner, Value):
return inner
return _Value.__new__(Value, inner)

class ZenohId(_ZenohId):
"""A Zenoh UUID"""
@staticmethod
Expand Down Expand Up @@ -115,7 +152,6 @@ def _upgrade_(inner: _QoS) -> 'QoS':
QoS.DEFAULT = QoS()


IntoSample = Union[_Sample, Tuple[IntoKeyExpr, IntoValue, SampleKind], Tuple[KeyExpr, IntoValue]]
class Sample(_Sample):
"""
A KeyExpr-Value pair, annotated with the kind (PUT or DELETE) of publication used to emit it and a timestamp.
Expand Down

0 comments on commit 79a045d

Please sign in to comment.