Browse Source

Use async I/O as well

main
Luke Murphy 5 years ago
parent
commit
e4574e7ecc
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 17
      etherpump/commands/pull.py

17
etherpump/commands/pull.py

@ -208,8 +208,9 @@ async def handle_pad(args, padid, data, info, session):
while True:
try:
if os.path.exists(metapath):
with open(metapath) as f:
meta.update(json.load(f))
async with await trio.open_file(metapath) as f:
contents = await f.read()
meta.update(json.loads(contents))
url = (
info['localapiurl'] + 'getRevisionsCount?' + urlencode(data)
)
@ -328,8 +329,8 @@ async def handle_pad(args, padid, data, info, session):
ver["path"] = p + raw_ext
ver["url"] = quote(ver["path"])
with open(ver["path"], "w") as f:
f.write(text)
async with await trio.open_file(ver["path"], "w") as f:
await f.write(text)
# once the content is settled, compute a hash
# and link it in the metadata!
@ -405,7 +406,7 @@ async def handle_pad(args, padid, data, info, session):
scripts=args.script,
links=links,
)
with open(ver["path"], "w") as f:
async with await trio.open_file(ver["path"], "w") as f:
print(
ET.tostring(doc, method="html", encoding="unicode"),
file=f,
@ -430,7 +431,7 @@ async def handle_pad(args, padid, data, info, session):
html5tidy(
doc, indent=True, title=padid, scripts=args.script, links=links,
)
with open(ver["path"], "w") as f:
async with await trio.open_file(ver["path"], "w") as f:
print(
ET.tostring(doc, method="html", encoding="unicode"), file=f,
)
@ -441,8 +442,8 @@ async def handle_pad(args, padid, data, info, session):
versions.append(ver)
ver["path"] = metapath
ver["url"] = quote(metapath)
with open(metapath, "w") as f:
json.dump(meta, f, indent=2)
async with await trio.open_file(metapath, "w") as f:
await f.write(json.dumps(meta))
async def handle_pad_chunk(args, padids, data, info, session):

Loading…
Cancel
Save