Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where multiple handlers weren't registering correctly #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

blampe
Copy link

@blampe blampe commented Jan 27, 2017

The use case here is this:

@listen_to("(.*)")
def do_some_fallback(msg):
    ...

@listen_to("(.*)")
def do_some_other_fallback(msg):
    ...

We want >1 function attached to one regex "(.*)". However due to the way Python compiles regexs, these handlers were overwriting themselves here:

PluginsManager.commands['respond_to'][re.compile(regexp, flags)] = func

To convince yourself what's happening:

$ python
Python 2.7.13 (default, Dec 18 2016, 07:03:34)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> mapping = {}
>>> mapping[re.compile('(.*)', 0)] = 1
>>> mapping[re.compile('(.*)', 0)] = 2
>>> mapping[re.compile('(.*)', 0)] = 3
>>> mapping
{<_sre.SRE_Pattern object at 0x10f418580>: 3}

@blampe
Copy link
Author

blampe commented Feb 1, 2017

cc @gotlium

@gotlium
Copy link
Contributor

gotlium commented Feb 1, 2017

Hi, we need to test with our existing code. Or you can add some settings to enable this feature. Because we have a backward compatibility with slackbot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants