Skip to content

Commit d7145c2

Browse files
author
Sven Siegmund
committed
Preparing API rework
1 parent 9612031 commit d7145c2

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/rtfparse/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(self, config: config_loader.Config, file: io.BufferedReader) -> Non
183183
else:
184184
self.structure.append(Plain_Text(self.config, file))
185185
# name the group like its first Control Word
186-
# this way the renderer will be able to ignore entire groups
186+
# this way the renderer will be able to ignore entire groups based on their first control word
187187
try:
188188
if isinstance(self.structure[0], Control_Word):
189189
self.name = self.structure[0].control_name

src/rtfparse/minimal.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env python
22

33

4-
def tc(val, nbits):
5-
"""Compute the 2's complement of int value val. Credit: https://stackoverflow.com/a/37075643/9235421"""
6-
if val < 0:
7-
if (val + 1).bit_length() >= nbits:
8-
raise ValueError(f"Value {val} is out of range of {nbits}-bit value.")
9-
val = (1 << nbits) + val
10-
else:
11-
if val.bit_length() > nbits:
12-
raise ValueError(f"Value {val} is out of range of {nbits}-bit value.")
13-
# If sign bit is set.
14-
if (val & (1 << (nbits - 1))) != 0:
15-
# compute negative value.
16-
val = val - (1 << nbits)
17-
return val
4+
import pathlib
5+
from rtfparse.parsers import Rtf_Parser
6+
from rtfparse.renderers import encapsulated_html
7+
8+
9+
parser = Rtf_Parser()
10+
renderer = encapsulated_html.Encapsulated_HTML()
11+
source_file = pathlib.Path(r"D:\trace\email\test_mail_sw_release.rtf")
12+
target_file = pathlib.Path(r"D:\trace\email\extracted_with_rtfparse.html")
13+
14+
15+
with open(source_file, mode="rb") as rtf_file:
16+
parser.parse_file(rtf_file, default_encoding="cp1252")
17+
with open(target_file, mode="w", encoding="utf-8") as html_file:
18+
renderer.render(parser.parsed, target_file)

0 commit comments

Comments
 (0)