-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathcontent.py
More file actions
29 lines (22 loc) · 835 Bytes
/
content.py
File metadata and controls
29 lines (22 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ...types import T
class ContentPropertyMixin:
"""Provide helper functions for :class:`Document` to allow universal content property access. """
@property
def content_hash(self) -> int:
"""Get the document hash according to its content.
:return: the unique hash code to represent this Document
"""
return hash(self)
def convert_content_to_datauri(self: 'T') -> 'T':
"""Convert :attr:`.content` in :attr:`.uri` inplace with best effort
:return: itself after processed
"""
if self.text:
self.convert_text_to_datauri()
elif self.buffer:
self.convert_buffer_to_datauri()
elif self.content_type:
raise NotImplementedError
return self