Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 15th, 2011  |  syntax: None  |  size: 0.69 KB  |  hits: 71  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # -*- coding: utf-8 -*-
  2. import quopri
  3. import StringIO
  4.  
  5. # helpers (the quopri module only supports file-to-file conversion)
  6.  
  7. def encodestring(instring, tabs=0):
  8.     outfile = StringIO.StringIO()
  9.     quopri.encode(StringIO.StringIO(instring), outfile, tabs)
  10.     return outfile.getvalue()
  11.  
  12. def decodestring(instring):
  13.     outfile = StringIO.StringIO()
  14.     quopri.decode(StringIO.StringIO(instring), outfile)
  15.     return outfile.getvalue()
  16.  
  17. firstExample = "=91hey=92"
  18. print decodestring(firstExample).decode('windows-1252')
  19.  
  20. secondExample = "=E2=80=98=E2=80=99,=E2=80=9C=E2=80=9D=3Dhey=C3=B7=C2=BD=C3=96=C3=B1=E2=99=A6=E2=86=92%@=C2=A5=C3=B7"
  21. print decodestring(secondExample).decode('utf-8')