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

Mapping regex to function parameters #25

Open
BenjamenMeyer opened this issue Mar 26, 2015 · 2 comments
Open

Mapping regex to function parameters #25

BenjamenMeyer opened this issue Mar 26, 2015 · 2 comments

Comments

@BenjamenMeyer
Copy link
Member

v0.8 introduced using regex to be able to register the end-point handler.
It could be useful, however, to use the regex functionality to assign portions of the URL to the functions parameters in order to not have to apply the regex twice.

The functions currently look like the following:

def my_handler(self, request, uri, headers)
      return (200, headers, 'hello')

Under this proposal, the functions could look like:

def my_handler(self, request, uri, headers, my_param1)
      return (200, headers, 'hello from {0}'.format(my_param1)
@BenjamenMeyer
Copy link
Member Author

this could be handled a few different ways:

  1. Inspect the target function's callspec to determine what parameters to provide
  2. Update the registration function to tell it whether or not to forwards the regex group matches (if any) to the function. The registration might be able to validate that groups are part of the regex result as part of the process.
self.register(MyClass.my_handler, MyClass.PathMatchRegEx, forward_regex_groups=True)

Default would have to be False....something to think about.

@BenjamenMeyer
Copy link
Member Author

This will be easier to implement and validate once Issue #71 has been completed.

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

No branches or pull requests

1 participant