wowool-common 3.0.2.dev19__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wowool-common might be problematic. Click here for more details.
- wowool/analysis.py +289 -0
- wowool/analysis_parser.py +102 -0
- wowool/annotation/__init__.py +4 -0
- wowool/annotation/annotation.py +156 -0
- wowool/annotation/concept.py +473 -0
- wowool/annotation/paragraph.py +166 -0
- wowool/annotation/sentence.py +262 -0
- wowool/annotation/token.py +266 -0
- wowool/apps/info.py +97 -0
- wowool/common/pipeline/__init__.py +1 -0
- wowool/common/pipeline/objects.py +45 -0
- wowool/common/utilities.py +13 -0
- wowool/config.py +67 -0
- wowool/diagnostic.py +250 -0
- wowool/document/__init__.py +2 -0
- wowool/document/apps/chunks.py +22 -0
- wowool/document/apps/themes.py +11 -0
- wowool/document/apps/topics.py +11 -0
- wowool/document/document.py +399 -0
- wowool/document/factory.py +176 -0
- wowool/error.py +2 -0
- wowool/io/console/__init__.py +1 -0
- wowool/io/console/argument_parser.py +29 -0
- wowool/io/console/console.py +102 -0
- wowool/io/provider/__init__.py +4 -0
- wowool/io/provider/docx.py +26 -0
- wowool/io/provider/factory.py +173 -0
- wowool/io/provider/file.py +85 -0
- wowool/io/provider/html.py +42 -0
- wowool/io/provider/html_v2.py +420 -0
- wowool/io/provider/input_provider.py +38 -0
- wowool/io/provider/pdf.py +320 -0
- wowool/io/provider/pdf_no_layout.py +48 -0
- wowool/io/provider/rtf.py +14 -0
- wowool/io/provider/str.py +17 -0
- wowool/string/__init__.py +153 -0
- wowool/tool/woc/create.py +42 -0
- wowool/utility/__init__.py +16 -0
- wowool/utility/apps/decorators.py +66 -0
- wowool/utility/apps/yml_include.py +30 -0
- wowool/utility/csv/__init__.py +26 -0
- wowool/utility/default_arguments.py +44 -0
- wowool/utility/diagnostics.py +24 -0
- wowool/utility/iterators/__init__.py +59 -0
- wowool/utility/method_registry.py +20 -0
- wowool/utility/numbers.py +42 -0
- wowool/utility/path/__init__.py +1 -0
- wowool/utility/path/path.py +11 -0
- wowool/utility/text/cleanup.py +82 -0
- wowool/visitor.py +48 -0
- wowool/wow.py +424 -0
- wowool_common-3.0.2.dev19.dist-info/METADATA +10 -0
- wowool_common-3.0.2.dev19.dist-info/RECORD +55 -0
- wowool_common-3.0.2.dev19.dist-info/WHEEL +5 -0
- wowool_common-3.0.2.dev19.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
def _has_module(name) -> bool:
|
|
2
|
+
try:
|
|
3
|
+
import importlib.util
|
|
4
|
+
|
|
5
|
+
module_spec = importlib.util.find_spec(name)
|
|
6
|
+
return True if module_spec else False
|
|
7
|
+
except ModuleNotFoundError:
|
|
8
|
+
return False
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AppConsole:
|
|
12
|
+
def __init__(self, console):
|
|
13
|
+
self.console_ = console
|
|
14
|
+
|
|
15
|
+
def log(self, obj, **kwargs):
|
|
16
|
+
self.console_.log(obj, **kwargs)
|
|
17
|
+
|
|
18
|
+
def print(self, obj, **kwargs):
|
|
19
|
+
self.console_.print(obj, **kwargs)
|
|
20
|
+
|
|
21
|
+
def print_json(self, obj, **kwargs):
|
|
22
|
+
self.console_.print_json(obj, **kwargs)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_markers = {
|
|
26
|
+
"default": "default",
|
|
27
|
+
"error": "red bold",
|
|
28
|
+
"literal": "green bold",
|
|
29
|
+
"stem": "green",
|
|
30
|
+
"uri": "blue bold",
|
|
31
|
+
"warning": "yellow bold",
|
|
32
|
+
"info": "blue bold",
|
|
33
|
+
"note": "bold",
|
|
34
|
+
"prog": "bold",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RichConsole:
|
|
39
|
+
def __init__(self, console, console_stderr):
|
|
40
|
+
self.console_ = console
|
|
41
|
+
self.console_stderr_ = console_stderr
|
|
42
|
+
|
|
43
|
+
def log(self, obj, **kwargs):
|
|
44
|
+
self.console_.log(obj, **kwargs)
|
|
45
|
+
|
|
46
|
+
def print(self, obj, **kwargs):
|
|
47
|
+
if isinstance(obj, str):
|
|
48
|
+
for marker, color in _markers.items():
|
|
49
|
+
obj = obj.replace(f"<{marker}>", f"[{color}]").replace(f"</{marker}>", f"[/{color}]")
|
|
50
|
+
|
|
51
|
+
if "file" in kwargs:
|
|
52
|
+
del kwargs["file"]
|
|
53
|
+
self.console_stderr_.print(obj, **kwargs)
|
|
54
|
+
else:
|
|
55
|
+
self.console_.print(obj, **kwargs)
|
|
56
|
+
|
|
57
|
+
def print_json(self, obj, **kwargs):
|
|
58
|
+
if not isinstance(obj, str):
|
|
59
|
+
import json
|
|
60
|
+
|
|
61
|
+
obj = json.dumps(obj, ensure_ascii=False)
|
|
62
|
+
self.console_.print_json(obj, ensure_ascii=False, **kwargs)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class PrintConsole:
|
|
66
|
+
def log(self, obj, **kwargs):
|
|
67
|
+
print(obj, **kwargs)
|
|
68
|
+
|
|
69
|
+
def print(self, obj, **kwargs):
|
|
70
|
+
if isinstance(obj, str):
|
|
71
|
+
for marker in _markers.keys():
|
|
72
|
+
obj = obj.replace(f"<{marker}>", "").replace(f"</{marker}>", "")
|
|
73
|
+
print(obj, **kwargs)
|
|
74
|
+
|
|
75
|
+
def print_json(self, obj, **kwargs):
|
|
76
|
+
import json
|
|
77
|
+
|
|
78
|
+
print(json.dumps(obj, indent=4, sort_keys=True, ensure_ascii=False), **kwargs)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
console = None
|
|
82
|
+
if _has_module("rich"):
|
|
83
|
+
try:
|
|
84
|
+
from rich.console import Console
|
|
85
|
+
from rich.theme import Theme
|
|
86
|
+
|
|
87
|
+
custom_theme = Theme(
|
|
88
|
+
{
|
|
89
|
+
"info": "dim cyan",
|
|
90
|
+
"warning": "magenta",
|
|
91
|
+
"danger": "bold red",
|
|
92
|
+
"h1": "bold blue",
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
console = AppConsole(RichConsole(Console(theme=custom_theme), Console(stderr=True, theme=custom_theme)))
|
|
96
|
+
|
|
97
|
+
except Exception as ex:
|
|
98
|
+
# TODO: change this into a warning
|
|
99
|
+
print("warning rich not installed: 'pip install rich' to have colorful messages.", ex)
|
|
100
|
+
pass
|
|
101
|
+
if not console:
|
|
102
|
+
console = AppConsole(PrintConsole())
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .input_provider import InputProvider
|
|
2
|
+
import docx
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_headding_markup_level(paragraph):
|
|
6
|
+
if paragraph.style.style_id and paragraph.style.style_id.startswith("Heading"):
|
|
7
|
+
print(paragraph.style.style_id)
|
|
8
|
+
return int(paragraph.style.style_id[7])
|
|
9
|
+
return None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DocxFileInputProvider(InputProvider):
|
|
13
|
+
def __init__(self, fid):
|
|
14
|
+
InputProvider.__init__(self, fid)
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def text(self, **kwargs):
|
|
18
|
+
doc = docx.Document(self.id)
|
|
19
|
+
text = ""
|
|
20
|
+
for paragraph in doc.paragraphs:
|
|
21
|
+
if markup_level := get_headding_markup_level(paragraph):
|
|
22
|
+
text += f"{'#' * markup_level} {paragraph.text}\n\n"
|
|
23
|
+
else:
|
|
24
|
+
text += paragraph.text + "\n\n"
|
|
25
|
+
|
|
26
|
+
return text
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Union, Optional
|
|
3
|
+
from wowool.io.provider import InputProvider
|
|
4
|
+
from wowool.utility.path import expand_path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def data2str(data: Union[str, bytes, None], encoding="utf-8") -> str:
|
|
8
|
+
if isinstance(data, str):
|
|
9
|
+
return data
|
|
10
|
+
elif isinstance(data, bytes):
|
|
11
|
+
return data.decode(encoding)
|
|
12
|
+
elif data is None:
|
|
13
|
+
return ""
|
|
14
|
+
else:
|
|
15
|
+
raise RuntimeError(f"Data only supports str|bytes but was passed {type(data)}")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _make_str(uid, data, encoding, **kwargs) -> InputProvider:
|
|
19
|
+
from wowool.io.provider.str import StrInputProvider
|
|
20
|
+
|
|
21
|
+
_txt = data2str(data, encoding)
|
|
22
|
+
return StrInputProvider(_txt, id=str(uid), **kwargs)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _make_text_file(uid, data, encoding, **kwargs) -> InputProvider:
|
|
26
|
+
try:
|
|
27
|
+
from wowool.io.provider.file import FileInputProvider
|
|
28
|
+
|
|
29
|
+
return FileInputProvider(uid, encoding=encoding, **kwargs)
|
|
30
|
+
except Exception as ex:
|
|
31
|
+
raise ex
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _make_html(uid, data, encoding, **kwargs) -> InputProvider:
|
|
35
|
+
try:
|
|
36
|
+
from wowool.io.provider.html_v2 import HTMLFileInputProvider
|
|
37
|
+
|
|
38
|
+
return HTMLFileInputProvider(uid, data, **kwargs)
|
|
39
|
+
except Exception as ex:
|
|
40
|
+
raise RuntimeError(f"install the BeautifulSoup(beautifulsoup4) library, 'pip install beautifulsoup4' {ex}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _make_docx(uid, data, **kwargs) -> InputProvider:
|
|
44
|
+
assert data is None, "The docx reader does not support data, only files"
|
|
45
|
+
try:
|
|
46
|
+
from wowool.io.provider.docx import DocxFileInputProvider
|
|
47
|
+
|
|
48
|
+
if "encoding" in kwargs:
|
|
49
|
+
del kwargs["encoding"]
|
|
50
|
+
return DocxFileInputProvider(uid, **kwargs)
|
|
51
|
+
except ModuleNotFoundError as ex:
|
|
52
|
+
raise ModuleNotFoundError(f"install the python-docx library, 'pip install python-docx' {ex}")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# def _make_pdf(uid, data, **kwargs) -> InputProvider:
|
|
56
|
+
# assert data is None, "The pdf reader does not support data, only files"
|
|
57
|
+
# try:
|
|
58
|
+
# # from wowool.io.provider.pdf import PdfFileInputProvider
|
|
59
|
+
|
|
60
|
+
# from wowool.io.provider.pdf_no_layout import PdfFileInputProvider
|
|
61
|
+
|
|
62
|
+
# return PdfFileInputProvider(uid)
|
|
63
|
+
|
|
64
|
+
# except ModuleNotFoundError as ex:
|
|
65
|
+
# raise ModuleNotFoundError(f"install the pdfminer.six library, 'pip install pdfminer.six' {ex}")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _make_pdf(uid, data, **kwargs) -> InputProvider:
|
|
69
|
+
assert data is None, "The pdf reader does not support data, only files"
|
|
70
|
+
try:
|
|
71
|
+
# from wowool.io.provider.pdf import PdfFileInputProvider
|
|
72
|
+
|
|
73
|
+
from wowool.io.pdf.provider import PDFFileInputProvider
|
|
74
|
+
|
|
75
|
+
return PDFFileInputProvider(uid)
|
|
76
|
+
|
|
77
|
+
except ModuleNotFoundError as ex:
|
|
78
|
+
raise ModuleNotFoundError(f"install the pdfminer.six library, 'pip install pdfminer.six' {ex}")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _invalid_type(uid, data, **kwargs):
|
|
82
|
+
raise RuntimeError("Invalid type")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
creators = {
|
|
86
|
+
"txt": _make_text_file,
|
|
87
|
+
"text": _make_str,
|
|
88
|
+
"str": _make_str,
|
|
89
|
+
"html": _make_html,
|
|
90
|
+
"pdf": _make_pdf,
|
|
91
|
+
"docx": _make_docx,
|
|
92
|
+
"_invalid_type": _invalid_type,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Factory:
|
|
97
|
+
@staticmethod
|
|
98
|
+
def create(
|
|
99
|
+
data: Optional[Union[str, bytes]] = None,
|
|
100
|
+
id: Optional[str] = None,
|
|
101
|
+
provider_type: str = "",
|
|
102
|
+
encoding="utf8",
|
|
103
|
+
**kwargs,
|
|
104
|
+
) -> InputProvider:
|
|
105
|
+
"""
|
|
106
|
+
Class to create a document from input data or from file.
|
|
107
|
+
|
|
108
|
+
.. code-block :: python
|
|
109
|
+
|
|
110
|
+
fn = "test.html"
|
|
111
|
+
doc = Factory.create(fn)
|
|
112
|
+
|
|
113
|
+
.. code-block :: python
|
|
114
|
+
|
|
115
|
+
fn = "test.html"
|
|
116
|
+
with open(fn) as fh:
|
|
117
|
+
html_data = fh.read()
|
|
118
|
+
doc = Factory.create(id = fn, data = html_data, provider_type = "html")
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
_data = data
|
|
122
|
+
if id is not None and _data is None:
|
|
123
|
+
try:
|
|
124
|
+
fn = Path(id)
|
|
125
|
+
except Exception:
|
|
126
|
+
fn = None
|
|
127
|
+
# this should be done in the provider itself
|
|
128
|
+
# if fn.exists():
|
|
129
|
+
# with open(fn, "rb") as fh:
|
|
130
|
+
# bdata = fh.read()
|
|
131
|
+
# _data = bdata.decode(encoding)
|
|
132
|
+
if fn is None:
|
|
133
|
+
provider_type = "text"
|
|
134
|
+
if not provider_type:
|
|
135
|
+
if fn.exists():
|
|
136
|
+
provider_type = fn.suffix[1:] if fn.suffix.startswith(".") else "txt"
|
|
137
|
+
else:
|
|
138
|
+
provider_type = "text"
|
|
139
|
+
else:
|
|
140
|
+
if data is not None:
|
|
141
|
+
if id is not None:
|
|
142
|
+
|
|
143
|
+
fn = Path(id)
|
|
144
|
+
if not provider_type:
|
|
145
|
+
if fn.exists():
|
|
146
|
+
provider_type = fn.suffix[1:] if fn.suffix.startswith(".") else "txt"
|
|
147
|
+
|
|
148
|
+
if not provider_type:
|
|
149
|
+
provider_type = "txt" if _data is None else "text"
|
|
150
|
+
return creators.get(provider_type, _invalid_type)(id, _data, encoding=encoding, **kwargs)
|
|
151
|
+
|
|
152
|
+
@staticmethod
|
|
153
|
+
def split_path_on_wildcards(path_description: Path, pattern: str = "*.txt"):
|
|
154
|
+
"""
|
|
155
|
+
Split a path description into a folder and a wildcard pattern.
|
|
156
|
+
"""
|
|
157
|
+
parts = path_description.parts
|
|
158
|
+
|
|
159
|
+
for index, part in enumerate(parts):
|
|
160
|
+
if "*" in part or "?" in part:
|
|
161
|
+
return Path(*parts[:index]), str(Path(*parts[index:]))
|
|
162
|
+
|
|
163
|
+
return path_description, pattern
|
|
164
|
+
|
|
165
|
+
@staticmethod
|
|
166
|
+
def glob(folder: Path | str, pattern: str = "*.txt", provider_type: str = "", **kwargs):
|
|
167
|
+
folder = expand_path(folder)
|
|
168
|
+
if Path(folder).is_file():
|
|
169
|
+
yield Factory.create(id=folder, provider_type=provider_type)
|
|
170
|
+
else:
|
|
171
|
+
folder, pattern_ = Factory.split_path_on_wildcards(folder, pattern=pattern)
|
|
172
|
+
for fn in folder.glob(pattern_):
|
|
173
|
+
yield Factory.create(id=fn, provider_type=provider_type, **kwargs)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from .input_provider import InputProvider
|
|
3
|
+
import errno
|
|
4
|
+
from logging import getLogger
|
|
5
|
+
|
|
6
|
+
global filemagic
|
|
7
|
+
filemagic = None
|
|
8
|
+
|
|
9
|
+
logger = getLogger("wowool.input_providers")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _strip_upper_ascii(s):
|
|
13
|
+
assert isinstance(s, bytes)
|
|
14
|
+
return bytes([i for i in s if 31 < i < 127 or i == 0xD or i == 0xA]).decode("utf8")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class FileInputProvider(InputProvider):
|
|
18
|
+
def __init__(self, fid, encoding="utf8", cleanup=None, **kwargs):
|
|
19
|
+
InputProvider.__init__(self, str(fid))
|
|
20
|
+
self.data = None
|
|
21
|
+
self.encoding = encoding
|
|
22
|
+
self.cleanup = cleanup
|
|
23
|
+
|
|
24
|
+
def cache_it(self, s):
|
|
25
|
+
if self.cache_fn and self.encoding != "utf8":
|
|
26
|
+
with open(self.cache_fn, "w") as fh:
|
|
27
|
+
fh.write(s)
|
|
28
|
+
return s
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def text(self, **kwargs):
|
|
32
|
+
fn = Path(self.id)
|
|
33
|
+
self.cache_fn = Path(fn.parent, ".utf8_cache_" + fn.name)
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
Path(self.cache_fn).exists()
|
|
37
|
+
except OSError as exc:
|
|
38
|
+
|
|
39
|
+
if exc.errno == errno.ENAMETOOLONG:
|
|
40
|
+
self.cache_fn = None
|
|
41
|
+
|
|
42
|
+
if self.cache_fn and self.cache_fn.exists():
|
|
43
|
+
with open(self.cache_fn, "r", encoding="utf8") as f:
|
|
44
|
+
logger.debug(f"Reading Cache file {self.id()}")
|
|
45
|
+
return f.read()
|
|
46
|
+
|
|
47
|
+
if "encoding" in kwargs:
|
|
48
|
+
self.encoding = kwargs["encoding"]
|
|
49
|
+
if self.encoding == "auto":
|
|
50
|
+
global filemagic
|
|
51
|
+
if filemagic is None:
|
|
52
|
+
try:
|
|
53
|
+
import magic
|
|
54
|
+
except:
|
|
55
|
+
raise RuntimeError("install the chardet library, 'on macos: brew install libmagic ; pip3 install filemagic'")
|
|
56
|
+
import magic
|
|
57
|
+
|
|
58
|
+
filemagic = magic.Magic(flags=magic.MAGIC_MIME_ENCODING)
|
|
59
|
+
self.encoding = filemagic.id_filename(self.id())
|
|
60
|
+
if self.encoding == "binary":
|
|
61
|
+
# print(f"self.cleanup.................{self.cleanup}")
|
|
62
|
+
if self.cleanup is None:
|
|
63
|
+
raise RuntimeError(f"Warning: Cannot process binary file: {self.id}")
|
|
64
|
+
try:
|
|
65
|
+
if self.encoding == "unknown-8bit":
|
|
66
|
+
print(f"Warning: unkown encoding using ascii : {self.id}")
|
|
67
|
+
with open(self.id(), "rb") as f:
|
|
68
|
+
r = f.read()
|
|
69
|
+
if self.cleanup:
|
|
70
|
+
return self.cache_it(self.cleanup(r))
|
|
71
|
+
else:
|
|
72
|
+
return self.cache_it(_strip_upper_ascii(r))
|
|
73
|
+
with open(self.id, "r", encoding=self.encoding) as f:
|
|
74
|
+
r = f.read()
|
|
75
|
+
if self.cleanup:
|
|
76
|
+
return self.cache_it(self.cleanup(r))
|
|
77
|
+
else:
|
|
78
|
+
return r
|
|
79
|
+
except Exception as ex:
|
|
80
|
+
if self.cleanup:
|
|
81
|
+
with open(self.id, "rb") as f:
|
|
82
|
+
r = f.read()
|
|
83
|
+
return self.cache_it(self.cleanup(r))
|
|
84
|
+
else:
|
|
85
|
+
raise ex
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from .input_provider import InputProvider
|
|
2
|
+
from bs4 import BeautifulSoup
|
|
3
|
+
from io import StringIO
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class HTMLFileInputProvider(InputProvider):
|
|
7
|
+
def __init__(self, fid, encoding="utf8"):
|
|
8
|
+
InputProvider.__init__(self, str(fid))
|
|
9
|
+
self.encoding = encoding
|
|
10
|
+
|
|
11
|
+
@property
|
|
12
|
+
def text(self, **kwargs):
|
|
13
|
+
with open(self.id(), "r", encoding=self.encoding) as f:
|
|
14
|
+
html_data = f.read()
|
|
15
|
+
soup = BeautifulSoup(html_data, "html.parser")
|
|
16
|
+
# kill all script and style elements
|
|
17
|
+
for script in soup(["script", "style"]):
|
|
18
|
+
script.extract() # rip it out
|
|
19
|
+
|
|
20
|
+
# get text
|
|
21
|
+
text = soup.get_text(" ")
|
|
22
|
+
|
|
23
|
+
# break into lines and remove leading and trailing space on each
|
|
24
|
+
lines = (line.strip() for line in text.splitlines())
|
|
25
|
+
|
|
26
|
+
# break multi-headlines into a line each
|
|
27
|
+
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
|
28
|
+
sio = StringIO()
|
|
29
|
+
prevcontent = ""
|
|
30
|
+
for mychunk in chunks:
|
|
31
|
+
if mychunk == "":
|
|
32
|
+
continue
|
|
33
|
+
if mychunk[-1:] != ".":
|
|
34
|
+
mychunk = mychunk + "."
|
|
35
|
+
filecontent = mychunk + "\n"
|
|
36
|
+
if filecontent != prevcontent:
|
|
37
|
+
sio.write(filecontent)
|
|
38
|
+
prevcontent = filecontent
|
|
39
|
+
|
|
40
|
+
text = sio.getvalue()
|
|
41
|
+
sio.close()
|
|
42
|
+
return text
|