patch_part.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from collections.abc import Mapping
  2. from typing import Any, Literal, TypeVar, cast
  3. from attrs import define as _attrs_define
  4. from attrs import field as _attrs_field
  5. T = TypeVar("T", bound="PatchPart")
  6. @_attrs_define
  7. class PatchPart:
  8. """
  9. Attributes:
  10. id (str):
  11. session_id (str):
  12. message_id (str):
  13. type_ (Literal['patch']):
  14. hash_ (str):
  15. files (list[str]):
  16. """
  17. id: str
  18. session_id: str
  19. message_id: str
  20. type_: Literal["patch"]
  21. hash_: str
  22. files: list[str]
  23. additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
  24. def to_dict(self) -> dict[str, Any]:
  25. id = self.id
  26. session_id = self.session_id
  27. message_id = self.message_id
  28. type_ = self.type_
  29. hash_ = self.hash_
  30. files = self.files
  31. field_dict: dict[str, Any] = {}
  32. field_dict.update(self.additional_properties)
  33. field_dict.update(
  34. {
  35. "id": id,
  36. "sessionID": session_id,
  37. "messageID": message_id,
  38. "type": type_,
  39. "hash": hash_,
  40. "files": files,
  41. }
  42. )
  43. return field_dict
  44. @classmethod
  45. def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
  46. d = dict(src_dict)
  47. id = d.pop("id")
  48. session_id = d.pop("sessionID")
  49. message_id = d.pop("messageID")
  50. type_ = cast(Literal["patch"], d.pop("type"))
  51. if type_ != "patch":
  52. raise ValueError(f"type must match const 'patch', got '{type_}'")
  53. hash_ = d.pop("hash")
  54. files = cast(list[str], d.pop("files"))
  55. patch_part = cls(
  56. id=id,
  57. session_id=session_id,
  58. message_id=message_id,
  59. type_=type_,
  60. hash_=hash_,
  61. files=files,
  62. )
  63. patch_part.additional_properties = d
  64. return patch_part
  65. @property
  66. def additional_keys(self) -> list[str]:
  67. return list(self.additional_properties.keys())
  68. def __getitem__(self, key: str) -> Any:
  69. return self.additional_properties[key]
  70. def __setitem__(self, key: str, value: Any) -> None:
  71. self.additional_properties[key] = value
  72. def __delitem__(self, key: str) -> None:
  73. del self.additional_properties[key]
  74. def __contains__(self, key: str) -> bool:
  75. return key in self.additional_properties