Skip to content

Instantly share code, notes, and snippets.

@firedfox
Created September 21, 2012 10:02
Show Gist options
  • Save firedfox/3760718 to your computer and use it in GitHub Desktop.
Save firedfox/3760718 to your computer and use it in GitHub Desktop.
jskit
#!/usr/bin/python
import re, sys, urllib
if __name__ == '__main__':
e = len(sys.argv) >= 3
if len(sys.argv) > 1:
r = re.compile('([^\x00-\xff])')
f = open(sys.argv[1])
s = f.read()
try:
s = unicode(s, 'utf-8')
s = r.sub(lambda s : s.group(0).encode('raw_unicode_escape'), s)
if e:
print s
else:
print urllib.quote(s)
except:
if e:
print s
else:
print urllib.quote(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment