Folder: Implement __eq__ for folders
This allows to compare folders directly with strings. It also allows constructs such as "if 'moo' in repo.getfolders()". See the code documentation for the exact behavior (it basically is equal if it's the same instance *or* a string matching the untranslated folder name. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
75ea403278
commit
10dd317026
@ -479,3 +479,20 @@ class BaseFolder(object):
|
|||||||
self.ui.error(e, exc_info()[2], "Syncing folder %s [acc: %s]" %\
|
self.ui.error(e, exc_info()[2], "Syncing folder %s [acc: %s]" %\
|
||||||
(self, self.accountname))
|
(self, self.accountname))
|
||||||
raise # raise unknown Exceptions so we can fix them
|
raise # raise unknown Exceptions so we can fix them
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""Comparisons work either on string comparing folder names or
|
||||||
|
on the same instance
|
||||||
|
|
||||||
|
MailDirFolder('foo') == 'foo' --> True
|
||||||
|
a = MailDirFolder('foo'); a == b --> True
|
||||||
|
MailDirFolder('foo') == 'moo' --> False
|
||||||
|
MailDirFolder('foo') == IMAPFolder('foo') --> False
|
||||||
|
MailDirFolder('foo') == MaildirFolder('foo') --> False
|
||||||
|
"""
|
||||||
|
if isinstance(other, basestring):
|
||||||
|
return other == self.name
|
||||||
|
return id(self) == id(other)
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
Loading…
Reference in New Issue
Block a user