class Property(DataClassJsonMixin): iid: int type: str description: str format: str access: List[str] value_list: List = field(default_factory=list, metadata=config(field_name="value-list")) value_range: List = field(default=None, metadata=config(field_name="value-range")) unit: str = None def __repr__(self): return f"piid: {self.iid} ({self.description}): ({self.format}, unit: {self.unit}) (acc: {self.access}, value-list: {self.value_list}, value-range: {self.value_range})" def __str__(self): return self.__repr__() def _generate_enum(self): s = f"class {self.pretty_name()}Enum(enum.Enum):\n" for value in self.value_list: s += f" {pretty_name(value['description'])} = {value['value']}\n" s += "\n" return s def pretty_name(self): return pretty_name(self.description) def _generate_value_and_range(self): s = "" if self.value_range: s += f" Range: {self.value_range}\n" if self.value_list: s += f" Values: {self.pretty_name()}Enum\n" return s def _generate_docstring(self): return ( f"{self.description} (siid: {self.siid}, piid: {self.iid}) - {self.type} " ) def _generate_getter(self): s = "" s += ( f"def read_{self.pretty_name()}() -> {python_type_for_type(self.format)}:\n" ) s += f' """{self._generate_docstring()}\n' s += self._generate_value_and_range() s += ' """\n\n' return s def _generate_setter(self): s = "" s += f"def write_{self.pretty_name()}(var: {python_type_for_type(self.format)}):\n" s += f' """{self._generate_docstring()}\n' s += self._generate_value_and_range() s += ' """\n' s += "\n" return s def as_code(self, siid): s = "" self.siid = siid if self.value_list: s += self._generate_enum() if "read" in self.access: s += self._generate_getter() if "write" in self.access: s += self._generate_setter() return s
class Reminder: item: ItemAndMetadata = field(metadata=config(field_name="item")) seqno: int = field(metadata=config(field_name="seqno")) remind_time: Time = field(metadata=config(field_name="remindTime"))
class ReminderSet: more_reminders_ready: bool = field(metadata=config( field_name="moreRemindersReady")) reminders: Optional[Optional[List[Reminder]]] = field( default=None, metadata=config(field_name="reminders"))
class Dismissal: msg_i_ds: Optional[Optional[List[MsgID]]] = field( default=None, metadata=config(field_name="msgIDs")) ranges: Optional[Optional[List[MsgRange]]] = field( default=None, metadata=config(field_name="ranges"))
class State: items: Optional[Optional[List[ItemAndMetadata]]] = field( default=None, metadata=config(field_name="items"))
class PsbtOut(DataClassJsonMixin): redeem_script: bytes = field( default=b"", metadata=config(encoder=lambda v: v.hex(), decoder=bytes.fromhex) ) witness_script: bytes = field( default=b"", metadata=config(encoder=lambda v: v.hex(), decoder=bytes.fromhex) ) bip32_derivs: Dict[bytes, bytes] = field( default_factory=dict, metadata=config(encoder=_encode_bip32_derivs, decoder=_decode_bip32_derivs), ) unknown: Dict[bytes, bytes] = field( default_factory=dict, metadata=config( encoder=_encode_dict_bytes_bytes, decoder=_decode_dict_bytes_bytes ), ) @classmethod def deserialize( cls: Type[_PsbtOut], output_map: Dict[bytes, bytes], assert_valid: bool = True ) -> _PsbtOut: out = cls() for k, v in output_map.items(): if k[0:1] == PSBT_OUT_REDEEM_SCRIPT: out.redeem_script = _deserialize_bytes(k, v, "redeem script") elif k[0:1] == PSBT_OUT_WITNESS_SCRIPT: out.witness_script = _deserialize_bytes(k, v, "witness script") elif k[0:1] == PSBT_OUT_BIP32_DERIVATION: out.bip32_derivs.update( _deserialize_bip32_derivs(k, v, "PsbtOut BIP32 pubkey") ) else: # unknown out.unknown[k] = v if assert_valid: out.assert_valid() return out def serialize(self, assert_valid: bool = True) -> bytes: if assert_valid: self.assert_valid() out = b"" if self.redeem_script: out += _serialize_bytes(PSBT_OUT_REDEEM_SCRIPT, self.redeem_script) if self.witness_script: out += _serialize_bytes(PSBT_OUT_WITNESS_SCRIPT, self.witness_script) if self.bip32_derivs: out += _serialize_dict_bytes_bytes( PSBT_OUT_BIP32_DERIVATION, self.bip32_derivs ) if self.unknown: out += _serialize_dict_bytes_bytes(b"", self.unknown) return out def assert_valid(self) -> None: "Assert logical self-consistency." _assert_valid_redeem_script(self.redeem_script) _assert_valid_witness_script(self.witness_script) _assert_valid_bip32_derivs(self.bip32_derivs) _assert_valid_unknown(self.unknown)
class Item: category: Category = field(metadata=config(field_name="category")) dtime: TimeOrOffset = field(metadata=config(field_name="dtime")) body: Body = field(metadata=config(field_name="body")) remind_times: Optional[Optional[List[TimeOrOffset]]] = field( default=None, metadata=config(field_name="remindTimes"))
class OutOfBandMessage(DataClassJsonMixin): uid: UID = field(metadata=config(field_name="uid")) system: System = field(metadata=config(field_name="system")) body: Body = field(metadata=config(field_name="body"))
class ConnectedDevice(DataClassJsonMixin): device_id: DeviceID = field(metadata=config(field_name="deviceID")) device_type: str = field(metadata=config(field_name="deviceType")) device_platform: str = field(metadata=config(field_name="devicePlatform")) user_agent: str = field(metadata=config(field_name="userAgent"))
class Metadata(DataClassJsonMixin): uid: UID = field(metadata=config(field_name="uid")) msg_id: MsgID = field(metadata=config(field_name="msgID")) ctime: Time = field(metadata=config(field_name="ctime")) device_id: DeviceID = field(metadata=config(field_name="deviceID")) in_band_msg_type: int = field(metadata=config(field_name="inBandMsgType"))
class ReminderID(DataClassJsonMixin): uid: UID = field(metadata=config(field_name="uid")) msg_id: MsgID = field(metadata=config(field_name="msgID")) seqno: int = field(metadata=config(field_name="seqno"))
class TimeOrOffset(DataClassJsonMixin): time: Time = field(metadata=config(field_name="time")) offset: DurationMsec = field(metadata=config(field_name="offset"))
class AuthResult(DataClassJsonMixin): uid: UID = field(metadata=config(field_name="uid")) username: str = field(metadata=config(field_name="username")) sid: SessionID = field(metadata=config(field_name="sid")) is_admin: bool = field(metadata=config(field_name="isAdmin"))
class SyncResult(DataClassJsonMixin): hash: str = field(metadata=config(field_name="hash")) msgs: Optional[Optional[List[InBandMessage]]] = field( default=None, metadata=config(field_name="msgs") )
class SelectorComponentOption(Base): id_: str = field(default=None, metadata=config(field_name='id')) name: str = None tags: Optional[Tuple[str, ...]] = None
class StateSyncMessage(DataClassJsonMixin): md: Metadata = field(metadata=config(field_name="md"))
class RelatedLink(Base): type_: str = field(default=None, metadata=config(field_name='type')) name: str = None link: str = None description: Optional[str] = None notification_properties: Optional[NotificationTokens] = None
class MsgRange(DataClassJsonMixin): end_time: TimeOrOffset = field(metadata=config(field_name="endTime")) category: Category = field(metadata=config(field_name="category")) skip_msg_i_ds: Optional[Optional[List[MsgID]]] = field( default=None, metadata=config(field_name="skipMsgIDs") )
class DataClassWithConfigHelper: id: float = field(metadata=dataclasses_json.config(encoder=str))
def get_field_dc_mm(mm_field: marshmallow.fields.Field, **kwargs) -> dataclasses.Field: """Pass.""" kwargs["metadata"] = dataclasses_json.config(mm_field=mm_field) return dataclasses.field(**kwargs)
class ConnectedUser: uid: UID = field(metadata=config(field_name="uid")) devices: Optional[Optional[List[ConnectedDevice]]] = field( default=None, metadata=config(field_name="devices"))
class PrimerMatch: match: str = field(metadata=config(field_name="match")) start: int = field(metadata=config(field_name="start")) end: int = field(metadata=config(field_name="end")) dist: int = field(metadata=config(field_name="dist"))
class ItemAndMetadata: md: Optional[Metadata] = field(default=None, metadata=config(field_name="md")) item: Optional[Item] = field(default=None, metadata=config(field_name="item"))
def isodatetime(**kwargs: Any) -> Field: # type: ignore """dataclass field rendering a datetime object as a string when parsing/formatting.""" return field(metadata=config(encoder=isoformat, decoder=isoparse, mm_field=fields.DateTime(format='iso')), **kwargs)
class StateUpdateMessage: md: Metadata = field(metadata=config(field_name="md")) creation: Optional[Item] = field(default=None, metadata=config(field_name="creation")) dismissal: Optional[Dismissal] = field( default=None, metadata=config(field_name="dismissal"))
class PolygonConfidenced(WithConfidence): content: Polygon = field(default=None, metadata=config(decoder=decode_polygon, encoder=encode_polygon))
class InBandMessage: state_update: Optional[StateUpdateMessage] = field( default=None, metadata=config(field_name="stateUpdate")) state_sync: Optional[StateSyncMessage] = field( default=None, metadata=config(field_name="stateSync"))
class WorkspaceTab(Base): id_: str = field(default=None, metadata=config(field_name='id')) name: str = None
class Message: oobm: Optional[OutOfBandMessage] = field( default=None, metadata=config(field_name="oobm")) ibm: Optional[InBandMessage] = field(default=None, metadata=config(field_name="ibm"))
class TravelAdvice: title: str = field(metadata=config(field_name='titel')) advice: List[Dict[str, str]] = field(metadata=config(field_name='reisadvies'))