Jelajahi Sumber

All tests pass with python3

oz123 10 tahun lalu
induk
melakukan
274192c38a
4 mengubah file dengan 59 tambahan dan 33 penghapusan
  1. 21 6
      pwman/data/nodes.py
  2. 15 7
      pwman/tests/db_tests.py
  3. 8 7
      pwman/ui/tools.py
  4. 15 13
      pwman/util/generator.py

+ 21 - 6
pwman/data/nodes.py

@@ -40,17 +40,32 @@ class NewNode(object):
 
     def dump_edit_to_db(self):
         dump = u""
-        dump += u"username:"+self._username.decode()+u"##"
-        dump += u"password:"+self._password.decode()+u"##"
-        dump += u"url:"+self._url.decode()+u"##"
-        dump += u"notes:"+self._notes.decode()+u"##"
+        try:
+            dump += u"username:"+self._username.decode()+u"##"
+        except AttributeError:
+            dump += u"username:"+self._username+u"##"
+        try:
+            dump += u"password:"+self._password.decode()+u"##"
+        except AttributeError:
+            dump += u"password:"+self._password+u"##"
+        try:
+            dump += u"url:"+self._url.decode()+u"##"
+        except AttributeError:
+            dump += u"url:"+self._url+u"##"
+        try:
+            dump += u"notes:"+self._notes.decode()+u"##"
+        except AttributeError:
+            dump += u"notes:"+self._notes+u"##"
         dump += u"tags:"
         tagsloc = u""
         for tag in self._tags:
             if isinstance(tag, str):
                 tagsloc += u"tag:"+tag.strip()+u"**endtag**"
-            else:
-                tagsloc += u"tag:"+tag._name.decode()+u"**endtag**"
+            if isinstance(tag, bytes):
+                try:
+                    tagsloc += u"tag:"+tag.decode()+u"**endtag**"
+                except:
+                    tagsloc += u"tag:"+tag+u"**endtag**"
 
         dump += tagsloc
         dump = [dump]

+ 15 - 7
pwman/tests/db_tests.py

@@ -38,7 +38,7 @@ import unittest
 if sys.version_info.major > 2:
     from io import StringIO
 else:
-    import StringIO
+    from StringIO import StringIO
 import os
 import os.path
 
@@ -329,13 +329,21 @@ class CLITests(unittest.TestCase):
                              node.tags,
                              node.tags))
 
-        dummy_stdin = StringIO.StringIO('4\n\nX')
-        self.assertTrue(len(dummy_stdin.readlines()))
-        dummy_stdin.seek(0)
-        sys.stdin = dummy_stdin
-        menu.run(node)
+        dummy_stdin = StringIO('4\n\nX')
+
+        class dummy_stdin(object):
+
+            def __init__(self):
+                self.idx = -1
+                self.ans = ['4', 'some fucking notes','X']
+
+            def __call__(self, msg):
+                self.idx += 1
+                return self.ans[self.idx]
+
+        dstin = dummy_stdin()
+        menu.run(node, reader=dstin)
         self.tester.cli._db.editnode(2, node)
-        sys.stdin = sys.__stdin__
 
     def test_get_pass_conf(self):
         numerics, leet, s_chars = get_pass_conf()

+ 8 - 7
pwman/ui/tools.py

@@ -236,7 +236,7 @@ class CMDLoop(object):  # pragma: no cover
         else:
             print (item.__class__)
 
-    def run(self, new_node=None):
+    def run(self, new_node=None, reader=raw_input):
         while True:
             i = 0
             for x in self.items:
@@ -247,13 +247,14 @@ class CMDLoop(object):  # pragma: no cover
                     current = x
 
                 # when printing tags, we have list ...
-                currentstr = ''
+                currentstr = b''
                 if type(current) == list:
                     for c in current:
+                        print(c, type(c))
                         try:
-                            currentstr += ' ' + c
+                            currentstr += b' ' + c
                         except TypeError:
