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

Using get_empty_kwargs to provide custom keyword arguments (#2487). #15

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 15 additions & 9 deletions nereid/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,26 @@ def __init__(self, *args, **kwargs):
self.is_csrf_exempt = kwargs.pop('exempt_csrf', False)
super(Rule, self).__init__(*args, **kwargs)

def empty(self):
"""Return an unbound copy of this rule. This can be useful if you
want to reuse an already bound URL for another map.
def get_empty_kwargs(self):
"""
Provides kwargs for instantiating empty copy with empty()

Use this method to provide custom keyword arguments to the subclass of
``Rule`` when calling ``some_rule.empty()``. Helpful when the subclass
has custom keyword arguments that are needed at instantiation.

Ref: https://github.com/mitsuhiko/werkzeug/pull/645
Must return a ``dict`` that will be provided as kwargs to the new
instance of ``Rule``, following the initial ``self.rule`` value which
is always provided as the first, required positional argument.
"""
defaults = None
if self.defaults:
defaults = dict(self.defaults)
return self.__class__(
self.rule, defaults, self.subdomain, self.methods,
self.build_only, self.endpoint, self.strict_slashes,
self.redirect_to, self.alias, self.host
)
return dict(defaults=defaults, subdomain=self.subdomain,
methods=self.methods, build_only=self.build_only,
endpoint=self.endpoint, strict_slashes=self.strict_slashes,
redirect_to=self.redirect_to, alias=self.alias,
host=self.host, readonly=self.readonly)

@property
def is_readonly(self):
Expand Down