def unregister(self, event, callback): regex = redis_to_py_pattern(event) entry = self.callbacks.get(regex) if entry: if callback in entry.callbacks: entry.callbacks.remove(callback) if not entry.callbacks: self.callbacks.pop(regex)
def test_redis_to_py_pattern(self): p = redis_to_py_pattern('h?llo') c = re.compile(p) self.match(c, 'hello') self.match(c, 'hallo') self.not_match(c, 'haallo') self.not_match(c, 'hallox') # p = redis_to_py_pattern('h*llo') c = re.compile(p) self.match(c, 'hello') self.match(c, 'hallo') self.match(c, 'hasjdbvhckjcvkfcdfllo') self.not_match(c, 'haallox') self.not_match(c, 'halloouih') # p = redis_to_py_pattern('h[ae]llo') c = re.compile(p) self.match(c, 'hello') self.match(c, 'hallo') self.not_match(c, 'hollo')
def register(self, event, callback): """Register a ``callback`` for ``event`` """ regex = redis_to_py_pattern(event) entry = self.callbacks.get(regex) if not entry: entry = regex_callbacks(re.compile(regex), []) self.callbacks[regex] = entry if callback not in entry.callbacks: entry.callbacks.append(callback) return entry
def event_pattern(self, event): """Channel pattern for an event name """ return redis_to_py_pattern(event)
def unregister(self, event, callback): regex = redis_to_py_pattern(event) entry = self.callbacks.get(regex) if entry: self._remove_callback(entry, callback)