Commits

Jason R. Coombs  committed 4a3333f

Fix a few errors on Python 3

  • Participants
  • Parent commits bfdab40

Comments (0)

Files changed (2)

File keyring/__init__.py

 import logging
 logger = logging.getLogger('keyring')
 
-from core import set_keyring, get_keyring, set_password, get_password
+from keyring.core import set_keyring, get_keyring, set_password, get_password
 from keyring.getpassbackend import get_password as get_pass_get_password

File keyring/core.py

 Created by Kang Zhang on 2009-07-09
 """
 import os
-import ConfigParser
+try:
+	import configparser as config_parser
+except ImportError:
+	import ConfigParser as config_parser
 import imp
 import sys
 
 
         keyrings = backend.get_all_keyring()
         # rank according to the supported result
-        keyrings.sort(lambda x, y: y.supported() - x.supported())
+        keyrings.sort(key=lambda x, y: y.supported() - x.supported())
         # get the most recommended one
         keyring = keyrings[0]
 
         module = load_module(keyring_name, sys.path+[keyring_path])
 
     keyring_class = keyring_name.split('.')[-1].strip()
-    exec  "keyring_temp = module." + keyring_class + "() " in locals()
+    exec("keyring_temp = module." + keyring_class + "() ", locals=locals())
 
     return keyring_temp
 
             break
 
     if os.path.exists(keyring_cfg):
-        config = ConfigParser.RawConfigParser()
+        config = config_parser.RawConfigParser()
         config.read(keyring_cfg)
         # load the keyring-path option
         try:
                 keyring_path = config.get("backend", "keyring-path").strip()
             else:
                 keyring_path = None
-        except ConfigParser.NoOptionError:
+        except config_parser.NoOptionError:
             keyring_path = None
 
         # load the keyring class name, and then load this keyring
             if config.has_section("backend"):
                 keyring_name = config.get("backend", "default-keyring").strip()
             else:
-                raise ConfigParser.NoOptionError('backend', 'default-keyring')
+                raise config_parser.NoOptionError('backend', 'default-keyring')
 
             keyring = load_keyring(keyring_path, keyring_name)
-        except (ConfigParser.NoOptionError, ImportError):
+        except (config_parser.NoOptionError, ImportError):
             logger.warning("Keyring config file contains incorrect values.\n" +
                            "Config file: %s" % keyring_cfg)