file_content.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from collections.abc import Mapping
  2. from typing import TYPE_CHECKING, Any, TypeVar, Union
  3. from attrs import define as _attrs_define
  4. from attrs import field as _attrs_field
  5. from ..types import UNSET, Unset
  6. if TYPE_CHECKING:
  7. from ..models.file_content_patch import FileContentPatch
  8. T = TypeVar("T", bound="FileContent")
  9. @_attrs_define
  10. class FileContent:
  11. """
  12. Attributes:
  13. content (str):
  14. diff (Union[Unset, str]):
  15. patch (Union[Unset, FileContentPatch]):
  16. """
  17. content: str
  18. diff: Union[Unset, str] = UNSET
  19. patch: Union[Unset, "FileContentPatch"] = UNSET
  20. additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
  21. def to_dict(self) -> dict[str, Any]:
  22. content = self.content
  23. diff = self.diff
  24. patch: Union[Unset, dict[str, Any]] = UNSET
  25. if not isinstance(self.patch, Unset):
  26. patch = self.patch.to_dict()
  27. field_dict: dict[str, Any] = {}
  28. field_dict.update(self.additional_properties)
  29. field_dict.update(
  30. {
  31. "content": content,
  32. }
  33. )
  34. if diff is not UNSET:
  35. field_dict["diff"] = diff
  36. if patch is not UNSET:
  37. field_dict["patch"] = patch
  38. return field_dict
  39. @classmethod
  40. def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
  41. from ..models.file_content_patch import FileContentPatch
  42. d = dict(src_dict)
  43. content = d.pop("content")
  44. diff = d.pop("diff", UNSET)
  45. _patch = d.pop("patch", UNSET)
  46. patch: Union[Unset, FileContentPatch]
  47. if isinstance(_patch, Unset):
  48. patch = UNSET
  49. else:
  50. patch = FileContentPatch.from_dict(_patch)
  51. file_content = cls(
  52. content=content,
  53. diff=diff,
  54. patch=patch,
  55. )
  56. file_content.additional_properties = d
  57. return file_content
  58. @property
  59. def additional_keys(self) -> list[str]:
  60. return list(self.additional_properties.keys())
  61. def __getitem__(self, key: str) -> Any:
  62. return self.additional_properties[key]
  63. def __setitem__(self, key: str, value: Any) -> None:
  64. self.additional_properties[key] = value
  65. def __delitem__(self, key: str) -> None:
  66. del self.additional_properties[key]
  67. def __contains__(self, key: str) -> bool:
  68. return key in self.additional_properties