# eric6.WebBrowser.AdBlock.AdBlockRule

Module implementing the AdBlock rule class.

### Global Attributes

None

### Classes

AdBlockRule | Class implementing the AdBlock rule.
AdBlockRuleOption | Class implementing the rule option enum.
AdBlockRuleType | Class implementing the rule type enum.

### Functions

toSecondLevelDomain | Module function to get a second level domain from the given URL.

## AdBlockRule

Class implementing the AdBlock rule.

### Derived from

object

### Class Attributes

None

### Class Methods

None

### Methods

AdBlockRule | Constructor
__convertPatternToRegExp | Private method to convert a wildcard pattern to a regular expression.
__filterIsOnlyDomain | Private method to check, if the given filter is a domain only filter.
__filterIsOnlyEndsMatch | Private method to check, if the given filter is to match against the end of a string.
__hasException | Private method to check, if the given option has been set as an exception.
__hasOption | Private method to check, if the given option has been set.
__isMatchingDomain | Private method to check, if a given domain matches the given filter string.
__isMatchingRegExpStrings | Private method to check the given URL against the fixed parts of the regexp.
__parseDomains | Private method to parse a string with a domain list.
__parseFilter | Private method to parse the filter pattern.
__parseRegExpFilter | Private method to split the given regular expression into strings that can be used with 'in'.
__setException | Private method to set the given option as an exception.
__stringMatch | Private method to match a domain string.
addBlockedDomains | Public method to add to the list of blocked domains.
allowedDomains | Public method to get a copy of the list of allowed domains.
blockedDomains | Public method to get a copy of the list of blocked domains.
caseSensitivity | Public method to get the case sensitivity.
copyFrom | Public method to copy another AdBlock rule.
cssSelector | Public method to get the CSS selector of the rule.
filter | Public method to get the rule filter string.
getRegExpAndMatchers | Public method to get the regular expression and associated string matchers.
isCSSRule | Public method to check, if the rule is a CSS rule.
isComment | Public method to check, if this is a comment.
isDocument | Public method to check, if this is a document rule.
isDomainRestricted | Public method to check, if this rule is restricted by domain.
isElementHiding | Public method to check, if this is an element hiding rule.
isEnabled | Public method to check, if the rule is enabled.
isException | Public method to check, if the rule defines an exception.
isHeader | Public method to check, if this is a header.
isInternalDisabled | Public method to check, if this rule was disabled internally.
isSlow | Public method to check, if this is a slow rule.
matchDomain | Public method to match a domain.
matchFont | Public method to match a Font rule.
matchImage | Public method to match an Image rule.
matchMedia | Public method to match a Media rule.
matchObject | Public method to match an object rule.
matchObjectSubrequest | Public method to match an Object Subrequest rule.
matchOther | Public method to match any other rule.
matchPing | Public method to match a Ping rule.
matchScript | Public method to match a Script rule.
matchString | Public method to get the match string.
matchStyleSheet | Public method to match a StyleSheet rule.
matchSubdocument | Public method to match a sub-document rule.
matchThirdParty | Public method to match a third-party rule.
matchXmlHttpRequest | Public method to match a XmlHttpRequest rule.
networkMatch | Public method to check the rule for a match.
ruleExceptions | Public method to get the rule exceptions.
ruleOptions | Public method to get the rule options.
ruleType | Public method to get the rule type.
setEnabled | Public method to set the rule's enabled state.
setException | Public method to set the rule's exception flag.
setFilter | Public method to set the rule filter string.
setOption | Public method to set the given option.
setSubscription | Public method to set the subscription this rule belongs to.
subscription | Public method to get the subscription this rule belongs to.
urlMatch | Public method to check an URL against the rule.

### Static Methods

None

#### AdBlockRule (Constructor)

AdBlockRule(filterRule="", subscription=None)

Constructor

filterRule (str)
  filter string of the rule
subscription (AdBlockSubscription)
  reference to the subscription object

#### AdBlockRule.__convertPatternToRegExp

__convertPatternToRegExp(wildcardPattern)

Private method to convert a wildcard pattern to a regular expression.

wildcardPattern (str)
  string containing the wildcard pattern

Returns:
  string containing a regular expression

Return Type:
  string

#### AdBlockRule.__filterIsOnlyDomain

__filterIsOnlyDomain(filterString)

Private method to check, if the given filter is a domain only filter.

filterString (str)
  filter string to be checked

Returns:
  flag indicating a domain only filter

Return Type:
  bool

#### AdBlockRule.__filterIsOnlyEndsMatch

__filterIsOnlyEndsMatch(filterString)

