Do magic matching of single words or quoted string
485966
def _string_to_dictsql(self, part):
        
        self._logger.debug("parsing string: " + unicode(part[0]) + " of type: " + part.getName())

        if part.getName() == 'tag':
            self._logger.debug("Query part '" + part[0] + "' interpreted as tag")
            dictsql = {
                    'interpretation': {
                        'string': part[0],
                        'interpretation': '(inherited) tag',
                        'attribute': 'tag',
                        'operator': 'equals_any',
                        'error': False
                    },
                    'operator': 'or',
                    'val1': {
                        'operator': 'equals_any',
                        'val1': 'tags',
                        'val2': part[0][1:]
                    },
                    'val2': {
                        'operator': 'equals_any',
                        'val1': 'inherited_tags',
                        'val2': part[0][1:]
                    }
            }

        elif part.getName() == 'vrf_rt':
            self._logger.debug("Query part '" + part.vrf_rt + "' interpreted as VRF RT")
            dictsql = {
                    'interpretation': {
                        'attribute': 'VRF RT',
                        'interpretation': 'vrf_rt',
                        'operator': 'equals',
                        'string': part.vrf_rt,
                        'error': False
                        },
                    'operator': 'equals',
                    'val1': 'vrf_rt',
                    'val2': part.vrf_rt
                    }

        elif part.getName() == 'ipv6_address':
            self._logger.debug("Query part '" + part.ipv6_address + "' interpreted as IPv6 address")
            dictsql = {
                'interpretation': {
                    'string': part.ipv6_address,
                    'interpretation': 'IPv6 address',
                    'attribute': 'prefix',
                    'operator': 'contains_equals',
                    'error': False
                },
                'operator': 'contains_equals',
                'val1': 'prefix',
                'val2': part.ipv6_address
            }

        elif part.getName() == 'ipv6_prefix':
            self._logger.debug("Query part '" + part.ipv6_prefix[0] + "' interpreted as IPv6 prefix")

            strict_prefix = unicode(IPy.IP(part.ipv6_prefix[0], make_net=True))
            interp = {
                    'string': part.ipv6_prefix[0],
                    'interpretation': 'IPv6 prefix',
                    'attribute': 'prefix',
                    'operator': 'contained_within_equals',
                    'error': False
                }
            if part.ipv6_prefix[0] != strict_prefix:
                interp['strict_prefix'] = strict_prefix

            dictsql = {
                'interpretation': interp,
                'operator': 'contained_within_equals',
                'val1': 'prefix',
                'val2': strict_prefix
            }

        else:
            # since it's difficult to parse shortened IPv4 addresses (like 10/8)
            # using pyparsing we do a bit of good ol parsing here

            if self._get_afi(part[0]) == 4 and len(part[0].split('/')) == 2:
                self._logger.debug("Query part '" + part[0] + "' interpreted as prefix")
                address, prefix_length = part[0].split('/')

                # complete a prefix to it's fully expanded form
                # 10/8 will be expanded into 10.0.0.0/8 which PostgreSQL can
                # parse correctly
                while len(address.split('.')) < 4:
                    address += '.0'

                prefix = address + '/' + prefix_length
                strict_prefix = unicode(IPy.IP(part[0], make_net=True))

                interp = {
                        'string': part[0],
                        'interpretation': 'IPv4 prefix',
                        'attribute': 'prefix',
                        'operator': 'contained_within_equals',
                        'error': False
                    }

                if prefix != part[0]:
                    interp['expanded'] = prefix

                if prefix != strict_prefix:
                    interp['strict_prefix'] = strict_prefix

                dictsql = {
                    'interpretation': interp,
                    'operator': 'contained_within_equals',
                    'val1': 'prefix',
                    'val2': strict_prefix
                }

            # IPv4 address
            # split on dot to make sure we have all four octets before we do a
            # search
            elif self._get_afi(part[0]) == 4 and len(part[0].split('.')) == 4:
                self._logger.debug("Query part '" + part[0] + "' interpreted as prefix")
                address = unicode(IPy.IP(part[0]))
                dictsql = {
                    'interpretation': {
                        'string': address,
                        'interpretation': 'IPv4 address',
                        'attribute': 'prefix',
                        'operator': 'contains_equals',
                        'error': False
                    },
                    'operator': 'contains_equals',
                    'val1': 'prefix',
                    'val2': address
                }

            else:
                # Description or comment
                self._logger.debug("Query part '" + part[0] + "' interpreted as text")
                dictsql = {
                        'interpretation': {
                            'string': part[0],
                            'interpretation': 'text',
                            'attribute': 'description or comment or node or order_id or customer_id',
                            'operator': 'regex',
                            'error': False
                        },
                        'operator': 'or',
                        'val1': {
                            'operator': 'or',
                            'val1': {
                                'operator': 'or',
                                'val1': {
                                    'operator': 'or',
                                    'val1': {
                                        'operator': 'regex_match',
                                        'val1': 'comment',
                                        'val2': part[0]
                                        },
                                    'val2': {
                                        'operator': 'regex_match',
                                        'val1': 'description',
                                        'val2': part[0]
                                        }
                                    },
                                'val2': {
                                    'operator': 'regex_match',
                                    'val1': 'node',
                                    'val2': part[0]
                                    }
                                },
                            'val2': {
                                'operator': 'regex_match',
                                'val1': 'order_id',
                                'val2': part[0]
                                },
                            },
                        'val2': {
                            'operator': 'regex_match',
                            'val1': 'customer_id',
                            'val2': part[0]
                            }
                        }

        return dictsql
