From: khamidou Date: Wed, 10 Feb 2010 12:06:20 +0000 (+0100) Subject: some bugfixes revolving around unicode X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c464b525240c9b821dbfd85ea62bc4c24c37314a;p=liszt.git some bugfixes revolving around unicode --- diff --git a/liszt b/liszt index 9d7532e..3b66429 100755 --- a/liszt +++ b/liszt @@ -32,7 +32,7 @@ def help(): print "liszt r[remove|d|delete listname ?entryindex?" print "liszt s listname ?entryindex?" print "liszt chk|check listname index" - print "liszt u|update listname index ?'new description'? ?'check'? ?'date'?" + print "liszt u|update listname" def bailout(msg): @@ -45,7 +45,18 @@ def create_spool_file(dict): os.write(fd, json.dumps(dict)) os.close(fd) - +class CachedList(object): + def __init__(self, listname): + try: + fd = open(os.path.expanduser('~/.liszt/cached/%s' % listname)) + except IOError: + bailout("Unable to open cached list " + listname) + + try: + self.list = json.load(fd) + except ValueError: + bailout("List %s is not a valid json file" % listname) + fd.close() class CommandParser(object): def __init__(self, args): self.dispatch = {"create" : self.parse_create, @@ -201,8 +212,7 @@ class CommandParser(object): # fields = lines[i].split("\t") FIXME: add support for different fields on a line. if lines[i] != '': - session.create_list_entry(listname, lines[i].rstrip().lstrip()) - dict = {"request" : "create-entry", "listname" : listname, "contents" : {"title" : lines[i]}} + dict = {"request" : "create-entry", "listname" : listname, "content" : {"title" : lines[i].rstrip().lstrip()}} create_spool_file(dict) os.unlink(filename) diff --git a/liszt-daemon b/liszt-daemon index f676e01..c021b59 100755 --- a/liszt-daemon +++ b/liszt-daemon @@ -186,12 +186,16 @@ class LisztSession: continue def create_list(self, listname): + listname = listname.encode("utf8") try: urllib2.urlopen(base + "/create/" + quote(listname) + "/") except HTTPError: bailout("Unable to create the list " + listname) def create_list_entry(self, listname, entry): + listname = listname.encode("utf8") + entry = entry.encode("utf8") + try: urllib2.urlopen(base + "/create/" + quote(listname) + "/" + quote(entry) + "/") except HTTPError: @@ -291,6 +295,7 @@ def process_json_delayed_file(path): session.create_list_entry(data["listname"], data["content"]["title"]) # FIXME : use the other options if defined. except KeyError: return + elif data["request"] == "delete-list": session.remove_list(data["listname"]) elif data["request"] == "delete-entry":