# HG changeset patch
# User Paul Moore
# Date 1365343730 -3600
# Node ID 27d8f89d64c398d9a7a63207d16ef361c3a00bfb
# Parent 1c496e933168ffb33622c8549bc1372d7a368f4f
Python 3 compatibility
diff -r 1c496e933168 -r 27d8f89d64c3 t.py
--- a/t.py Tue Oct 09 13:46:00 2012 -0400
+++ b/t.py Sun Apr 07 15:08:50 2013 +0100
@@ -32,7 +32,7 @@
Currently SHA1 hashing is used. It should be plenty for our purposes.
"""
- return hashlib.sha1(text).hexdigest()
+ return hashlib.sha1(text.encode('utf-8')).hexdigest()
def _task_from_taskline(taskline):
"""Parse a taskline (from a task file) and return a task.
@@ -150,13 +150,13 @@
If no tasks match the prefix an UnknownPrefix exception will be raised.
"""
- matched = filter(lambda tid: tid.startswith(prefix), self.tasks.keys())
+ matched = [tid for tid in self.tasks.keys() if tid.startswith(prefix)]
if len(matched) == 1:
return self.tasks[matched[0]]
elif len(matched) == 0:
raise UnknownPrefix(prefix)
else:
- matched = filter(lambda tid: tid == prefix, self.tasks.keys())
+ matched = [tid for tid in self.tasks.keys() if tid == prefix]
if len(matched) == 1:
return self.tasks[matched[0]]
else:
@@ -219,7 +219,7 @@
for _, task in sorted(tasks.items()):
if grep.lower() in task['text'].lower():
p = '%s - ' % task[label].ljust(plen) if not quiet else ''
- print p + task['text']
+ print (p + task['text'])
def write(self, delete_if_empty=False):
"""Flush the finished and unfinished tasks to the files on disk."""
@@ -302,9 +302,11 @@
kind = 'tasks' if not options.done else 'done'
td.print_list(kind=kind, verbose=options.verbose, quiet=options.quiet,
grep=options.grep)
- except AmbiguousPrefix, e:
+ except AmbiguousPrefix:
+ e = sys.exc_info()[1]
sys.stderr.write('The ID "%s" matches more than one task.\n' % e.prefix)
- except UnknownPrefix, e:
+ except UnknownPrefix:
+ e = sys.exc_info()[1]
sys.stderr.write('The ID "%s" does not match any task.\n' % e.prefix)