(self, rule: str)
| 603 | return _urlencode(items) |
| 604 | |
| 605 | def _parse_rule(self, rule: str) -> t.Iterable[RulePart]: |
| 606 | content = "" |
| 607 | static = True |
| 608 | argument_weights = [] |
| 609 | static_weights: list[tuple[int, int]] = [] |
| 610 | final = False |
| 611 | convertor_number = 0 |
| 612 | |
| 613 | pos = 0 |
| 614 | while pos < len(rule): |
| 615 | match = _part_re.match(rule, pos) |
| 616 | if match is None: |
| 617 | raise ValueError(f"malformed url rule: {rule!r}") |
| 618 | |
| 619 | data = match.groupdict() |
| 620 | if data["static"] is not None: |
| 621 | static_weights.append((len(static_weights), -len(data["static"]))) |
| 622 | self._trace.append((False, data["static"])) |
| 623 | content += data["static"] if static else re.escape(data["static"]) |
| 624 | |
| 625 | if data["variable"] is not None: |
| 626 | if static: |
| 627 | # Switching content to represent regex, hence the need to escape |
| 628 | content = re.escape(content) |
| 629 | static = False |
| 630 | c_args, c_kwargs = parse_converter_args(data["arguments"] or "") |
| 631 | convobj = self.get_converter( |
| 632 | data["variable"], data["converter"] or "default", c_args, c_kwargs |
| 633 | ) |
| 634 | self._converters[data["variable"]] = convobj |
| 635 | self.arguments.add(data["variable"]) |
| 636 | if not convobj.part_isolating: |
| 637 | final = True |
| 638 | content += f"(?P<__werkzeug_{convertor_number}>{convobj.regex})" |
| 639 | convertor_number += 1 |
| 640 | argument_weights.append(convobj.weight) |
| 641 | self._trace.append((True, data["variable"])) |
| 642 | |
| 643 | if data["slash"] is not None: |
| 644 | self._trace.append((False, "/")) |
| 645 | if final: |
| 646 | content += "/" |
| 647 | else: |
| 648 | if not static: |
| 649 | content += r"\Z" |
| 650 | weight = Weighting( |
| 651 | -len(static_weights), |
| 652 | static_weights, |
| 653 | -len(argument_weights), |
| 654 | argument_weights, |
| 655 | ) |
| 656 | yield RulePart( |
| 657 | content=content, |
| 658 | final=final, |
| 659 | static=static, |
| 660 | suffixed=False, |
| 661 | weight=weight, |
| 662 | ) |
no test coverage detected