-                            currentstr += ' ' + c.name
+                            currentstr += b' ' + c.name
                 # for the case we are not dealing with
                 # a list of tags
                 else:
@@ -261,7 +262,7 @@ class CMDLoop(object):  # pragma: no cover
 
                 print ("%s - %s: %s" % (i, x.name, currentstr))
             print("X - Finish editing")
-            option = raw_input("Enter your choice:")[0]
+            option = reader("Enter your choice:")[0]
             try:
                 print ("Selection, ", option)
                 # substract 1 because array subscripts start at 0
@@ -287,7 +288,7 @@ class CMDLoop(object):  # pragma: no cover
                     self.items[2].setter = new_node.url
                 elif selection == 3:  # for notes
                     # new_node.notes = getinput("Notes:")
-                    new_node.notes = getinput("Notes:")
+                    new_node.notes = reader("Notes:")
                     self.items[3].getter = new_node.notes
                     self.items[3].setter = new_node.notes
                 elif selection == 4:
@@ -301,7 +302,7 @@ class CMDLoop(object):  # pragma: no cover
                 if (option.upper() == 'X'):
                     break
                 print("Invalid selection")
-            
+
 
 def getonechar(question, width=_defaultwidth):  # pragma: no cover
     question = "%s " % (question)

+ 15 - 13
pwman/util/generator.py

@@ -1,15 +1,15 @@
 #============================================================================
 # This file is part of Pwman3.
-# 
+#
 # Pwman3 is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License, version 2
-# as published by the Free Software Foundation; 
-# 
+# as published by the Free Software Foundation;
+#
 # Pwman3 is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
@@ -75,7 +75,7 @@ def random_special_sign(password):
     this will do the following:
     In [203]: for i in range(10):
     print random_special_sign("secret")
-    .....:     
+    .....:
     secre%
     sec\et
     secre?
@@ -89,7 +89,7 @@ def random_special_sign(password):
     note: numbers are not replaced:
     In [5]: for i in range(10):
     print random_special_sign(password)
-   ...:     
+   ...:
     s3cr?t
     s3cr$t
     s3cre#
@@ -100,12 +100,12 @@ def random_special_sign(password):
     s3*ret
     s3cre:
     s3cr@t
-    
+
     In [6]: password = "v3r71mp0rt4nt"
-    
+
     In [7]: for i in range(10):
         print random_special_sign(password)
-   ...:     
+   ...:
     v3r71mp0rt4)t
     v3r71m&0rt4nt
     v3r71mp0rt4-t
@@ -121,11 +121,11 @@ def random_special_sign(password):
     specialsigns = ["@", "#", "?", "!", '\\', "|", "$",
                      "%", "^", "&", "*", "(", ")", ":", ";",
                      "{", "}", "+","-"]
-     
+
     place = int(random.randint(0, len(password)-1))
     while password[place].isdigit():
         place = int(random.randint(0, len(password)-1))
-    
+
     randomsign = specialsigns[int(random.randint(0, len(specialsigns)-1))]
     for idx, letter in enumerate(password):
         if not idx == place:
@@ -133,7 +133,7 @@ def random_special_sign(password):
         if idx == place:
             newpass = newpass + randomsign
     return newpass
-    
+
 def change_numerics(password):
     newpassword = str()
     for l in password:
@@ -1569,7 +1569,7 @@ def _random_word(pwlen):
         #
         # Append the syllable units to the word units.
         #
-        word_units = word_units + syllable_units
+        word_units = word_units + list(syllable_units)
 
         #
         # If the word has been improperly formed, throw out
@@ -1728,6 +1728,7 @@ def _have_initial_y(units):
         #
         # Count vowels.
         #
+        units = list(units)
         if (gram_rules[units[unit_count]] & VOWEL):
             vowel_count = vowel_count + 1
 
@@ -1759,6 +1760,7 @@ def _have_final_split(units):
     # Count all the vowels in the word.
     #
     for unit_count in range(len(units)):
+        units = list(units)
         if (gram_rules[units[unit_count]] & VOWEL):
             vowel_count = vowel_count + 1