Private method to check, if the given filter is to match against the end of a string.

filterString (str)
  filter string to be checked

Returns:
  flag indicating a end of string match filter

Return Type:
  bool

#### AdBlockRule.__hasException

__hasException(opt)

Private method to check, if the given option has been set as an exception.

opt (AdBlockRuleOption)
  option to check for

Returns:
  flag indicating the exception state of the option

Return Type:
  bool

#### AdBlockRule.__hasOption

__hasOption(opt)

Private method to check, if the given option has been set.

opt (AdBlockRuleOption)
  option to check for

Returns:
  flag indicating the state of the option

Return Type:
  bool

#### AdBlockRule.__isMatchingDomain

__isMatchingDomain(domain, filterString)

Private method to check, if a given domain matches the given filter string.

domain (str)
  domain to be checked
filterString (str)
  filter string to check against

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.__isMatchingRegExpStrings

__isMatchingRegExpStrings(url)

Private method to check the given URL against the fixed parts of the regexp.

url (str)
  URL to be checked

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.__parseDomains

__parseDomains(domains, separator)

Private method to parse a string with a domain list.

domains (str)
  list of domains
separator (str)
  separator character used by the list

#### AdBlockRule.__parseFilter

__parseFilter()

Private method to parse the filter pattern.

#### AdBlockRule.__parseRegExpFilter

__parseRegExpFilter(filterString)

Private method to split the given regular expression into strings that can be used with 'in'.

filterString (str)
  regexp filter string to be parsed

Returns:
  fixed string parts of the filter

Return Type:
  list of str

#### AdBlockRule.__setException

__setException(opt, on)

Private method to set the given option as an exception.

opt (AdBlockRuleOption)
  option to be set
on (bool)
  flag indicating to set or unset the exception

#### AdBlockRule.__stringMatch

__stringMatch(domain, encodedUrl)

Private method to match a domain string.

domain (str)
  domain to match
encodedUrl (str)
  URL in encoded form

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.addBlockedDomains

addBlockedDomains(domains)

Public method to add to the list of blocked domains.

domains (str or list of str)
  list of domains to be added

#### AdBlockRule.allowedDomains

allowedDomains()

Public method to get a copy of the list of allowed domains.

Returns:
  list of allowed domains

Return Type:
  list of str

#### AdBlockRule.blockedDomains

blockedDomains()

Public method to get a copy of the list of blocked domains.

Returns:
  list of blocked domains

Return Type:
  list of str

#### AdBlockRule.caseSensitivity

caseSensitivity()

Public method to get the case sensitivity.

Returns:
  case sensitivity

Return Type:
  Qt.CaseSensitivity

#### AdBlockRule.copyFrom

copyFrom(other)

Public method to copy another AdBlock rule.

other (AdBlockRule)
  reference to the AdBlock rule to copy from

#### AdBlockRule.cssSelector

cssSelector()

Public method to get the CSS selector of the rule.

Returns:
  CSS selector

Return Type:
  str

#### AdBlockRule.filter

filter()

Public method to get the rule filter string.

Returns:
  rule filter string

Return Type:
  str

#### AdBlockRule.getRegExpAndMatchers

getRegExpAndMatchers()

Public method to get the regular expression and associated string matchers.

Returns:
  tuple containing the regular expression and the list of string matchers

Return Type:
  tuple of (QRegExp, list of str)

#### AdBlockRule.isCSSRule

isCSSRule()

Public method to check, if the rule is a CSS rule.

Returns:
  flag indicating a CSS rule

Return Type:
  bool

#### AdBlockRule.isComment

isComment()

Public method to check, if this is a comment.

Returns:
  flag indicating a comment

Return Type:
  bool

#### AdBlockRule.isDocument

isDocument()

Public method to check, if this is a document rule.

Returns:
  flag indicating a document rule

Return Type:
  bool

#### AdBlockRule.isDomainRestricted

isDomainRestricted()

Public method to check, if this rule is restricted by domain.

Returns:
  flag indicating a domain restriction

Return Type:
  bool

#### AdBlockRule.isElementHiding

isElementHiding()

Public method to check, if this is an element hiding rule.

Returns:
  flag indicating an element hiding rule

Return Type:
  bool

#### AdBlockRule.isEnabled

isEnabled()

Public method to check, if the rule is enabled.

Returns:
  flag indicating enabled state

Return Type:
  bool

#### AdBlockRule.isException

isException()

Public method to check, if the rule defines an exception.

Returns:
  flag indicating an exception

Return Type:
  bool

#### AdBlockRule.isHeader

