diff options
Diffstat (limited to 'lang/python')
| -rwxr-xr-x | lang/python/examples/delkey.py | 18 | ||||
| -rwxr-xr-x | lang/python/examples/encrypt-to-all.py | 17 | ||||
| -rwxr-xr-x | lang/python/examples/exportimport.py | 25 | ||||
| -rw-r--r-- | lang/python/examples/inter-edit.py | 11 | 
4 files changed, 38 insertions, 33 deletions
| diff --git a/lang/python/examples/delkey.py b/lang/python/examples/delkey.py index dfcc5ea4..600e0c07 100755 --- a/lang/python/examples/delkey.py +++ b/lang/python/examples/delkey.py @@ -2,10 +2,10 @@  # $Id$  # Copyright (C) 2004,2008 Igor Belyi <[email protected]>  # -#    This program is free software; you can redistribute it and/or modify -#    it under the terms of the GNU General Public License as published by -#    the Free Software Foundation; either version 2 of the License, or -#    (at your option) any later version. +#    This program is free software; you can redistribute it and/or +#    modify it under the terms of the GNU General Public License as +#    published by the Free Software Foundation; either version 2 of +#    the License, or (at your option) any later version.  #  #    This program is distributed in the hope that it will be useful,  #    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  #    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  # It deletes keys for [email protected] generated by genkey.pl script @@ -23,9 +24,10 @@ from pyme import core  core.check_version(None) -# Note that we need to collect all keys out of the iterator return by c.op_keylist_all() -# method before starting to delete them. If you delete a key in the middle of iteration -# c.op_keylist_next() will raise INV_VALUE exception +# Note that we need to collect all keys out of the iterator return by +# c.op_keylist_all() method before starting to delete them. If you +# delete a key in the middle of iteration c.op_keylist_next() will +# raise INV_VALUE exception  c = core.Context()  # 0 in keylist means to list not only public but secret keys as well. diff --git a/lang/python/examples/encrypt-to-all.py b/lang/python/examples/encrypt-to-all.py index c890df4f..672e6614 100755 --- a/lang/python/examples/encrypt-to-all.py +++ b/lang/python/examples/encrypt-to-all.py @@ -3,10 +3,10 @@  # Copyright (C) 2008 Igor Belyi <[email protected]>  # Copyright (C) 2002 John Goerzen <[email protected]>  # -#    This program is free software; you can redistribute it and/or modify -#    it under the terms of the GNU General Public License as published by -#    the Free Software Foundation; either version 2 of the License, or -#    (at your option) any later version. +#    This program is free software; you can redistribute it and/or +#    modify it under the terms of the GNU General Public License as +#    published by the Free Software Foundation; either version 2 of +#    the License, or (at your option) any later version.  #  #    This program is distributed in the hope that it will be useful,  #    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  #    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 @@ -46,11 +47,11 @@ for key in c.op_keylist_all(None, 0):          valid = 0          for subkey in key.subkeys:              keyid = subkey.keyid -            if keyid == None: +            if keyid is None:                  break              can_encrypt = subkey.can_encrypt              valid += can_encrypt -            print("     Subkey %s: encryption %s" % \ +            print("     Subkey %s: encryption %s" %                    (keyid, can_encrypt and "enabled" or "disabled"))      except UnicodeEncodeError as e:          print(e) @@ -64,5 +65,3 @@ passno = 0  print("Encrypting to %d recipients" % len(names))  print(sendto(names)) - - diff --git a/lang/python/examples/exportimport.py b/lang/python/examples/exportimport.py index 54204fb7..6c7d5b8f 100755 --- a/lang/python/examples/exportimport.py +++ b/lang/python/examples/exportimport.py @@ -2,10 +2,10 @@  # $Id$  # Copyright (C) 2004,2008 Igor Belyi <[email protected]>  # -#    This program is free software; you can redistribute it and/or modify -#    it under the terms of the GNU General Public License as published by -#    the Free Software Foundation; either version 2 of the License, or -#    (at your option) any later version. +#    This program is free software; you can redistribute it and/or +#    modify it under the terms of the GNU General Public License as +#    published by the Free Software Foundation; either version 2 of +#    the License, or (at your option) any later version.  #  #    This program is distributed in the hope that it will be useful,  #    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  #    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  # It uses keys for [email protected] generated by genkey.pl script @@ -33,7 +34,7 @@ print(" - Export %s's public keys - " % user)  c.op_export(user, 0, expkey)  # print out exported data to see how it looks in armor. -expkey.seek(0,0) +expkey.seek(0, 0)  expstring = expkey.read()  if expstring:      print(expstring) @@ -46,10 +47,10 @@ else:  # 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  # exported public one. If it's Ok with you uncomment the next 4 lines. -#print " - Delete %s's public keys - " % user -#for thekey in [x for x in c.op_keylist_all(user, 0)]: -#    if not thekey.secret: -#        c.op_delete(thekey, 1) +# print " - Delete %s's public keys - " % user +# for thekey in [x for x in c.op_keylist_all(user, 0)]: +#     if not thekey.secret: +#         c.op_delete(thekey, 1)  # 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:      print(" - Result of the import - ")      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":                  print(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))              else:                  print(k, ":", result.__getattr__(k)) diff --git a/lang/python/examples/inter-edit.py b/lang/python/examples/inter-edit.py index f97232b7..32f8edd9 100644 --- a/lang/python/examples/inter-edit.py +++ b/lang/python/examples/inter-edit.py @@ -14,9 +14,11 @@  #  #    You should have received a copy of the GNU General Public License  #    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.core import Data, Context  from pyme.constants import status @@ -29,12 +31,13 @@ for name in dir(status):      if not name.startswith('__') and name != "util":          stat2str[getattr(status, name)] = name +  # Print the output received since the last prompt before giving the new prompt  def edit_fnc(stat, args, helper):      global stat_strings      try:          while True: -            helper["data"].seek(helper["skip"],0) +            helper["data"].seek(helper["skip"], 0)              data = helper["data"].read()              helper["skip"] += len(data)              print(data) @@ -53,5 +56,5 @@ else:      helper = {"skip": 0, "data": out}      c.op_edit(key, edit_fnc, helper, out)      print("[-- Final output --]") -    out.seek(helper["skip"],0) +    out.seek(helper["skip"], 0)      print(out.read()) | 
