zmos 0.0.1__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.
- zmos/__init__.py +6 -0
- zmos/__main__.py +6 -0
- zmos/analysis.py +364 -0
- zmos/casework.py +330 -0
- zmos/cli.py +168 -0
- zmos/commands/__init__.py +1 -0
- zmos/commands/ai.py +823 -0
- zmos/commands/casework.py +848 -0
- zmos/commands/common.py +153 -0
- zmos/commands/core.py +769 -0
- zmos/commands/craft.py +237 -0
- zmos/commands/crypto.py +173 -0
- zmos/commands/diction.py +56 -0
- zmos/commands/editor.py +57 -0
- zmos/commands/effects.py +110 -0
- zmos/commands/files.py +510 -0
- zmos/commands/mind.py +270 -0
- zmos/commands/mshesh.py +255 -0
- zmos/commands/net.py +844 -0
- zmos/commands/notes.py +178 -0
- zmos/commands/runtime.py +1021 -0
- zmos/commands/social.py +247 -0
- zmos/commands/synth.py +223 -0
- zmos/commands/transfer.py +200 -0
- zmos/commands/update.py +91 -0
- zmos/commands/views.py +505 -0
- zmos/commands/workspace.py +247 -0
- zmos/completion.py +283 -0
- zmos/constants.py +557 -0
- zmos/data/diction_code.txt +10000 -0
- zmos/data/english.txt +2048 -0
- zmos/deepseek.py +317 -0
- zmos/diction.py +133 -0
- zmos/editor.py +503 -0
- zmos/effects.py +297 -0
- zmos/exports.py +142 -0
- zmos/formats.py +990 -0
- zmos/generator.py +3933 -0
- zmos/graphics.py +1022 -0
- zmos/intelligence.py +1510 -0
- zmos/local_ai.py +1434 -0
- zmos/maintenance.py +142 -0
- zmos/media.py +1157 -0
- zmos/mshesh.py +325 -0
- zmos/parser.py +165 -0
- zmos/py.typed +0 -0
- zmos/registry.py +169 -0
- zmos/runtime.py +906 -0
- zmos/session.py +662 -0
- zmos/shell.py +360 -0
- zmos/splash.py +239 -0
- zmos/storage.py +231 -0
- zmos/synth.py +392 -0
- zmos/theme.py +559 -0
- zmos/tui.py +312 -0
- zmos/universe.py +949 -0
- zmos/updater.py +201 -0
- zmos/util.py +1579 -0
- zmos/webfetch.py +106 -0
- zmos/webimages.py +335 -0
- zmos/workspace.py +505 -0
- zmos-0.0.1.dist-info/METADATA +484 -0
- zmos-0.0.1.dist-info/RECORD +67 -0
- zmos-0.0.1.dist-info/WHEEL +5 -0
- zmos-0.0.1.dist-info/entry_points.txt +6 -0
- zmos-0.0.1.dist-info/licenses/LICENSE +21 -0
- zmos-0.0.1.dist-info/top_level.txt +1 -0
zmos/__init__.py
ADDED
zmos/__main__.py
ADDED
zmos/analysis.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"""Local text analysis and reversible transformations.
|
|
2
|
+
|
|
3
|
+
No model, no network: statistics, heuristics, regexes and ``difflib``. The
|
|
4
|
+
functions are shared by the ``review``, ``redact``, ``sanitize``, ``summarize``,
|
|
5
|
+
``scope`` and ``curate`` commands.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import difflib
|
|
11
|
+
import math
|
|
12
|
+
import re
|
|
13
|
+
from collections import Counter
|
|
14
|
+
from typing import Any, Iterable, Sequence
|
|
15
|
+
|
|
16
|
+
STOPWORDS = set(
|
|
17
|
+
"the a an and or but if of to in on at by for with from as is are was were "
|
|
18
|
+
"be been being it its this that these those i you he she we they his her "
|
|
19
|
+
"their our my your not no so than then there here what which who whom whose "
|
|
20
|
+
"when where why how all any both each few more most other some such only "
|
|
21
|
+
"own same too very can just should now into over under about after before "
|
|
22
|
+
"between during through without within up down out off again further once "
|
|
23
|
+
"every also may might must shall will would could have has had do does did "
|
|
24
|
+
"done one two three use used using make made new".split()
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
POSITIVE = set(
|
|
28
|
+
"good great clear calm quiet safe secure stable healthy improve improved "
|
|
29
|
+
"success successful reliable reliable ready open generous kind bright warm "
|
|
30
|
+
"strong fixed resolved contained verified valid clean".split()
|
|
31
|
+
)
|
|
32
|
+
NEGATIVE = set(
|
|
33
|
+
"bad broken fail failed failure error critical risk vulnerable exposed weak "
|
|
34
|
+
"unsafe unstable corrupt lost leak breach attack threat danger urgent "
|
|
35
|
+
"unknown missing denied blocked cold dark empty".split()
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
WORD_RE = re.compile(r"[A-Za-z][A-Za-z'_-]*")
|
|
39
|
+
SENTENCE_RE = re.compile(r"(?<=[.!?])\s+")
|
|
40
|
+
IPV4_RE = re.compile(r"\b(?:\d{1,3}\.){3}\d{1,3}\b")
|
|
41
|
+
IPV6_RE = re.compile(r"\b(?:[0-9a-fA-F]{1,4}:){2,7}[0-9a-fA-F]{1,4}\b")
|
|
42
|
+
MAC_RE = re.compile(r"\b(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}\b")
|
|
43
|
+
EMAIL_RE = re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b")
|
|
44
|
+
URL_RE = re.compile(r"https?://[^\s<>()\[\]{}]+", re.I)
|
|
45
|
+
DOMAIN_RE = re.compile(r"\b(?:[a-zA-Z0-9-]+\.)+(?:void|mesh|null|ghost|root|relay|hollow|lab|local|invalid|test)\b", re.I)
|
|
46
|
+
HASH_RE = re.compile(r"\b(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{40}|[0-9a-fA-F]{32})\b")
|
|
47
|
+
CVE_RE = re.compile(r"\bCVE-\d{4}-\d{4,7}\b", re.I)
|
|
48
|
+
PATH_RE = re.compile(r"(?<![\w.-])/(?:[\w.@+-]+/)*[\w.@+-]+")
|
|
49
|
+
TS_RE = re.compile(
|
|
50
|
+
r"\b(?:\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2})?(?:Z|[+-]\d{2}:?\d{2})?"
|
|
51
|
+
r"|\d{2}:\d{2}:\d{2})\b"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def words(text: str) -> list[str]:
|
|
56
|
+
return WORD_RE.findall(text)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def sentences(text: str) -> list[str]:
|
|
60
|
+
clean = " ".join(text.split())
|
|
61
|
+
return [s for s in SENTENCE_RE.split(clean) if s.strip()]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def syllable_count(word: str) -> int:
|
|
65
|
+
word = re.sub(r"[^A-Za-z]", "", word).lower()
|
|
66
|
+
if not word:
|
|
67
|
+
return 0
|
|
68
|
+
if len(word) <= 3:
|
|
69
|
+
return 1
|
|
70
|
+
groups = re.findall(r"[aeiouy]+", word)
|
|
71
|
+
count = len(groups)
|
|
72
|
+
if word.endswith("e") and not word.endswith(("le", "ye")) and count > 1:
|
|
73
|
+
count -= 1
|
|
74
|
+
if word.endswith("es") and not word.endswith(("ses", "zes", "ces")) and count > 1:
|
|
75
|
+
count -= 1
|
|
76
|
+
return max(1, count)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def text_stats(text: str) -> dict[str, int]:
|
|
80
|
+
lines = text.splitlines()
|
|
81
|
+
tokens = words(text)
|
|
82
|
+
return {
|
|
83
|
+
"chars": len(text),
|
|
84
|
+
"lines": len(lines),
|
|
85
|
+
"nonempty": sum(1 for line in lines if line.strip()),
|
|
86
|
+
"words": len(tokens),
|
|
87
|
+
"unique": len({w.lower() for w in tokens}),
|
|
88
|
+
"sentences": len(sentences(text)),
|
|
89
|
+
"syllables": sum(syllable_count(w) for w in tokens),
|
|
90
|
+
"max_line": max((len(line) for line in lines), default=0),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def readability(text: str) -> dict[str, Any]:
|
|
95
|
+
stats = text_stats(text)
|
|
96
|
+
words_n = max(1, stats["words"])
|
|
97
|
+
sentences_n = max(1, stats["sentences"])
|
|
98
|
+
syllables_n = max(1, stats["syllables"])
|
|
99
|
+
ease = 206.835 - 1.015 * (words_n / sentences_n) - 84.6 * (syllables_n / words_n)
|
|
100
|
+
ease = round(max(0.0, min(100.0, ease)), 1)
|
|
101
|
+
grade = round(max(0.0, 0.39 * (words_n / sentences_n) + 11.8 * (syllables_n / words_n) - 15.59), 1)
|
|
102
|
+
if ease >= 70:
|
|
103
|
+
label = "easy"
|
|
104
|
+
elif ease >= 50:
|
|
105
|
+
label = "plain"
|
|
106
|
+
elif ease >= 30:
|
|
107
|
+
label = "dense"
|
|
108
|
+
else:
|
|
109
|
+
label = "very dense"
|
|
110
|
+
return {
|
|
111
|
+
"ease": ease, "grade": grade, "label": label,
|
|
112
|
+
"words": words_n, "sentences": sentences_n, "syllables": syllables_n,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def tone(text: str) -> dict[str, Any]:
|
|
117
|
+
tokens = [w.lower() for w in words(text)]
|
|
118
|
+
positive = sum(1 for w in tokens if w in POSITIVE)
|
|
119
|
+
negative = sum(1 for w in tokens if w in NEGATIVE)
|
|
120
|
+
score = (positive - negative) / max(1, positive + negative)
|
|
121
|
+
if positive > negative * 1.4:
|
|
122
|
+
label = "positive"
|
|
123
|
+
elif negative > positive * 1.4:
|
|
124
|
+
label = "negative"
|
|
125
|
+
elif positive or negative:
|
|
126
|
+
label = "mixed"
|
|
127
|
+
else:
|
|
128
|
+
label = "neutral"
|
|
129
|
+
return {
|
|
130
|
+
"label": label, "score": round(score, 2),
|
|
131
|
+
"positive": positive, "negative": negative,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def keywords(text: str, limit: int = 14) -> list[tuple[str, int]]:
|
|
136
|
+
counts = Counter(
|
|
137
|
+
w.lower() for w in words(text)
|
|
138
|
+
if len(w) > 2 and w.lower() not in STOPWORDS
|
|
139
|
+
)
|
|
140
|
+
return counts.most_common(max(1, limit))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def entities(text: str) -> dict[str, list[str]]:
|
|
144
|
+
found = {
|
|
145
|
+
"ipv4": unique(IPV4_RE.findall(text)),
|
|
146
|
+
"ipv6": unique(IPV6_RE.findall(text)),
|
|
147
|
+
"mac": unique(MAC_RE.findall(text)),
|
|
148
|
+
"email": unique(EMAIL_RE.findall(text)),
|
|
149
|
+
"url": unique(URL_RE.findall(text)),
|
|
150
|
+
"domain": unique(DOMAIN_RE.findall(text)),
|
|
151
|
+
"hash": unique(h.lower() for h in HASH_RE.findall(text)),
|
|
152
|
+
"cve": unique(c.upper() for c in CVE_RE.findall(text)),
|
|
153
|
+
"path": unique(p.rstrip(".,;:)]}") for p in PATH_RE.findall(text) if p.count("/") >= 1),
|
|
154
|
+
}
|
|
155
|
+
return {key: values for key, values in found.items() if values}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def unique(values: Iterable[str]) -> list[str]:
|
|
159
|
+
seen: set[str] = set()
|
|
160
|
+
out: list[str] = []
|
|
161
|
+
for value in values:
|
|
162
|
+
key = str(value)
|
|
163
|
+
if key not in seen:
|
|
164
|
+
seen.add(key)
|
|
165
|
+
out.append(key)
|
|
166
|
+
return out
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def iocs(entities_map: dict[str, list[str]] | None = None, text: str = "") -> list[dict[str, str]]:
|
|
170
|
+
data = entities_map if entities_map is not None else entities(text)
|
|
171
|
+
kind_map = {
|
|
172
|
+
"ipv4": "ip", "ipv6": "ip", "mac": "mac", "email": "email",
|
|
173
|
+
"url": "url", "domain": "domain", "hash": "hash", "cve": "cve", "path": "path",
|
|
174
|
+
}
|
|
175
|
+
out: list[dict[str, str]] = []
|
|
176
|
+
for key, values in data.items():
|
|
177
|
+
for value in values:
|
|
178
|
+
out.append({"type": kind_map.get(key, key), "value": value})
|
|
179
|
+
return out
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def timeline(text: str, limit: int = 40) -> list[dict[str, str]]:
|
|
183
|
+
rows: list[dict[str, str]] = []
|
|
184
|
+
for line in text.splitlines():
|
|
185
|
+
match = TS_RE.search(line)
|
|
186
|
+
if match:
|
|
187
|
+
rows.append({"at": match.group(0), "line": line.strip()[:220]})
|
|
188
|
+
rows.sort(key=lambda row: row["at"])
|
|
189
|
+
return rows[: max(1, limit)]
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def quality_scores(text: str) -> dict[str, int]:
|
|
193
|
+
stats = text_stats(text)
|
|
194
|
+
read = readability(text)
|
|
195
|
+
ents = entities(text)
|
|
196
|
+
entity_count = sum(len(v) for v in ents.values())
|
|
197
|
+
action_words = sum(
|
|
198
|
+
1 for line in text.splitlines()
|
|
199
|
+
if re.match(r"\s*(?:[-*]|\d+\.)?\s*(?:check|verify|review|collect|scan|patch|rotate|isolate|contain|notify|document|test|measure|open|close|remove|add|run|inspect|compare)\b", line, re.I)
|
|
200
|
+
)
|
|
201
|
+
long_sentences = sum(1 for s in sentences(text) if len(s.split()) > 30)
|
|
202
|
+
clarity = 100 - min(45, max(0, int((read["grade"] - 9) * 4))) - min(20, long_sentences * 4)
|
|
203
|
+
specificity = min(100, 35 + entity_count * 7 + min(20, stats["unique"] // 8))
|
|
204
|
+
evidence = min(100, 30 + len(ents.get("path", [])) * 10 + len(ents.get("hash", [])) * 15 + len(ents.get("cve", [])) * 12 + len(ents.get("ipv4", [])) * 6)
|
|
205
|
+
actionability = min(100, 30 + action_words * 8)
|
|
206
|
+
brevity = 100 if stats["words"] <= 700 else max(25, 100 - (stats["words"] - 700) // 30)
|
|
207
|
+
return {
|
|
208
|
+
"clarity": max(0, clarity),
|
|
209
|
+
"specificity": max(0, specificity),
|
|
210
|
+
"evidence": max(0, evidence),
|
|
211
|
+
"actionability": max(0, actionability),
|
|
212
|
+
"brevity": max(0, brevity),
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def review(text: str) -> dict[str, Any]:
|
|
217
|
+
stats = text_stats(text)
|
|
218
|
+
read = readability(text)
|
|
219
|
+
mood = tone(text)
|
|
220
|
+
motifs = keywords(text, 10)
|
|
221
|
+
ents = entities(text)
|
|
222
|
+
rows = timeline(text, 20)
|
|
223
|
+
scores = quality_scores(text)
|
|
224
|
+
average = round(sum(scores.values()) / len(scores))
|
|
225
|
+
if average >= 80:
|
|
226
|
+
verdict = "Strong: specific, actionable and proportionate."
|
|
227
|
+
elif average >= 60:
|
|
228
|
+
verdict = "Usable: the evidence is there, but the next action could be sharper."
|
|
229
|
+
else:
|
|
230
|
+
verdict = "Thin: add concrete observations, names, paths and next steps."
|
|
231
|
+
cues: list[str] = []
|
|
232
|
+
if scores["evidence"] < 60:
|
|
233
|
+
cues.append("Name the evidence: paths, hosts, hashes, timestamps or commands.")
|
|
234
|
+
if scores["actionability"] < 60:
|
|
235
|
+
cues.append("Add a short next-actions list with verbs and owners.")
|
|
236
|
+
if scores["clarity"] < 60:
|
|
237
|
+
cues.append("Split long sentences and lead with the finding.")
|
|
238
|
+
if not rows and stats["lines"] > 8:
|
|
239
|
+
cues.append("Add timestamps so the report has a readable timeline.")
|
|
240
|
+
if stats["words"] > 900:
|
|
241
|
+
cues.append("Cut the report to the evidence and the decision it supports.")
|
|
242
|
+
if not cues:
|
|
243
|
+
cues.append("Read it once as the person who has to act on it.")
|
|
244
|
+
return {
|
|
245
|
+
"source": "(text)",
|
|
246
|
+
"stats": stats,
|
|
247
|
+
"readability": read,
|
|
248
|
+
"tone": mood,
|
|
249
|
+
"keywords": motifs,
|
|
250
|
+
"entities": ents,
|
|
251
|
+
"iocs": iocs(ents),
|
|
252
|
+
"timeline": rows,
|
|
253
|
+
"scores": scores,
|
|
254
|
+
"average": average,
|
|
255
|
+
"verdict": verdict,
|
|
256
|
+
"cues": cues,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def summarize(text: str, count: int = 5) -> str:
|
|
261
|
+
blocks = sentences(text)
|
|
262
|
+
if not blocks:
|
|
263
|
+
return ""
|
|
264
|
+
terms = {word for word, _ in keywords(text, 24)}
|
|
265
|
+
scored: list[tuple[float, int, str]] = []
|
|
266
|
+
for index, sentence in enumerate(blocks):
|
|
267
|
+
tokens = [w.lower() for w in words(sentence)]
|
|
268
|
+
if not tokens:
|
|
269
|
+
continue
|
|
270
|
+
score = sum(1 for token in tokens if token in terms) / math.sqrt(len(tokens))
|
|
271
|
+
score += 0.8 if index == 0 else 0.0
|
|
272
|
+
score += 0.25 if any(ch.isdigit() for ch in sentence) else 0.0
|
|
273
|
+
scored.append((score, index, sentence))
|
|
274
|
+
chosen = sorted(sorted(scored, key=lambda item: -item[0])[: max(1, count)], key=lambda item: item[1])
|
|
275
|
+
return " ".join(sentence for _, _, sentence in chosen)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
PLAIN_REPLACEMENTS = {
|
|
279
|
+
"utilise": "use", "utilize": "use", "commence": "start", "terminate": "end",
|
|
280
|
+
"endeavour": "try", "endeavor": "try", "sufficient": "enough",
|
|
281
|
+
"approximately": "about", "consequently": "so", "furthermore": "also",
|
|
282
|
+
"however": "but", "nevertheless": "still", "therefore": "so",
|
|
283
|
+
"additional": "more", "numerous": "many", "obtain": "get",
|
|
284
|
+
"demonstrate": "show", "facilitate": "help", "implement": "do",
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def plain_language(text: str) -> str:
|
|
289
|
+
out = text
|
|
290
|
+
for old, new in PLAIN_REPLACEMENTS.items():
|
|
291
|
+
out = re.sub(r"\b" + re.escape(old) + r"\b", new, out, flags=re.I)
|
|
292
|
+
out = re.sub(r";\s*", ". ", out)
|
|
293
|
+
out = re.sub(r"\s*—\s*", ", ", out)
|
|
294
|
+
out = re.sub(r"([.!?])\s+", r"\1\n\n", out)
|
|
295
|
+
return out
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
SANITIZE_RULES: list[tuple[re.Pattern[str], str]] = [
|
|
299
|
+
(EMAIL_RE, "[EMAIL]"),
|
|
300
|
+
(URL_RE, "[URL]"),
|
|
301
|
+
(MAC_RE, "[MAC]"),
|
|
302
|
+
(IPV4_RE, "[IP]"),
|
|
303
|
+
(IPV6_RE, "[IPV6]"),
|
|
304
|
+
(HASH_RE, "[HASH]"),
|
|
305
|
+
(CVE_RE, "[CVE]"),
|
|
306
|
+
(re.compile(r"\b(?:sk|pk|rk|api|tok|ghp|glpat)[-_][A-Za-z0-9_-]{12,}\b", re.I), "[TOKEN]"),
|
|
307
|
+
(re.compile(r"\b(?:password|passwd|secret|token|api[_-]?key)\s*[:=]\s*\S+", re.I), lambda m: re.split(r"[:=]", m.group(0), maxsplit=1)[0] + ": [SECRET]"),
|
|
308
|
+
]
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def sanitize(text: str) -> str:
|
|
312
|
+
out = text
|
|
313
|
+
for pattern, replacement in SANITIZE_RULES:
|
|
314
|
+
out = pattern.sub(replacement, out)
|
|
315
|
+
return out
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def redact(text: str, terms: Sequence[str]) -> str:
|
|
319
|
+
out = text
|
|
320
|
+
for term in sorted((t for t in terms if t), key=len, reverse=True):
|
|
321
|
+
out = re.sub(re.escape(term), "[REDACTED]", out, flags=re.I)
|
|
322
|
+
return out
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def redact_svg(text: str, terms: Sequence[str], title: str = "redacted") -> str:
|
|
326
|
+
lines = text.splitlines()[:36]
|
|
327
|
+
rows: list[str] = []
|
|
328
|
+
y = 54
|
|
329
|
+
for raw in lines:
|
|
330
|
+
if not raw.strip():
|
|
331
|
+
y += 12
|
|
332
|
+
continue
|
|
333
|
+
redacted = redact(raw, terms)
|
|
334
|
+
safe = xml_escape(redacted[:110])
|
|
335
|
+
rows.append(f'<text x="42" y="{y}" font-family="monospace" font-size="11" fill="#1a1a1a">{safe}</text>')
|
|
336
|
+
y += 16
|
|
337
|
+
return (
|
|
338
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="900" height="680" viewBox="0 0 900 680">'
|
|
339
|
+
'<rect width="900" height="680" fill="#f4efe4"/>'
|
|
340
|
+
f'<text x="42" y="28" font-family="monospace" font-size="13" fill="#7a2e22">REDACTED · {xml_escape(title)}</text>'
|
|
341
|
+
+ "".join(rows)
|
|
342
|
+
+ '<text x="42" y="660" font-family="monospace" font-size="9" fill="#6d655a">synthetic document · original retained in the workspace</text>'
|
|
343
|
+
"</svg>\n"
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def xml_escape(text: str) -> str:
|
|
348
|
+
return (
|
|
349
|
+
str(text).replace("&", "&").replace("<", "<")
|
|
350
|
+
.replace(">", ">").replace('"', """)
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def diff_text(before: str, after: str, *, from_name: str = "before", to_name: str = "after") -> str:
|
|
355
|
+
return "\n".join(
|
|
356
|
+
difflib.unified_diff(
|
|
357
|
+
before.splitlines(), after.splitlines(),
|
|
358
|
+
fromfile=from_name, tofile=to_name, lineterm="",
|
|
359
|
+
)
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def first_sentences(text: str, count: int = 3) -> str:
|
|
364
|
+
return " ".join(sentences(text)[: max(1, count)])
|