summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-09-16 14:09:46 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2012-09-22 10:37:02 +0100
commit83a2cee3595c0a2713ad0c610a9eea0b355b3037 (patch)
tree412cb4ad614da4f63bede75ef8156f77b93b7532 /alot
parentf669476d9afe8bdbe9d321e8adc96947e1d29926 (diff)
move ignorecase parameter to Addressbook.__init__
... and use it in subclasses lookup() methods
Diffstat (limited to 'alot')
-rw-r--r--alot/addressbooks.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/alot/addressbooks.py b/alot/addressbooks.py
index a1491f29..7767e597 100644
--- a/alot/addressbooks.py
+++ b/alot/addressbooks.py
@@ -18,19 +18,20 @@ class AddressBook(object):
unspecified. See :class:`AbookAddressBook` and
:class:`MatchSdtoutAddressbook` for implementations.
"""
+ def __init__(self, ignorecase=True):
+ self.reflags = re.IGNORECASE if ignorecase else 0
def get_contacts(self):
"""list all contacts tuples in this abook as (name, email) tuples"""
return []
- def lookup(self, query='', ignorecase=True):
+ def lookup(self, query=''):
"""looks up all contacts where name or address match query"""
res = []
query = '.*%s.*' % query
- flags = re.IGNORECASE if ignorecase else 0
for name, email in self.get_contacts():
try:
- if re.match(query, name, flags) or re.match(query, email, flags):
+ if re.match(query, name, self.reflags) or re.match(query, email, self.reflags):
res.append((name, email))
except:
pass
@@ -39,11 +40,12 @@ class AddressBook(object):
class AbookAddressBook(AddressBook):
""":class:`AddressBook` that parses abook's config/database files"""
- def __init__(self, path='~/.abook/addressbook'):
+ def __init__(self, path='~/.abook/addressbook', **kwargs):
"""
:param path: path to theme file
:type path: str
"""
+ AddressBook.__init__(self, **kwargs)
DEFAULTSPATH = os.path.join(os.path.dirname(__file__), 'defaults')
self._spec = os.path.join(DEFAULTSPATH, 'abook_contacts.spec')
path = os.path.expanduser(path)
@@ -63,7 +65,7 @@ class AbookAddressBook(AddressBook):
class MatchSdtoutAddressbook(AddressBook):
""":class:`AddressBook` that parses a shell command's output for lookups"""
- def __init__(self, command, match=None):
+ def __init__(self, command, match=None, **kwargs):
"""
:param command: lookup command
:type command: str
@@ -73,6 +75,7 @@ class MatchSdtoutAddressbook(AddressBook):
:regexp:`^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)`.
:type match: str
"""
+ AddressBook.__init__(self, **kwargs)
self.command = command
if not match:
self.match = '^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)'
@@ -90,7 +93,7 @@ class MatchSdtoutAddressbook(AddressBook):
lines = resultstring.splitlines()
res = []
for l in lines:
- m = re.match(self.match, l)
+ m = re.match(self.match, l, self.reflags)
if m:
info = m.groupdict()
email = info['email'].strip()