Skip to content
Snippets Groups Projects
Commit b931680c authored by Andreas Schärtl's avatar Andreas Schärtl
Browse files

add fix-rdf-file.py

passed an rdf file w/ bad iris on stdin, it returns
a fixed version
parent 75c14a78
No related branches found
No related tags found
No related merge requests found
#! /usr/bin/env python3
from urllib import parse
import re
import sys
def fix_quoted(s: str) -> str:
payload = s.strip('"')
fixed = parse.quote(payload)
return '"%s"' % fixed
def print_fixed_line(line: str):
# https://stackoverflow.com/questions/249791
regex = r"(\"(?:[^\"]|\\.)*\")"
matches = re.findall(regex, line)
for match in matches:
fixed = fix_quoted(match)
line = line.replace(match, fixed)
print(line, end='')
def main():
for line in sys.stdin:
print_fixed_line(line)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit, BrokenPipeError):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment