Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

gpgsigner.py ported to Python 3 #10

Merged
merged 1 commit into from

2 participants

therealplato nanotube
therealplato

Some libraries were renamed or changed:
xmlrpclib was changed to xmlrpc.client
StringIO was changed to io


Python 3 makes a distinction between strings and bytes. stdin accepts
bytes which must be encoded from our input string. stdout returns bytes
which must be decoded into our output string.

(note - UTF8 encoding is the default and is used here, it may not be the
best choice. This script is untested on Python 2.x.)

Pipe challenge to gpg's stdin:
old: p1.stdin.write(input)
new: p1.stdin.write(bytes(input, 'UTF8'))

Pipe gpg's output to the XMLRPC call:
old: pasteid = s.pastes.newPaste('text',output)
new: pasteid = s.pastes.newPaste('text',output.decode())


Finally, the print statement is now a print() function:
old: print "http://paste.pocoo.org/raw/%s/" % (pasteid)
new: print ("http://paste.pocoo.org/raw/",pasteid,"/", sep="")

nanotube nanotube merged commit e87743d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2011
  1. therealplato
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 0 deletions.
  1. +25 −0 GPG/gpgsigner.py3.py
25 GPG/gpgsigner.py3.py
View
@@ -0,0 +1,25 @@
+#/usr/bin/env python
+
+#
+# script to automatically gpg sign a message, upload it to paste.pocoo.org,
+# and spit out the raw paste url. very effort-saving!
+#
+# usage:
+# python gpgsigner.py yourchallengestringgoeshere
+#
+# original code by nanotube, python 3 port by PLATO
+
+from xmlrpc.client import ServerProxy
+import subprocess
+import sys
+import io
+
+input = " ".join(sys.argv[1:])
+
+p1 = subprocess.Popen(['gpg','--clearsign'], stdin = subprocess.PIPE, stdout=subprocess.PIPE)
+p1.stdin.write(bytes(input, 'UTF8'))
+output = p1.communicate()[0]
+
+s = ServerProxy('http://paste.pocoo.org/xmlrpc/')
+pasteid = s.pastes.newPaste('text',output.decode())
+print ("http://paste.pocoo.org/raw/",pasteid,"/", sep="")
Something went wrong with that request. Please try again.