| 767 | return params |
| 768 | |
| 769 | def match(self, other): |
| 770 | if not other: |
| 771 | return False |
| 772 | |
| 773 | if not isinstance(other, MediaType): |
| 774 | other = MediaType(other) |
| 775 | |
| 776 | main_types = [self.main_type, other.main_type] |
| 777 | sub_types = [self.sub_type, other.sub_type] |
| 778 | |
| 779 | # Main types and sub types must be defined. |
| 780 | if not all((*main_types, *sub_types)): |
| 781 | return False |
| 782 | |
| 783 | # Main types must match or one be "*", same for sub types. |
| 784 | for this_type, other_type in (main_types, sub_types): |
| 785 | if this_type != other_type and this_type != "*" and other_type != "*": |
| 786 | return False |
| 787 | |
| 788 | if bool(self.range_params) == bool(other.range_params): |
| 789 | # If both have params or neither have params, they must be |
| 790 | # identical. |
| 791 | result = self.range_params == other.range_params |
| 792 | else: |
| 793 | # If self has params and other does not, it's a match. |
| 794 | # If other has params and self does not, don't match. |
| 795 | result = bool(self.range_params or not other.range_params) |
| 796 | return result |
| 797 | |
| 798 | @cached_property |
| 799 | def quality(self): |