aboutsummaryrefslogtreecommitdiff
path: root/demos/demo_keygen.py
diff options
context:
space:
mode:
Diffstat (limited to 'demos/demo_keygen.py')
-rwxr-xr-xdemos/demo_keygen.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/demos/demo_keygen.py b/demos/demo_keygen.py
index bdd7388..860ee4e 100755
--- a/demos/demo_keygen.py
+++ b/demos/demo_keygen.py
@@ -17,9 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-from __future__ import with_statement
-import string
import sys
from binascii import hexlify
@@ -28,6 +26,7 @@ from optparse import OptionParser
from paramiko import DSSKey
from paramiko import RSAKey
from paramiko.ssh_exception import SSHException
+from paramiko.py3compat import u
usage="""
%prog [-v] [-b bits] -t type [-N new_passphrase] [-f output_keyfile]"""
@@ -47,16 +46,16 @@ key_dispatch_table = {
def progress(arg=None):
if not arg:
- print '0%\x08\x08\x08',
+ sys.stdout.write('0%\x08\x08\x08 ')
sys.stdout.flush()
elif arg[0] == 'p':
- print '25%\x08\x08\x08\x08',
+ sys.stdout.write('25%\x08\x08\x08\x08 ')
sys.stdout.flush()
elif arg[0] == 'h':
- print '50%\x08\x08\x08\x08',
+ sys.stdout.write('50%\x08\x08\x08\x08 ')
sys.stdout.flush()
elif arg[0] == 'x':
- print '75%\x08\x08\x08\x08',
+ sys.stdout.write('75%\x08\x08\x08\x08 ')
sys.stdout.flush()
if __name__ == '__main__':
@@ -92,8 +91,8 @@ if __name__ == '__main__':
parser.print_help()
sys.exit(0)
- for o in default_values.keys():
- globals()[o] = getattr(options, o, default_values[string.lower(o)])
+ for o in list(default_values.keys()):
+ globals()[o] = getattr(options, o, default_values[o.lower()])
if options.newphrase:
phrase = getattr(options, 'newphrase')
@@ -106,7 +105,7 @@ if __name__ == '__main__':
if ktype == 'dsa' and bits > 1024:
raise SSHException("DSA Keys must be 1024 bits")
- if not key_dispatch_table.has_key(ktype):
+ if ktype not in key_dispatch_table:
raise SSHException("Unknown %s algorithm to generate keys pair" % ktype)
# generating private key
@@ -121,7 +120,7 @@ if __name__ == '__main__':
f.write(" %s" % comment)
if options.verbose:
- print "done."
+ print("done.")
- hash = hexlify(pub.get_fingerprint())
- print "Fingerprint: %d %s %s.pub (%s)" % (bits, ":".join([ hash[i:2+i] for i in range(0, len(hash), 2)]), filename, string.upper(ktype))
+ hash = u(hexlify(pub.get_fingerprint()))
+ print("Fingerprint: %d %s %s.pub (%s)" % (bits, ":".join([ hash[i:2+i] for i in range(0, len(hash), 2)]), filename, ktype.upper()))