about summary refs log tree commit diff
path: root/.escape_codes_url.py
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2016-06-24T16·20-0400
committerWilliam Carroll <wpcarro@gmail.com>2016-06-24T16·20-0400
commit00c2bdc9886d19abf2224fe7738dc773d01b82e6 (patch)
treec9bf879dade4b504c202813d95eaa7a94185dc5d /.escape_codes_url.py
parent0166fe0c48d9513be1ced4b574364268a075c271 (diff)
Adds new script to retrieve URL escape codes
Diffstat (limited to '.escape_codes_url.py')
-rw-r--r--.escape_codes_url.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/.escape_codes_url.py b/.escape_codes_url.py
new file mode 100644
index 000000000000..60aa1c210694
--- /dev/null
+++ b/.escape_codes_url.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+
+"""
+Forward and Backward lookups for URL escape sequences
+"""
+
+import sys, re
+
+
+literal_to_esccode = {
+  ' ': '%20',
+  '<': '%3C',
+  '>': '%3E',
+  '#': '%23',
+  '%': '%25',
+  '{': '%7B',
+  '}': '%7D',
+  '|': '%7C',
+  '\\': '%5C',
+  '^': '%5E',
+  '~': '%7E',
+  '[': '%5B',
+  ']': '%5D',
+  '`': '%60',
+  ';': '%3B',
+  '/': '%2F',
+  '?': '%3F',
+  ':': '%3A',
+  '@': '%40',
+  '=': '%3D',
+  '&': '%26',
+  '$': '%24',
+}
+
+
+esccode_to_literal = {
+  v: k for k, v in literal_to_esccode.items()
+}
+
+
+def is_esccode(string):
+  p = re.compile(r'^%\w\w$')
+  m = p.match(string)
+  return bool(p.match(string))
+
+
+try:
+  el = sys.argv[1]
+except:
+  el = None
+
+if not el:
+  print literal_to_esccode
+else:
+  msg = esccode_to_literal[el] if is_esccode(el) else literal_to_esccode[el]
+  print '"{0}": "{1}"'.format(el, msg)