Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/defcon/test/testTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, name=None):
self.stack = []

def __repr__(self):
return "<_TestObservable {name} {id}".format(name=self.name, id=id(self))
return "<_TestObservable {name} {id}>".format(name=self.name, id=id(self))

def notificationCallback(self, notification):
print(notification.name, notification.object.name)
Expand Down
16 changes: 15 additions & 1 deletion Lib/defcon/test/tools/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ def test_addObserver_identifier(self):
dict(observer=observer, observable=observable, notification="A", identifier="identifier1"),
dict(observer=observer, observable=observable, notification="B", identifier="identifier2")
]
self.assertEqual(center.findObservations(), expected)
result = center.findObservations()
self.assertEqual(result, expected)

def test_addObserver_identifierDuplicate(self):
center = NotificationCenter()
Expand Down Expand Up @@ -528,5 +529,18 @@ def test_findObservations_all(self):
result = center.findObservations(observer=observer1, notification="A", observable=observable1, identifier="identifier1-1-A")
self.assertEqual(result, expected)

def test_findObservations_noIdentifier(self):
center = NotificationCenter()
observable = _TestObservable(center, "Observable")
observer = NotificationTestObserver()
center.addObserver(observer, "notificationCallback", "A", observable, identifier="identifier1")
center.addObserver(observer, "notificationCallback", "B", observable)
expected = [
dict(observer=observer, observable=observable, notification="A", identifier="identifier1"),
dict(observer=observer, observable=observable, notification="B", identifier=None)
]
result = center.findObservations()
self.assertEqual(result, expected)

if __name__ == "__main__":
unittest.main()
13 changes: 8 additions & 5 deletions Lib/defcon/tools/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,20 @@ def findObservations(self, observer=None, notification=None, observable=None, id
if observable is not None:
observable = weakref.ref(observable)
found = []
for (otherNotification, otherObservable), observerDict in self._identifierRegistry.items():
for (otherNotification, otherObservable), observerDict in self._registry.items():
if notification is not None:
if otherNotification != notification:
continue
if observable is not None:
if otherObservable != observable:
continue
for otherObserver, otherIdentifier in observerDict.items():
if identifier is not None:
if not fnmatchcase(otherIdentifier, identifier):
continue
for otherObserver, methodName in observerDict.items():
otherIdentifier = None
if (otherNotification, otherObservable) in self._identifierRegistry:
otherIdentifier = self._identifierRegistry[otherNotification, otherObservable].get(otherObserver)
if otherIdentifier is not None and identifier is not None:
if not fnmatchcase(otherIdentifier, identifier):
continue
if observer is not None:
if otherObserver != observer:
continue
Expand Down