44from ._property import _PropertyMixin
55
66if TYPE_CHECKING :
7- from ...types import DocumentContentType
7+ from ...types import DocumentContentType , ArrayType
8+ from ... import DocumentArray
89
910_all_mime_types = set (mimetypes .types_map .values ())
1011
@@ -22,16 +23,66 @@ def content(self) -> Optional['DocumentContentType']:
2223 if ct :
2324 return getattr (self , ct )
2425
26+ @_PropertyMixin .text .setter
27+ def text (self , value : str ):
28+ self ._clear_content ()
29+ self ._data .text = value
30+
31+ @_PropertyMixin .blob .setter
32+ def blob (self , value : bytes ):
33+ self ._clear_content ()
34+ self ._data .blob = value
35+
36+ @_PropertyMixin .tensor .setter
37+ def tensor (self , value : 'ArrayType' ):
38+ self ._clear_content ()
39+ self ._data .tensor = value
40+
2541 @content .setter
2642 def content (self , value : 'DocumentContentType' ):
27- if value is None :
28- self ._clear_content ()
29- elif isinstance (value , bytes ):
30- self .blob = value
43+ self ._clear_content ()
44+ if isinstance (value , bytes ):
45+ self ._data .blob = value
3146 elif isinstance (value , str ):
32- self .text = value
33- else :
34- self .tensor = value
47+ self ._data .text = value
48+ elif value is not None :
49+ self ._data .tensor = value
50+
51+ @_PropertyMixin .uri .setter
52+ def uri (self , value : str ):
53+ if value :
54+ mime_type = mimetypes .guess_type (value )[0 ]
55+
56+ if mime_type :
57+ self ._data .mime_type = mime_type
58+ self ._data .uri = value
59+
60+ @_PropertyMixin .mime_type .setter
61+ def mime_type (self , value : str ):
62+ if value and value not in _all_mime_types :
63+ # given but not recognizable, do best guess
64+ r = mimetypes .guess_type (f'*.{ value } ' )[0 ]
65+ value = r or value
66+
67+ self ._data .mime_type = value
68+
69+ @_PropertyMixin .chunks .setter
70+ def chunks (self , value : 'DocumentArray' ):
71+ from ...array .chunk import ChunkArray
72+
73+ if not isinstance (value , ChunkArray ):
74+ value = ChunkArray (value , reference_doc = self ._data ._reference_doc )
75+
76+ self ._data .chunks = value
77+
78+ @_PropertyMixin .matches .setter
79+ def matches (self , value : 'DocumentArray' ):
80+ from ...array .match import MatchArray
81+
82+ if not isinstance (value , MatchArray ):
83+ value = MatchArray (value , reference_doc = self ._data ._reference_doc )
84+
85+ self ._data .matches = value
3586
3687 @property
3788 def content_type (self ) -> Optional [str ]:
0 commit comments