Ver código fonte

Some more python3 fixes

oz123 10 anos atrás
pai
commit
1d91106ed1
3 arquivos alterados com 11 adições e 5 exclusões
  1. 3 3
      pwman/tests/test_complete_ui.py
  2. 5 2
      pwman/util/config.py
  3. 3 0
      scripts/pwman3

+ 3 - 3
pwman/tests/test_complete_ui.py

@@ -45,7 +45,7 @@ class Ferrum(unittest.TestCase):
     def test_a_db_warning(self):
         "when trying to run with old db, we should see warning"
         lfile = 'convert-test.log'
-        logfile = open(lfile, 'w')
+        logfile = open(lfile, 'wb')
         cmd = os.path.join(os.path.dirname(__file__), '../../scripts/pwman3'
                            ) + ' -d '+OLD_DB_PATH
         child = pexpect.spawn(cmd, logfile=logfile)
@@ -60,7 +60,7 @@ class Ferrum(unittest.TestCase):
     def test_b_run_convert(self):
         "invoke pwman with -k option to convert the old data"
         lfile = 'convert-test.log'
-        logfile = open(lfile, 'w')
+        logfile = open(lfile, 'wb')
         cmd = (os.path.join(os.path.dirname(__file__), '../../scripts/pwman3'
                             ) + ' -k -e Blowfish -d ' + OLD_DB_PATH)
         child = pexpect.spawn(cmd, logfile=logfile)
@@ -74,7 +74,7 @@ class Ferrum(unittest.TestCase):
 
     def test_c_change_pass(self):
         lfile = 'test-chg_passwd.log'
-        logfile = open(lfile, 'w')
+        logfile = open(lfile, 'wb')
         child = pexpect.spawn(os.path.join(os.path.dirname(__file__),
                                            '../../scripts/pwman3') +
                               ' -e Blowfish -d '+OLD_DB_PATH, logfile=logfile)

+ 5 - 2
pwman/util/config.py

@@ -110,7 +110,10 @@ def load(filename):
     try:
         try:
             fp = open(filename, "r")
-            parser.readfp(fp)
+            try:
+                parser.read_file(fp)
+            except AttributeError:
+                parser.readfp(fp)
         except ParsingError as e:
             raise ConfigException(e)
         except IOError as e:
@@ -144,7 +147,7 @@ def save(filename=None):
             for optionkey in sectiondict.keys():
                 parser.set(key, optionkey, sectiondict[optionkey])
     try:
-        fp = file(filename, "w+")
+        fp = open(filename, "w+")
         parser.write(fp)
         fp.close()
     except IOError as e:

+ 3 - 0
scripts/pwman3

@@ -31,6 +31,9 @@ import pwman.data.factory
 from pwman.data.convertdb import PwmanConvertDB
 from pwman.util.crypto_engine import CryptoEngine
 
+if sys.version_info.major > 2:
+    raw_input = input
+
 
 def auto_convert():
     try: