Saving unicode keys as string objects in cache database

This commit is contained in:
Manuel Cortez 2015-08-10 09:24:46 -05:00
parent eb0cf62a54
commit bad468560a
2 changed files with 5 additions and 4 deletions

View File

@ -457,7 +457,7 @@ class baseBufferController(bufferController):
self.session.sound.play("audio.ogg")
if utils.is_geocoded(tweet):
self.session.sound.play("geo.ogg")
# self.session.db[str(self.name+"_pos")]=self.buffer.list.get_selected()
self.session.db[self.name+"_pos"]=self.buffer.list.get_selected()
@_tweets_exist
def audio(self,url=''):

View File

@ -381,10 +381,11 @@ class Session(object):
if type(key) != str and type(key) != unicode:
output.speak("Uh oh, while shelving the database, a key of type " + str(type(key)) + " has been found. It will be converted to type str, but this will cause all sorts of problems on deshelve. Please bring this to the attention of the " + application.name + " developers immediately. More information about the error will be written to the error log.",True)
log.error("Uh oh, " + str(key) + " is of type " + str(type(key)) + "!")
# Convert unicode objects to UTF-8 strings before shelve these objects.
if type(value) == list and self.settings["general"]["persist_size"] != -1 and len(value) > self.settings["general"]["persist_size"]:
shelf[str(key)]=value[self.settings["general"]["persist_size"]:]
shelf[str(key.encode("utf-8"))]=value[self.settings["general"]["persist_size"]:]
else:
shelf[str(key)]=value
shelf[str(key.encode("utf-8"))]=value
shelf.close()
except:
output.speak("An exception occurred while shelving the " + application.name + " database. It will be deleted and rebuilt automatically. If this error persists, send the error log to the " + application.name + " developers.",True)
@ -401,7 +402,7 @@ class Session(object):
try:
shelf=shelve.open(paths.config_path(shelfname),'c')
for key,value in shelf.items():
self.db[unicode(key)]=value
self.db[key]=value
shelf.close()
except:
output.speak("An exception occurred while deshelving the " + application.name + " database. It will be deleted and rebuilt automatically. If this error persists, send the error log to the " + application.name + " developers.",True)