MCPcopy
hub / github.com/217heidai/adblockfilters / getRules

Method getRules

readme.py:28–41  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

26 ]
27
28 def getRules(self) -> List[Rule]:
29 logger.info("resolve readme...")
30 self.ruleList = []
31 with open(self.filename, "r") as f:
32 for line in f:
33 line = line.replace('\r', '').replace('\n', '')
34 if line.find('|')==0 and line.rfind('|')==len(line)-1:
35 rule = list(map(lambda x: x.strip(), line[1:-1].split('|')))
36 if rule[2].find('(') > 0 and rule[2].find(')') > 0 and rule[1].find('(') < 0:
37 url = rule[2][rule[2].find('(')+1:rule[2].find(')')]
38 matchObj1 = re.match(r'(http|https)://[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?', url)
39 if matchObj1:
40 self.ruleList.append(Rule(rule[0], rule[1], url, rule[-1]))
41 return self.ruleList
42
43 def getRulesNames(self) -> str:
44 names = ""

Callers 1

refreshMethod · 0.95

Calls 2

RuleClass · 0.85
matchMethod · 0.80

Tested by

no test coverage detected