def _classify(self, package): identifier = ['x-umeng-sdk', 'x-vungle-bundle-id', 'x-requested-with'] for id in identifier: for head_seg in package.add_header.split('\n'): if id in head_seg and '.' in head_seg: label = head_seg.replace(id + ':', '').strip() return consts.Prediction(label, 1.0, id) return consts.NULLPrediction
def search(self, ws): rst = consts.NULLPrediction for i in range(len(ws)): n = self.root for j, w in enumerate(ws[i:]): if w in n.child: n = n.child[w] if n.score > rst[1]: rst = consts.Prediction(n.clss, n.score, ws[i:i + j + 1]) else: break return rst
def c(self, package): """ Return {type:[(label, confidence)]} :param package: """ labelRsts = {} for rule_type, rules in self.rules.iteritems(): rst = consts.NULLPrediction if package.rawHost in rules: if '' not in rules[package.rawHost]: for pathSegObj in rules[package.rawHost]: if pathSegObj.search(package.origPath): label = rules[package.rawHost][pathSegObj][0] rst = consts.Prediction( label, 1, ("Path", package.rawHost, pathSegObj.pattern)) else: if package.refer_rawHost == '': label = rules[package.rawHost][''][0] rst = consts.Prediction(label, 1.0, ('Host', package.rawHost)) labelRsts[rule_type] = rst return labelRsts