46873
def match(self, context, line):
		""""""
		stripped = line.stripped
		return stripped.startswith('#') and not stripped.startswith('#{')
1217934
def correct_word(word_string):
    '''
    
    '''
    if word_string is None:
        return ""
    elif isinstance(word_string, str):
        return max(find_candidates(word_string), key=find_word_prob)
    else:
        raise InputError("string or none type variable not passed as argument to correct_word")
626682
def match_string(self, stype):
        """"""

        return not (stype - self.string_types) or bool(stype & self.wild_string_types)
907077
def quoted(text):
    
    if text and " " in text:
        sep = "'" if '"' in text else '"'
        return "%s%s%s" % (sep, text, sep)
    return text
1345458
def match_tokens(expected_tokens):
    """"""
    if isinstance(expected_tokens, Token):
        # Match a single token.
        def _grammar_func(tokens):
            try:
                next_token = next(iter(tokens))
            except StopIteration:
                return

            if next_token == expected_tokens:
                return TokenMatch(None, next_token.value, (next_token,))

    elif isinstance(expected_tokens, tuple):
        # Match multiple tokens.
        match_len = len(expected_tokens)
        def _grammar_func(tokens):
            upcoming = tuple(itertools.islice(tokens, match_len))
            if upcoming == expected_tokens:
                return TokenMatch(None, None, upcoming)
    else:
        raise TypeError(
            "'expected_tokens' must be an instance of Token or a tuple "
            "thereof. Got %r." % expected_tokens)

    return _grammar_func
938293
def get_quoted_strings(quoted_string):
    '''
    
    '''
    try:
        # This regex grabs all quoted data from string.
        # Note that this gets everything in between the first and last double quote.
        # This is intentional, as printed (and quoted) strings from a target file may contain
        # double quotes, and this function should ignore those. However, it also means that any
        # data between two quoted strings (ex: '"quote 1" non-quoted data
        # "quote 2"') will also be included.
        return re.findall(r'\"(.*)\"', quoted_string)[0]
    except KeyboardInterrupt as e:
        raise e
    except Exception:
        return ''
1073895
def find_matches(self, text):
        """"""
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if "." in text:
            return self.attr_matches(text)
        else:
            return self.global_matches(text)
574647
def match(self, s):
      
      self.matches = self.re.search(s)
      return self.matches
522008
def regex_matches_to_indexed_words(matches):
    
    words = [dict(v, **dict([('sentence', i)]))
             for i, s in enumerate(matches['sentences'])
             for k, v in s.items() if k != 'length']
    return words
1031156
def matches(text, what):
    '''
    
    
    '''
    return text.find(what) > -1 if is_string(what) else what.match(text)
493258
function _stringsByCharOrder(magicWord, givenMagicWord) {
  let charNumber = 0

  function _findMatchingCharacter(matchChar, string) {
    let found = false
    for (let j = charNumber; j < string.length; j++) {
      const stringChar = string[j]
      if (stringChar === matchChar) {
        found = true
        charNumber = j + 1
        break
      }
    }
    return found
  }

  for (let i = 0; i < givenMagicWord.length; i++) {
    const matchChar = givenMagicWord[i]
    const found = _findMatchingCharacter(matchChar, magicWord)
    if (!found) {
      return _matchRankMap.noMatch
    }
  }
  return _matchRankMap.matches
}
309692
def match(self, s=''):
        
        match = s.lower()
        res = {}
        for k in sorted(self):
            s = str(k) + '=\'' + str(self[k]) + '\''
            if match in s.lower():
                res[k] = self[k]
        return CMAOptions(res, unchecked=True)
460425
def _apply_single(self, string):
        
        if string is None:
            return None
        result = self.regex.sub("", string)
        result = self.SPACES_REGEX.sub(" ", result).strip()
        return result
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)) + ":]")
313100
function _stringsMatch(stringToMatch, givenString) {
  /* eslint complexity:[2, 8] */
  stringToMatch = ('' + stringToMatch).toLowerCase();

  // too long
  if (givenString.length > stringToMatch.length) {
    return _matchRankMap.noMatch;
  }

  // equals
  if (stringToMatch === givenString) {
    return _matchRankMap.equals;
  }

  // starts with
  if (stringToMatch.indexOf(givenString) === 0) {
    return _matchRankMap.startsWith;
  }

  // word starts with
  if (stringToMatch.indexOf(' ' + givenString) !== -1) {
    return _matchRankMap.wordStartsWith;
  }

  // contains
  if (stringToMatch.indexOf(givenString) !== -1) {
    return _matchRankMap.contains;
  } else if (givenString.length === 1) {
    // If the only character in the given magic word
    //   isn't even contained in the magic word, then
    //   it's definitely not a match.
    return _matchRankMap.noMatch;
  }

  // acronym
  if (_isAcronym(stringToMatch, givenString)) {
    return _matchRankMap.acronym;
  }

  return _stringsByCharOrder(stringToMatch, givenString);
}
152266
function matchAll(exp, text) {
    exp.lastIndex = 0;
    var matches = [];
    var match;
    while ((match = exp.exec(text)) != null) {
        matches.push(match[0]);
    }
    return matches;
}