Match rule and set attribute codes.
557502
def match(self, filename, line, codes):
        """"""
        if self.regex_match_any(line, codes):
            if self._vary_codes:
                self.codes = tuple([codes[-1]])
            return True
951424
def _matches(o, pattern):
    """"""
    if not len(o) == len(pattern):
        return False
    comps = zip(o,pattern)
    return all(isinstance(obj,kind) for obj,kind in comps)
984461
def match(self, rdclass, rdtype, covers):
        """"""
        if self.rdclass == rdclass and \
           self.rdtype == rdtype and \
           self.covers == covers:
            return True
        return False
1020913
def handle_attribute_value(self, value):
        """"""
        if self.re_js.match(value) or self.re_vb.match(value):
            return ''
        return value
94383
def _set_rules(self, rules: dict, overwrite=True):
        """"""

        if not isinstance(rules, dict):
            raise TypeError('rules must be an instance of dict or Rules,'
                            'got %r instead' % type(rules))

        if overwrite:
            self.rules = Rules(rules, self.default_rule)
        else:
            self.rules.update(rules)
498319
def match(self, string):
        """"""
        if self.casesensitive:
            return fnmatch.fnmatch(string, self.pattern)
        else:
            return fnmatch.fnmatch(string.lower(), self.pattern.lower())
1367811
private List<Rule> match(final RuleSet ruleSet, final OgnlContext ognlContext) throws OgnlException
	{
		log.debug("Assessing input for ruleset : " + ruleSet.id);

		//run the input commands
		ruleSet.runInput(ognlContext);

		final List<Rule> ret = new ArrayList<>();

		//assess each rule against the input, return any that match
		for (Rule rule : ruleSet.rules)
		{
			Boolean bresult = rule.assessMatch(ognlContext);

			if (bresult)
			{
				log.debug(rule.condition.getOriginalExpression() + " matches");
				ret.add(rule);
			}
		}

		return ret;
	}
1270400
def _build_matches(matches, uuids, no_filtered, fastmode=False):
    """"""

    result = []

    for m in matches:
        mk = m[0].uuid if not fastmode else m[0]
        subset = [uuids[mk]]

        for id_ in m[1:]:
            uk = id_.uuid if not fastmode else id_
            u = uuids[uk]

            if u not in subset:
                subset.append(u)

        result.append(subset)

    result += no_filtered
    result.sort(key=len, reverse=True)

    sresult = []
    for r in result:
        r.sort(key=lambda id_: id_.uuid)
        sresult.append(r)

    return sresult
701671
function _match (rule, cmtData) {
        var path = rule.subject.split('.');
        var extracted = cmtData;
        while (path.length > 0) {
            var item = path.shift();
            if (item === '') {
                continue;
            }
            if (extracted.hasOwnProperty(item)) {
                extracted = extracted[item];
            }
            if (extracted === null || typeof extracted === 'undefined') {
                extracted = null;
                break;
            }
        }
        if (extracted === null) {
            // Null precondition implies anything
            return true;
        }
        switch (rule.op) {
            case '<':
                return extracted < rule.value;
            case '>':
                return extracted > rule.value;
            case '~':
            case 'regexp':
                return (new RegExp(rule.value)).test(extracted.toString());
            case '=':
            case 'eq':
                return rule.value ===
                    ((typeof extracted === 'number') ?
                        extracted : extracted.toString());
            case '!':
            case 'not':
                return !_match(rule.value, extracted);
            case '&&':
            case 'and':
                if (Array.isArray(rule.value)) {
                    return rule.value.every(function (r) {
                        return _match(r, extracted);
                    });
                } else {
                    return false;
                }
            case '||':
            case 'or':
                if (Array.isArray(rule.value)) {
                    return rule.value.some(function (r) {
                        return _match(r, extracted);
                    });
                } else {
                    return false;
                }
            default:
                return false;
        }
    }
