diff --git a/plugins/Note/plugin.py b/plugins/Note/plugin.py index 95a53bbea..3fd3cb326 100644 --- a/plugins/Note/plugin.py +++ b/plugins/Note/plugin.py @@ -30,7 +30,6 @@ import re import time -import fnmatch import operator import supybot.dbi as dbi @@ -98,15 +97,9 @@ class DbiNoteDB(dbi.DB): self.set(id, n) def getUnnotifiedIds(self, to): -## def p(note): -## return not note.notified and note.to == to -## return [note.id for note in self.select(p)] return self.unNotified.get(to, []) def getUnreadIds(self, to): -## def p(note): -## return not note.read and note.to == to -## return [note.id for note in self.select(p)] return self.unRead.get(to, []) def send(self, frm, to, public, text): @@ -303,9 +296,8 @@ class Note(callbacks.Plugin): elif option == 'sent': own = frm if glob: - glob = fnmatch.translate(glob) - # ignore the trailing $ fnmatch.translate adds to the regexp - criteria.append(re.compile(glob[:-1]).search) + glob = utils.python.glob2re(glob) + criteria.append(re.compile(glob).search) def match(note): for p in criteria: if not p(note.text): diff --git a/plugins/Todo/plugin.py b/plugins/Todo/plugin.py index efc415e5f..b995140ba 100644 --- a/plugins/Todo/plugin.py +++ b/plugins/Todo/plugin.py @@ -1,5 +1,6 @@ ### # Copyright (c) 2003-2005, Daniel DiPaolo +# Copyright (c) 2010, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -30,7 +31,6 @@ import os import re import time -import fnmatch import operator import supybot.dbi as dbi @@ -230,8 +230,8 @@ class Todo(callbacks.Plugin): if option == 'regexp': criteria.append(arg.search) for glob in globs: - glob = fnmatch.translate(glob) - criteria.append(re.compile(glob[:-1]).search) + glob = utils.python.glob2re(glob) + criteria.append(re.compile(glob).search) try: tasks = self.db.select(user.id, criteria) L = [format('#%i: %s', t.id, self._shrink(t.task)) for t in tasks] diff --git a/src/utils/python.py b/src/utils/python.py index d636d62bb..f38de2f78 100644 --- a/src/utils/python.py +++ b/src/utils/python.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2005-2009, Jeremiah Fincher -# Copyright (c) 2009, James Vega +# Copyright (c) 2009-2010, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -30,6 +30,7 @@ import sys import types +import fnmatch import UserDict import threading @@ -65,7 +66,6 @@ def changeFunctionName(f, name, doc=None): class Object(object): def __ne__(self, other): return not self == other - class Synchronized(type): METHODS = '__synchronized__' @@ -103,5 +103,15 @@ class Synchronized(type): newclass = super(Synchronized, cls).__new__(cls, name, bases, dict) return newclass +# Translate glob to regular expression, trimming the "match EOL" portion of +# the regular expression. +if sys.version_info < (2, 6, 0): + # Pre-2.6 just uses the $ anchor + def glob2re(g): + return fnmatch.translate(g)[:-1] +else: + # Post-2.6 uses \Z(?ms) per http://issues.python.org/6665 + def glob2re(g): + return fnmatch.translate(g)[:-7] # vim:set shiftwidth=4 softtabstop=8 expandtab textwidth=78: