From bac63a62c4ae63dc857c9d2eed85b575b6ee66e9 Mon Sep 17 00:00:00 2001 From: Stewie Date: Fri, 26 Aug 2022 21:32:13 -0400 Subject: [PATCH] Creating text_to_bytes function --- ToolsTOPX.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/ToolsTOPX.py b/ToolsTOPX.py index 150e861..2522156 100644 --- a/ToolsTOPX.py +++ b/ToolsTOPX.py @@ -475,7 +475,63 @@ class ToolsTOPX(ToolsTales): return final_text, pos - + def text_to_bytes(self, text): + + splitLineBreak = text.split('\x0A') + nb = len(splitLineBreak) + bytesFinal = b'' + i=0 + + for line in splitLineBreak: + string_hex = re.split(self.HEX_TAG, line) + string_hex = [sh for sh in string_hex if sh] + #print(string_hex) + for s in string_hex: + if re.match(self.HEX_TAG, s): + bytesFinal += struct.pack("B", int(s[1:3], 16)) + else: + s_com = re.split(self.COMMON_TAG, s) + s_com = [sc for sc in s_com if sc] + + for c in s_com: + + if re.match(self.COMMON_TAG, c): + if ":" in c: + split = c.split(":") + + if split[0][1:] in self.itags.keys(): + bytesFinal += struct.pack("B", self.itags[split[0][1:]]) + bytesFinal += struct.pack("","") + ")" + bytesFinal += c.encode("cp932") + + if c in self.icolors: + bytesFinal += struct.pack("B", 0x5) + bytesFinal += struct.pack("=2 and i