@@ -222,7 +222,8 @@ def bind(
222
222
server_name = server_name .lower ()
223
223
if self .host_matching :
224
224
if subdomain is not None :
225
- raise RuntimeError ("host matching enabled and a subdomain was provided" )
225
+ raise RuntimeError (
226
+ "host matching enabled and a subdomain was provided" )
226
227
elif subdomain is None :
227
228
subdomain = self .default_subdomain
228
229
if script_name is None :
@@ -602,12 +603,14 @@ def match(
602
603
path_part = f"/{ path_info .lstrip ('/' )} " if path_info else ""
603
604
604
605
try :
605
- result = self .map ._matcher .match (domain_part , path_part , method , websocket )
606
+ result = self .map ._matcher .match (
607
+ domain_part , path_part , method , websocket )
606
608
except RequestPath as e :
607
609
# safe = https://url.spec.whatwg.org/#url-path-segment-string
608
610
new_path = quote (e .path_info , safe = "!$&'()*+,/:;=@" )
609
611
raise RequestRedirect (
610
- self .make_redirect_url (new_path , query_args )
612
+ self .make_redirect_url (new_path , query_args ),
613
+ new_path ,
611
614
) from None
612
615
except RequestAliasRedirect as e :
613
616
raise RequestRedirect (
@@ -617,11 +620,13 @@ def match(
617
620
e .matched_values ,
618
621
method ,
619
622
query_args ,
620
- )
623
+ ),
624
+ path_part ,
621
625
) from None
622
626
except NoMatch as e :
623
627
if e .have_match_for :
624
- raise MethodNotAllowed (valid_methods = list (e .have_match_for )) from None
628
+ raise MethodNotAllowed (
629
+ valid_methods = list (e .have_match_for )) from None
625
630
626
631
if e .websocket_mismatch :
627
632
raise WebsocketMismatch () from None
@@ -631,9 +636,10 @@ def match(
631
636
rule , rv = result
632
637
633
638
if self .map .redirect_defaults :
634
- redirect_url = self .get_default_redirect (rule , method , rv , query_args )
639
+ (redirect_url , redirect_path ) = self .get_default_redirect (
640
+ rule , method , rv , query_args )
635
641
if redirect_url is not None :
636
- raise RequestRedirect (redirect_url )
642
+ raise RequestRedirect (redirect_url , redirect_path )
637
643
638
644
if rule .redirect_to is not None :
639
645
if isinstance (rule .redirect_to , str ):
@@ -642,7 +648,8 @@ def _handle_match(match: t.Match[str]) -> str:
642
648
value = rv [match .group (1 )]
643
649
return rule ._converters [match .group (1 )].to_url (value )
644
650
645
- redirect_url = _simple_rule_re .sub (_handle_match , rule .redirect_to )
651
+ redirect_url = _simple_rule_re .sub (
652
+ _handle_match , rule .redirect_to )
646
653
else :
647
654
redirect_url = rule .redirect_to (self , ** rv )
648
655
@@ -655,7 +662,8 @@ def _handle_match(match: t.Match[str]) -> str:
655
662
urljoin (
656
663
f"{ self .url_scheme or 'http' } ://{ netloc } { self .script_name } " ,
657
664
redirect_url ,
658
- )
665
+ ),
666
+ redirect_url ,
659
667
)
660
668
661
669
if return_rule :
@@ -736,8 +744,9 @@ def get_default_redirect(
736
744
if r .provides_defaults_for (rule ) and r .suitable_for (values , method ):
737
745
values .update (r .defaults ) # type: ignore
738
746
domain_part , path = r .build (values ) # type: ignore
739
- return self .make_redirect_url (path , query_args , domain_part = domain_part )
740
- return None
747
+ return self .make_redirect_url (path , query_args ,
748
+ domain_part = domain_part ), path
749
+ return None , None
741
750
742
751
def encode_query_args (self , query_args : t .Mapping [str , t .Any ] | str ) -> str :
743
752
if not isinstance (query_args , str ):
0 commit comments