isHeader()

Public method to check, if this is a header.

Returns:
  flag indicating a header

Return Type:
  bool

#### AdBlockRule.isInternalDisabled

isInternalDisabled()

Public method to check, if this rule was disabled internally.

Returns:
  flag indicating an internally disabled rule

Return Type:
  bool

#### AdBlockRule.isSlow

isSlow()

Public method to check, if this is a slow rule.

Returns:
  flag indicating a slow rule

Return Type:
  bool

#### AdBlockRule.matchDomain

matchDomain(domain)

Public method to match a domain.

domain (str)
  domain name to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchFont

matchFont(req)

Public method to match a Font rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchImage

matchImage(req)

Public method to match an Image rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchMedia

matchMedia(req)

Public method to match a Media rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchObject

matchObject(req)

Public method to match an object rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchObjectSubrequest

matchObjectSubrequest(req)

Public method to match an Object Subrequest rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  boolean

#### AdBlockRule.matchOther

matchOther(req)

Public method to match any other rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchPing

matchPing(req)

Public method to match a Ping rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchScript

matchScript(req)

Public method to match a Script rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchString

matchString()

Public method to get the match string.

Returns:
  match string

Return Type:
  str

#### AdBlockRule.matchStyleSheet

matchStyleSheet(req)

Public method to match a StyleSheet rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.matchSubdocument

matchSubdocument(req)

Public method to match a sub-document rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  boolean

#### AdBlockRule.matchThirdParty

matchThirdParty(req)

Public method to match a third-party rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  boolean

#### AdBlockRule.matchXmlHttpRequest

matchXmlHttpRequest(req)

Public method to match a XmlHttpRequest rule.

req (QWebEngineUrlRequestInfo)
  request object to check

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.networkMatch

networkMatch(request, domain, encodedUrl)

Public method to check the rule for a match.

request (QWebEngineUrlRequestInfo)
  reference to the network request
domain (str)
  domain name
encodedUrl (str)
  string encoded URL to be checked

Returns:
  flag indicating a match

Return Type:
  bool

#### AdBlockRule.ruleExceptions

ruleExceptions()

Public method to get the rule exceptions.

Returns:
  rule exceptions

Return Type:
  AdBlockRuleOption

#### AdBlockRule.ruleOptions

ruleOptions()

Public method to get the rule options.

Returns:
  rule options

Return Type:
  AdBlockRuleOption

#### AdBlockRule.ruleType

ruleType()

Public method to get the rule type.

Returns:
  rule type

Return Type:
  AdBlockRuleType

#### AdBlockRule.setEnabled

setEnabled(enabled)

Public method to set the rule's enabled state.

enabled (bool)
  flag indicating the new enabled state

#### AdBlockRule.setException

setException(exception)

Public method to set the rule's exception flag.

exception (bool)
  flag indicating an exception rule

#### AdBlockRule.setFilter

setFilter(filterRule)

Public method to set the rule filter string.

filterRule (str)
  rule filter string

#### AdBlockRule.setOption

setOption(opt)

Public method to set the given option.

opt (AdBlockRuleOption)
  option to be set

#### AdBlockRule.setSubscription

setSubscription(subscription)

Public method to set the subscription this rule belongs to.

subscription (AdBlockSubscription)
  subscription of the rule

#### AdBlockRule.subscription

subscription()

Public method to get the subscription this rule belongs to.

Returns:
  subscription of the rule

Return Type:
  AdBlockSubscription

#### AdBlockRule.urlMatch

urlMatch(url)

Public method to check an URL against the rule.

url (QUrl)
  URL to check

Returns:
  flag indicating a match

Return Type:
  bool

Up

## AdBlockRuleOption

Class implementing the rule option enum.

### Derived from

IntEnum

### Class Attributes

DocumentOption
DomainRestrictedOption
ElementHideOption
FontOption
ImageOption
MediaOption
NoOption
ObjectOption
ObjectSubrequestOption
OtherOption
PingOption
ScriptOption
StyleSheetOption
SubdocumentOption
ThirdPartyOption
XMLHttpRequestOption

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## AdBlockRuleType

Class implementing the rule type enum.

### Derived from

IntEnum

### Class Attributes

CssRule
DomainMatchRule
Invalid
MatchAllUrlsRule
RegExpMatchRule
StringContainsMatchRule
StringEndsMatchRule

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## toSecondLevelDomain

toSecondLevelDomain(url)

Module function to get a second level domain from the given URL.

url (QUrl)
  URL to extract domain from

Returns:
  name of second level domain

Return Type:
  str

Up