changeset 11107:5f2902c0470d

<Jafet> fetch http://sprunge.us/MXOA
author HackBot
date Fri, 21 Jul 2017 12:34:55 +0000
parents 40c5d61c5d37
children 8f3c7e3a6f51
files MXOA
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MXOA	Fri Jul 21 12:34:55 2017 +0000
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+import re, sys, unicodedata as U
+def tr(c):
+    m = re.match(r'(.*\bLATIN\b.*\bLETTER )([A-Z])\b(.*)', U.name(c, ''))
+    if m:
+        p, q, r = m.groups()
+        n = ord(q) - ord('A')
+        try:
+            return U.lookup(p + chr(ord('A') + (n + 13) % 26) + r)
+        except KeyError:
+            return c
+    return c
+
+def tr2(c):
+    d = tr(c)
+    if d != c:
+        return d
+    else:
+        cs = [unichr(int(x, 16)) for x in U.decomposition(c).split()]
+        ds = [tr(x) for x in cs]
+        if cs != ds:
+            return u''.join(ds)
+        else:
+            return c
+
+for c in unicode(sys.stdin.read(), 'utf8'):
+    sys.stdout.write(tr2(c).encode('utf8'))
+