Return the matched text for this match or an empty string if no query exists for this match. `_usecache` can be set to False in testing to avoid any unwanted caching side effects as the caching depends on which index instance is being used and this index can
(
self,
whole_lines=False,
highlight=True,
highlight_matched='{}',
highlight_not_matched='[{}]',
_usecache=True,
)
| 755 | # FIXME: this should be done for all the matches found in a given scanned |
| 756 | # location at once to avoid reprocessing many times the original text |
| 757 | def matched_text( |
| 758 | self, |
| 759 | whole_lines=False, |
| 760 | highlight=True, |
| 761 | highlight_matched='{}', |
| 762 | highlight_not_matched='[{}]', |
| 763 | _usecache=True, |
| 764 | ): |
| 765 | """ |
| 766 | Return the matched text for this match or an empty string if no query |
| 767 | exists for this match. |
| 768 | |
| 769 | `_usecache` can be set to False in testing to avoid any unwanted caching |
| 770 | side effects as the caching depends on which index instance is being |
| 771 | used and this index can change during testing. |
| 772 | """ |
| 773 | if TRACE_MATCHED_TEXT and not TRACE_REPR_ALL_MATCHED_TEXTS: |
| 774 | logger_debug(f'LicenseMatch.matched_text: self.query: {self.query}') |
| 775 | |
| 776 | query = self.query |
| 777 | if not query: |
| 778 | # TODO: should we raise an exception instead??? |
| 779 | # this case should never exist except for tests! |
| 780 | return u'' |
| 781 | |
| 782 | if whole_lines and query.has_long_lines: |
| 783 | whole_lines = False |
| 784 | |
| 785 | return ''.join(get_full_matched_text( |
| 786 | match=self, |
| 787 | location=query.location, |
| 788 | query_string=query.query_string, |
| 789 | idx=query.idx, |
| 790 | whole_lines=whole_lines, |
| 791 | highlight=highlight, |
| 792 | highlight_matched=highlight_matched, |
| 793 | highlight_not_matched=highlight_not_matched, |
| 794 | _usecache=_usecache |
| 795 | )).rstrip() |
| 796 | |
| 797 | def to_dict( |
| 798 | self, |