Revision: 29094
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 21, 2010 11:33 by seanboycegmailcom
Initial Code
#!/usr/bin/env python __author__ = 'Sean Boyce' __license__ = 'PSF' import sys, urllib def usage(): import os.path scriptname = os.path.basename(sys.argv[0]) ret = """Usage: %s KEY=VALUE ... Returns a html encoded post string based on keys and values Example: In: %s name="Fred" email="[email protected]" Out: name=Fred&email=fred%%40example.com """ % (scriptname, scriptname,) return ret def html_encode(args): try: import urllib ls = [ tuple(x.split('=', 1)) for x in args ] return urllib.urlencode(ls, True) except Exception, e: sys.stderr.write(" ".join( ["Error!", e.__str__(), "\n"] ) ) return None if __name__ == '__main__': ret = 1 if len(sys.argv) > 1: output = html_encode(sys.argv[1:]) if output is not None: ret = 0 print(output) else: print usage() sys.exit(ret)
Initial URL
Initial Description
URLencode key-value pairs for HTTP POST - useful from shell, make sure you chmod +x this script before using.
Initial Title
HTML encode key-value pairs for HTTP POST (script)
Initial Tags
Initial Language
Python