python: PEP8 fixes.

Cherry picked from 0267c151.

Signed-off-by: Justus Winter <justus@gnupg.org>
This commit is contained in:
Justus Winter 2016-05-10 14:45:44 +02:00
parent aade53a12b
commit 11392a80d9
4 changed files with 38 additions and 33 deletions

View File

@ -2,10 +2,10 @@
# $Id$ # $Id$
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net> # Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published by # modify it under the terms of the GNU General Public License as
# the Free Software Foundation; either version 2 of the License, or # published by the Free Software Foundation; either version 2 of
# (at your option) any later version. # the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -14,7 +14,8 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
# Sample of key deletion # Sample of key deletion
# It deletes keys for joe@example.org generated by genkey.pl script # It deletes keys for joe@example.org generated by genkey.pl script
@ -23,9 +24,10 @@ from pyme import core
core.check_version(None) core.check_version(None)
# Note that we need to collect all keys out of the iterator return by c.op_keylist_all() # Note that we need to collect all keys out of the iterator return by
# method before starting to delete them. If you delete a key in the middle of iteration # c.op_keylist_all() method before starting to delete them. If you
# c.op_keylist_next() will raise INV_VALUE exception # delete a key in the middle of iteration c.op_keylist_next() will
# raise INV_VALUE exception
c = core.Context() c = core.Context()
# 0 in keylist means to list not only public but secret keys as well. # 0 in keylist means to list not only public but secret keys as well.

View File

@ -3,10 +3,10 @@
# Copyright (C) 2008 Igor Belyi <belyi@users.sourceforge.net> # Copyright (C) 2008 Igor Belyi <belyi@users.sourceforge.net>
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org> # Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published by # modify it under the terms of the GNU General Public License as
# the Free Software Foundation; either version 2 of the License, or # published by the Free Software Foundation; either version 2 of
# (at your option) any later version. # the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -15,7 +15,8 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
""" """
This program will try to encrypt a simple message to each key on your This program will try to encrypt a simple message to each key on your
@ -46,11 +47,11 @@ for key in c.op_keylist_all(None, 0):
valid = 0 valid = 0
for subkey in key.subkeys: for subkey in key.subkeys:
keyid = subkey.keyid keyid = subkey.keyid
if keyid == None: if keyid is None:
break break
can_encrypt = subkey.can_encrypt can_encrypt = subkey.can_encrypt
valid += can_encrypt valid += can_encrypt
print(" Subkey %s: encryption %s" % \ print(" Subkey %s: encryption %s" %
(keyid, can_encrypt and "enabled" or "disabled")) (keyid, can_encrypt and "enabled" or "disabled"))
except UnicodeEncodeError as e: except UnicodeEncodeError as e:
print(e) print(e)
@ -64,5 +65,3 @@ passno = 0
print("Encrypting to %d recipients" % len(names)) print("Encrypting to %d recipients" % len(names))
print(sendto(names)) print(sendto(names))

View File

@ -2,10 +2,10 @@
# $Id$ # $Id$
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net> # Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published by # modify it under the terms of the GNU General Public License as
# the Free Software Foundation; either version 2 of the License, or # published by the Free Software Foundation; either version 2 of
# (at your option) any later version. # the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -14,7 +14,8 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
# Sample of export and import of keys # Sample of export and import of keys
# It uses keys for joe@example.org generated by genkey.pl script # It uses keys for joe@example.org generated by genkey.pl script
@ -33,7 +34,7 @@ print(" - Export %s's public keys - " % user)
c.op_export(user, 0, expkey) c.op_export(user, 0, expkey)
# print out exported data to see how it looks in armor. # print out exported data to see how it looks in armor.
expkey.seek(0,0) expkey.seek(0, 0)
expstring = expkey.read() expstring = expkey.read()
if expstring: if expstring:
print(expstring) print(expstring)
@ -46,10 +47,10 @@ else:
# Note that since joe's key has private part as well we can only delete # Note that since joe's key has private part as well we can only delete
# both of them. As a side effect joe won't have private key for this # both of them. As a side effect joe won't have private key for this
# exported public one. If it's Ok with you uncomment the next 4 lines. # exported public one. If it's Ok with you uncomment the next 4 lines.
#print " - Delete %s's public keys - " % user # print " - Delete %s's public keys - " % user
#for thekey in [x for x in c.op_keylist_all(user, 0)]: # for thekey in [x for x in c.op_keylist_all(user, 0)]:
# if not thekey.secret: # if not thekey.secret:
# c.op_delete(thekey, 1) # c.op_delete(thekey, 1)
# initialize import data from a string as if it was read from a file. # initialize import data from a string as if it was read from a file.
@ -63,11 +64,11 @@ result = c.op_import_result()
if result: if result:
print(" - Result of the import - ") print(" - Result of the import - ")
for k in dir(result): for k in dir(result):
if not k in result.__dict__ and not k.startswith("_"): if k not in result.__dict__ and not k.startswith("_"):
if k == "imports": if k == "imports":
print(k, ":") print(k, ":")
for impkey in result.__getattr__(k): for impkey in result.__getattr__(k):
print(" fpr=%s result=%d status=%x" % \ print(" fpr=%s result=%d status=%x" %
(impkey.fpr, impkey.result, impkey.status)) (impkey.fpr, impkey.result, impkey.status))
else: else:
print(k, ":", result.__getattr__(k)) print(k, ":", result.__getattr__(k))

View File

@ -14,9 +14,11 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
import os, sys import os
import sys
from pyme import core from pyme import core
from pyme.core import Data, Context from pyme.core import Data, Context
from pyme.constants import status from pyme.constants import status
@ -29,12 +31,13 @@ for name in dir(status):
if not name.startswith('__') and name != "util": if not name.startswith('__') and name != "util":
stat2str[getattr(status, name)] = name stat2str[getattr(status, name)] = name
# Print the output received since the last prompt before giving the new prompt # Print the output received since the last prompt before giving the new prompt
def edit_fnc(stat, args, helper): def edit_fnc(stat, args, helper):
global stat_strings global stat_strings
try: try:
while True: while True:
helper["data"].seek(helper["skip"],0) helper["data"].seek(helper["skip"], 0)
data = helper["data"].read() data = helper["data"].read()
helper["skip"] += len(data) helper["skip"] += len(data)
print(data) print(data)
@ -53,5 +56,5 @@ else:
helper = {"skip": 0, "data": out} helper = {"skip": 0, "data": out}
c.op_edit(key, edit_fnc, helper, out) c.op_edit(key, edit_fnc, helper, out)
print("[-- Final output --]") print("[-- Final output --]")
out.seek(helper["skip"],0) out.seek(helper["skip"], 0)
print(out.read()) print(out.read())