1180955
def match_data(self, tokens, item):
        """"""
        if len(tokens) == 2:
            data_type, matches = tokens
            star_match = None
        elif len(tokens) == 3:
            data_type, matches, star_match = tokens
        else:
            raise CoconutInternalException("invalid data match tokens", tokens)
        self.add_check("_coconut.isinstance(" + item + ", " + data_type + ")")
        if star_match is None:
            self.add_check("_coconut.len(" + item + ") == " + str(len(matches)))
        elif len(matches):
            self.add_check("_coconut.len(" + item + ") >= " + str(len(matches)))
        self.match_all_in(matches, item)
        if star_match is not None:
            self.match(star_match, item + "[" + str(len(matches)) + ":]")
875580
private void addAttribute(Rule rule, String newAttribute, List<String> xmlLines) {
    List<Integer> linesToModify = new ArrayList<>();
    String currentRuleId = null;
    Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*");
    String expectedSubId = ((AbstractPatternRule) rule).getSubId();
    int lineCount = 0;
    int subRuleCount = 0;
    int modifyCount = 0;
    boolean inRuleGroup = false;
    for (String xmlLine : xmlLines) {
      if (xmlLine.contains("<rulegroup")) {
        subRuleCount = 0;
        inRuleGroup = true;
      } else if (xmlLine.contains("</rulegroup>")) {
        subRuleCount = 0;
        inRuleGroup = false;
      } else if ((xmlLine.contains("<rule ")||xmlLine.contains("<rule>")) && inRuleGroup) {
        subRuleCount++;
      }
      Matcher m = pattern.matcher(xmlLine);
      if (m.matches()) {
        currentRuleId = m.group(1);
      }
      if (xmlLine.contains("type=\"incorrect\"") || xmlLine.contains("type='incorrect'")) {
        if (currentRuleId != null && !currentRuleId.equals(rule.getId())) {
          lineCount++;
          continue;
        }
        if (!inRuleGroup) {
          subRuleCount = 1;
        }
        if (!expectedSubId.equals("0") && !expectedSubId.equals(String.valueOf(subRuleCount))) {
          lineCount++;
          continue;
        }
        linesToModify.add(lineCount);
        break;
      }
      lineCount++;
    }
    for (Integer s : linesToModify) {
      String newLine = xmlLines.get(s).replaceFirst("type=[\"']incorrect[\"']", newAttribute);
      xmlLines.set(s, newLine);
      addedCorrectionsCount++;
      modifyCount++;
    }
    if (modifyCount == 0) {
      System.err.println("No line modified: " + rule + "[" + expectedSubId + "]");
    }
  }
714969
protected static boolean locateMatchingAttributeValue(final String attrName, final String attrValue,
                                                          final Map<String, List<Object>> attributes) {
        return locateMatchingAttributeValue(attrName, attrValue, attributes, true);
    }
1116294
function parseAttributes(attrStr) {
    var reAttributes = /([^=<>\"\'\s]+)\s*(?:=\s*["']?([^"']*)["']?)?/g;
    var result = {};
    var match;

    if (attrStr) {
        while (match = reAttributes.exec(attrStr)) {
            result[match[1]] = match[2] || true;
        }
    }

    return result;
}
1290636
def match_files(self, matched, unmatched):
        """"""
        this_match = set(self.file_filter(unmatched))
        matched |= this_match
        unmatched -= this_match
902323
def set_attribute(self, code, value):
        """"""
        attr, _ = self.get_or_create(code=code)
        attr.value = value
        attr.save()
290728
def match_all_in(self, matches, item):
        """"""
        for i, match in enumerate(matches):
            self.match(match, item + "[" + str(i) + "]")
565602
def match_case_tokens(loc, tokens, check_var, top):
    """"""
    if len(tokens) == 2:
        matches, stmts = tokens
        cond = None
    elif len(tokens) == 3:
        matches, cond, stmts = tokens
    else:
        raise CoconutInternalException("invalid case match tokens", tokens)
    matching = Matcher(loc, check_var)
    matching.match(matches, match_to_var)
    if cond:
        matching.add_guard(cond)
    return matching.build(stmts, set_check_var=top)