8 """Helper context to write a pages file."""
10 def __init__(self, filename: str, *, transformations=[]):
11 self.full_filename = os.path.join(constants.pages_dir, filename)
12 self.xforms = [file_writer.remove_tricky_unicode]
13 self.xforms.extend(transformations)
17 def remove_tricky_unicode(x: str) -> str:
19 x = x.replace("\u2018", "'").replace("\u2019", "'")
20 x = x.replace("\u201c", '"').replace("\u201d", '"')
21 x = x.replace("\u2e3a", "-").replace("\u2014", "-")
26 def write(self, data):
27 for xform in self.xforms:
29 self.f.write(data.encode("utf-8"))
32 self.f = open(self.full_filename, "wb")
35 def __exit__(self, exc_type, exc_value, exc_traceback):
49 # with file_writer("test", transformations=[toupper]) as fw:
50 # fw.write(u"Another test!!")