mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-14 14:49:21 +01:00
Handle changes to fnmatch.translate in Python 2.6
Define utils.python.glob2re based on the Python version being used. Use glob2re in Todo and Note plugins. Closes: Sf#3059292 Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
fc2a84fb90
commit
b0575cec88
@ -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):
|
||||
|
@ -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]
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user