Explorar o código

Fix bugs related to python3.4

oz123 %!s(int64=10) %!d(string=hai) anos
pai
achega
8a6f059e11
Modificáronse 2 ficheiros con 9 adicións e 9 borrados
  1. 8 2
      pwman/data/drivers/sqlite.py
  2. 1 7
      pwman/data/nodes.py

+ 8 - 2
pwman/data/drivers/sqlite.py

@@ -24,6 +24,7 @@
 from pwman.data.database import Database, DatabaseException
 from pwman.data.database import Database, DatabaseException
 from pwman.data.database import __DB_FORMAT__
 from pwman.data.database import __DB_FORMAT__
 from pwman.data.nodes import NewNode
 from pwman.data.nodes import NewNode
+from pwman.data.tags import TagNew
 from pwman.util.crypto_engine import CryptoEngine
 from pwman.util.crypto_engine import CryptoEngine
 import sqlite3 as sqlite
 import sqlite3 as sqlite
 import itertools
 import itertools
@@ -226,8 +227,10 @@ class SQLiteDatabaseNewForm(Database):
 
 
         if isinstance(tag, str):
         if isinstance(tag, str):
             self._cur.execute(sql, [tag])
             self._cur.execute(sql, [tag])
-        else:
+        elif isinstance(tag, TagNew):
             self._cur.execute(sql, [tag._name])
             self._cur.execute(sql, [tag._name])
+        else:
+            self._cur.execute(sql, [tag.decode()])
 
 
     def _deletenodetags(self, node):
     def _deletenodetags(self, node):
         try:
         try:
@@ -248,14 +251,17 @@ class SQLiteDatabaseNewForm(Database):
     def _tagids(self, tags):
     def _tagids(self, tags):
         ids = []
         ids = []
         sql = "SELECT ID FROM TAGS WHERE DATA LIKE ?"
         sql = "SELECT ID FROM TAGS WHERE DATA LIKE ?"
+
         for tag in tags:
         for tag in tags:
             try:
             try:
                 if isinstance(tag, str):
                 if isinstance(tag, str):
                     enc = CryptoEngine.get()
                     enc = CryptoEngine.get()
                     tag = enc.encrypt(tag)
                     tag = enc.encrypt(tag)
                     self._cur.execute(sql, [tag])
                     self._cur.execute(sql, [tag])
-                else:
+                elif isinstance(tag, TagNew):
                     self._cur.execute(sql, [tag._name.decode()+u'%'])
                     self._cur.execute(sql, [tag._name.decode()+u'%'])
+                else:
+                    self._cur.execute(sql, [tag.decode()+u'%'])
 
 
                 values = self._cur.fetchall()
                 values = self._cur.fetchall()
                 if values:  # tags already exist in the database
                 if values:  # tags already exist in the database

+ 1 - 7
pwman/data/nodes.py

@@ -61,14 +61,8 @@ class NewNode(object):
         for tag in self._tags:
         for tag in self._tags:
             if isinstance(tag, str):
             if isinstance(tag, str):
                 tagsloc += u"tag:"+tag.strip()+u"**endtag**"
                 tagsloc += u"tag:"+tag.strip()+u"**endtag**"
-            if isinstance(tag, bytes):
-                try:
-                    tagsloc += u"tag:"+tag.decode()+u"**endtag**"
-                except:
-                    tagsloc += u"tag:"+tag+u"**endtag**"
-
             else:
             else:
-                tagsloc += u'tag:'+tag._name+u'**endtag**'
+                tagsloc += u'tag:'+tag._name.decode()+u'**endtag**'
 
 
         dump += tagsloc
         dump += tagsloc
         dump = [dump]
         dump = [dump]