diff bin/percent_encode.py @ 85:1daa8e444cfe

work-around for weird handling of %-encoding in Java impl. of SURT
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 24 Aug 2023 18:21:41 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/percent_encode.py	Thu Aug 24 18:21:41 2023 +0100
@@ -0,0 +1,9 @@
+'''Handle unquoting of non-UTF-8 bytes by %-encoding them'''
+import codecs
+
+def percent_encode(ude):
+  #print(ude.object,ude.object[ude.start:ude.end])
+  return (''.join('%%%X'%c for c in ude.object[ude.start:ude.end]),
+          ude.end)
+
+codecs.register_error('percent',percent_encode)