8141:27f636beebad | 8143:2c730d5fd177 |
---|---|
98 self.__allowedDomains = [] | 98 self.__allowedDomains = [] |
99 | 99 |
100 self.__isEnabled = True | 100 self.__isEnabled = True |
101 self.__isException = False | 101 self.__isException = False |
102 self.__isInternalDisabled = False | 102 self.__isInternalDisabled = False |
103 self.__caseSensitivity = Qt.CaseInsensitive | 103 self.__caseSensitivity = Qt.CaseSensitivity.CaseInsensitive |
104 | 104 |
105 self.__type = AdBlockRuleType.StringContainsMatchRule | 105 self.__type = AdBlockRuleType.StringContainsMatchRule |
106 self.__options = AdBlockRuleOption.NoOption | 106 self.__options = AdBlockRuleOption.NoOption |
107 self.__exceptions = AdBlockRuleOption.NoOption | 107 self.__exceptions = AdBlockRuleOption.NoOption |
108 | 108 |
193 for option in options: | 193 for option in options: |
194 if option.startswith("domain="): | 194 if option.startswith("domain="): |
195 self.__parseDomains(option[7:], "|") | 195 self.__parseDomains(option[7:], "|") |
196 handledOptions += 1 | 196 handledOptions += 1 |
197 elif option == "match-case": | 197 elif option == "match-case": |
198 self.__caseSensitivity = Qt.CaseSensitive | 198 self.__caseSensitivity = Qt.CaseSensitivity.CaseSensitive |
199 handledOptions += 1 | 199 handledOptions += 1 |
200 elif option.endswith("third-party"): | 200 elif option.endswith("third-party"): |
201 self.setOption(AdBlockRuleOption.ThirdPartyOption) | 201 self.setOption(AdBlockRuleOption.ThirdPartyOption) |
202 self.__setException(AdBlockRuleOption.ThirdPartyOption, | 202 self.__setException(AdBlockRuleOption.ThirdPartyOption, |
203 option.startswith("~")) | 203 option.startswith("~")) |
489 @rtype bool | 489 @rtype bool |
490 """ | 490 """ |
491 matched = False | 491 matched = False |
492 | 492 |
493 if self.__type == AdBlockRuleType.StringContainsMatchRule: | 493 if self.__type == AdBlockRuleType.StringContainsMatchRule: |
494 if self.__caseSensitivity == Qt.CaseInsensitive: | 494 if self.__caseSensitivity == Qt.CaseSensitivity.CaseInsensitive: |
495 matched = self.__matchString.lower() in encodedUrl.lower() | 495 matched = self.__matchString.lower() in encodedUrl.lower() |
496 else: | 496 else: |
497 matched = self.__matchString in encodedUrl | 497 matched = self.__matchString in encodedUrl |
498 elif self.__type == AdBlockRuleType.DomainMatchRule: | 498 elif self.__type == AdBlockRuleType.DomainMatchRule: |
499 matched = self.__isMatchingDomain(domain, self.__matchString) | 499 matched = self.__isMatchingDomain(domain, self.__matchString) |
500 elif self.__type == AdBlockRuleType.StringEndsMatchRule: | 500 elif self.__type == AdBlockRuleType.StringEndsMatchRule: |
501 if self.__caseSensitivity == Qt.CaseInsensitive: | 501 if self.__caseSensitivity == Qt.CaseSensitivity.CaseInsensitive: |
502 matched = encodedUrl.lower().endswith( | 502 matched = encodedUrl.lower().endswith( |
503 self.__matchString.lower()) | 503 self.__matchString.lower()) |
504 else: | 504 else: |
505 matched = encodedUrl.endswith(self.__matchString) | 505 matched = encodedUrl.endswith(self.__matchString) |
506 elif self.__type == AdBlockRuleType.RegExpMatchRule: | 506 elif self.__type == AdBlockRuleType.RegExpMatchRule: |
575 @type QWebEngineUrlRequestInfo | 575 @type QWebEngineUrlRequestInfo |
576 @return flag indicating a match | 576 @return flag indicating a match |
577 @rtype bool | 577 @rtype bool |
578 """ | 578 """ |
579 match = ( | 579 match = ( |
580 req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeObject) | 580 req.resourceType() == |
581 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeObject) | |
581 | 582 |
582 if self.__hasException(AdBlockRuleOption.ObjectOption): | 583 if self.__hasException(AdBlockRuleOption.ObjectOption): |
583 return not match | 584 return not match |
584 else: | 585 else: |
585 return match | 586 return match |
593 @return flag indicating a match | 594 @return flag indicating a match |
594 @rtype boolean | 595 @rtype boolean |
595 """ | 596 """ |
596 match = ( | 597 match = ( |
597 req.resourceType() == | 598 req.resourceType() == |
598 QWebEngineUrlRequestInfo.ResourceTypeSubFrame) | 599 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeSubFrame) |
599 | 600 |
600 if self.__hasException(AdBlockRuleOption.SubdocumentOption): | 601 if self.__hasException(AdBlockRuleOption.SubdocumentOption): |
601 return not match | 602 return not match |
602 else: | 603 else: |
603 return match | 604 return match |
610 @type QWebEngineUrlRequestInfo | 611 @type QWebEngineUrlRequestInfo |
611 @return flag indicating a match | 612 @return flag indicating a match |
612 @rtype bool | 613 @rtype bool |
613 """ | 614 """ |
614 match = ( | 615 match = ( |
615 req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeXhr) | 616 req.resourceType() == |
617 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeXhr) | |
616 | 618 |
617 if self.__hasException(AdBlockRuleOption.XMLHttpRequestOption): | 619 if self.__hasException(AdBlockRuleOption.XMLHttpRequestOption): |
618 return not match | 620 return not match |
619 else: | 621 else: |
620 return match | 622 return match |
627 @type QWebEngineUrlRequestInfo | 629 @type QWebEngineUrlRequestInfo |
628 @return flag indicating a match | 630 @return flag indicating a match |
629 @rtype bool | 631 @rtype bool |
630 """ | 632 """ |
631 match = ( | 633 match = ( |
632 req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeImage) | 634 req.resourceType() == |
635 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeImage) | |
633 | 636 |
634 if self.__hasException(AdBlockRuleOption.ImageOption): | 637 if self.__hasException(AdBlockRuleOption.ImageOption): |
635 return not match | 638 return not match |
636 else: | 639 else: |
637 return match | 640 return match |
644 @type QWebEngineUrlRequestInfo | 647 @type QWebEngineUrlRequestInfo |
645 @return flag indicating a match | 648 @return flag indicating a match |
646 @rtype bool | 649 @rtype bool |
647 """ | 650 """ |
648 match = ( | 651 match = ( |
649 req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeScript) | 652 req.resourceType() == |
653 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeScript) | |
650 | 654 |
651 if self.__hasException(AdBlockRuleOption.ScriptOption): | 655 if self.__hasException(AdBlockRuleOption.ScriptOption): |
652 return not match | 656 return not match |
653 else: | 657 else: |
654 return match | 658 return match |
662 @return flag indicating a match | 666 @return flag indicating a match |
663 @rtype bool | 667 @rtype bool |
664 """ | 668 """ |
665 match = ( | 669 match = ( |
666 req.resourceType() == | 670 req.resourceType() == |
667 QWebEngineUrlRequestInfo.ResourceTypeStylesheet) | 671 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeStylesheet) |
668 | 672 |
669 if self.__hasException(AdBlockRuleOption.StyleSheetOption): | 673 if self.__hasException(AdBlockRuleOption.StyleSheetOption): |
670 return not match | 674 return not match |
671 else: | 675 else: |
672 return match | 676 return match |
680 @return flag indicating a match | 684 @return flag indicating a match |
681 @rtype boolean | 685 @rtype boolean |
682 """ | 686 """ |
683 match = ( | 687 match = ( |
684 req.resourceType() == | 688 req.resourceType() == |
685 QWebEngineUrlRequestInfo.ResourceTypeSubResource | 689 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeSubResource |
686 ) | 690 ) |
687 match = match or ( | 691 match = match or ( |
688 req.resourceType() == | 692 req.resourceType() == |
689 QWebEngineUrlRequestInfo.ResourceTypePluginResource | 693 QWebEngineUrlRequestInfo.ResourceType.ResourceTypePluginResource |
690 ) | 694 ) |
691 | 695 |
692 if self.__objectSubrequestException: | 696 if self.__objectSubrequestException: |
693 return not match | 697 return not match |
694 else: | 698 else: |
702 @type QWebEngineUrlRequestInfo | 706 @type QWebEngineUrlRequestInfo |
703 @return flag indicating a match | 707 @return flag indicating a match |
704 @rtype bool | 708 @rtype bool |
705 """ | 709 """ |
706 match = ( | 710 match = ( |
707 req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypePing) | 711 req.resourceType() == |
712 QWebEngineUrlRequestInfo.ResourceType.ResourceTypePing) | |
708 | 713 |
709 if self.__hasException(AdBlockRuleOption.PingOption): | 714 if self.__hasException(AdBlockRuleOption.PingOption): |
710 return not match | 715 return not match |
711 else: | 716 else: |
712 return match | 717 return match |
719 @type QWebEngineUrlRequestInfo | 724 @type QWebEngineUrlRequestInfo |
720 @return flag indicating a match | 725 @return flag indicating a match |
721 @rtype bool | 726 @rtype bool |
722 """ | 727 """ |
723 match = ( | 728 match = ( |
724 req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeMedia) | 729 req.resourceType() == |
730 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMedia) | |
725 | 731 |
726 if self.__hasException(AdBlockRuleOption.MediaOption): | 732 if self.__hasException(AdBlockRuleOption.MediaOption): |
727 return not match | 733 return not match |
728 else: | 734 else: |
729 return match | 735 return match |
737 @return flag indicating a match | 743 @return flag indicating a match |
738 @rtype bool | 744 @rtype bool |
739 """ | 745 """ |
740 match = ( | 746 match = ( |
741 req.resourceType() == | 747 req.resourceType() == |
742 QWebEngineUrlRequestInfo.ResourceTypeFontResource) | 748 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeFontResource) |
743 | 749 |
744 if self.__hasException(AdBlockRuleOption.FontOption): | 750 if self.__hasException(AdBlockRuleOption.FontOption): |
745 return not match | 751 return not match |
746 else: | 752 else: |
747 return match | 753 return match |
754 @type QWebEngineUrlRequestInfo | 760 @type QWebEngineUrlRequestInfo |
755 @return flag indicating a match | 761 @return flag indicating a match |
756 @rtype bool | 762 @rtype bool |
757 """ | 763 """ |
758 match = req.resourceType() in [ | 764 match = req.resourceType() in [ |
759 QWebEngineUrlRequestInfo.ResourceTypeSubResource, | 765 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeSubResource, |
760 QWebEngineUrlRequestInfo.ResourceTypeWorker, | 766 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeWorker, |
761 QWebEngineUrlRequestInfo.ResourceTypeSharedWorker, | 767 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeSharedWorker, |
762 QWebEngineUrlRequestInfo.ResourceTypeServiceWorker, | 768 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeServiceWorker, |
763 QWebEngineUrlRequestInfo.ResourceTypePrefetch, | 769 QWebEngineUrlRequestInfo.ResourceType.ResourceTypePrefetch, |
764 QWebEngineUrlRequestInfo.ResourceTypeFavicon, | 770 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeFavicon, |
765 QWebEngineUrlRequestInfo.ResourceTypeUnknown, | 771 QWebEngineUrlRequestInfo.ResourceType.ResourceTypeUnknown, |
766 ] | 772 ] |
767 | 773 |
768 if self.__hasException(AdBlockRuleOption.OtherOption): | 774 if self.__hasException(AdBlockRuleOption.OtherOption): |
769 return not match | 775 return not match |
770 else: | 776 else: |