|
8 | 8 | import hecdss.record_type |
9 | 9 | from hecdss.array_container import ArrayContainer |
10 | 10 | from hecdss.location_info import LocationInfo |
| 11 | +from hecdss.text import Text |
11 | 12 | from hecdss.paired_data import PairedData |
12 | 13 | from hecdss.native import _Native |
13 | 14 | from hecdss.dateconverter import DateConverter |
@@ -179,8 +180,32 @@ def get(self, pathname: str, startdatetime=None, enddatetime=None, trim=False): |
179 | 180 | return self._get_array(pathname) |
180 | 181 | elif type == RecordType.LocationInfo: |
181 | 182 | return self._get_location_info(pathname) |
| 183 | + elif type == RecordType.Text: |
| 184 | + return self._get_text(pathname) |
182 | 185 | return None |
183 | 186 |
|
| 187 | + def _get_text(self, pathname: str): |
| 188 | + textLength = 1024 |
| 189 | + |
| 190 | + |
| 191 | + BUFFER_TOO_SMALL = -1 |
| 192 | + textArray = [] |
| 193 | + status = self._native.hec_dss_textRetrieve(pathname, textArray, textLength) |
| 194 | + while status == BUFFER_TOO_SMALL: |
| 195 | + textLength *= 2 |
| 196 | + status = self._native.hec_dss_textRetrieve(pathname, textArray, textLength) |
| 197 | + if textLength > 2*1048576: # 2 MB |
| 198 | + logger.error("Text record too large to read from '%s'", pathname) |
| 199 | + return None |
| 200 | + |
| 201 | + if status != 0: |
| 202 | + logger.error("Error reading text from '%s'", pathname) |
| 203 | + return None |
| 204 | + text = Text() |
| 205 | + text.id = pathname |
| 206 | + text.text = textArray[0] |
| 207 | + return text |
| 208 | + |
184 | 209 | def _get_array(self, pathname: str): |
185 | 210 | intValuesCount = [0] |
186 | 211 | floatValuesCount = [0] |
@@ -682,6 +707,10 @@ def put(self, container) -> int: |
682 | 707 | elif type(container) is LocationInfo: |
683 | 708 | status = self._native.hec_dss_locationStore(container,1) |
684 | 709 | self._catalog = None |
| 710 | + elif type(container) is Text: |
| 711 | + text = container |
| 712 | + status = self._native.hec_dss_textStore(text.id, text.text, len(text.text)) |
| 713 | + self._catalog = None |
685 | 714 | else: |
686 | 715 | raise NotImplementedError(f"unsupported record_type: {type(container)}. Expected types are: {RecordType.SUPPORTED_RECORD_TYPES.value}") |
687 | 716 |
|
@@ -812,6 +841,8 @@ def set_debug_level(self, level) -> int: |
812 | 841 | int: _description_ |
813 | 842 | """ |
814 | 843 | return self._native.hec_dss_set_debug_level(level) |
| 844 | + |
| 845 | + def |
815 | 846 |
|
816 | 847 |
|
817 | 848 | if __name__ == "__main__": |
|
0 commit comments