Do a fuzzy match for `prop` in the dictionary, taking into account unit suffix.
439224
def parse_unit(prop, dictionary, dt=None):
    ''''''
    # add the observation's time
    try:
        dt = timezone.parse_datetime(dictionary.get('date_time'))
    except TypeError:
        dt = None

    # 'prop' is a stub of the property's attribute key, so search for matches
    matches = [k for k in dictionary.keys() if prop in k]

    try:
        value = dictionary[matches[0]]
        unit = re.search(r' \(([^)]+)\)', matches[0])

    except IndexError:
        # No matches: fail out
        return None

    # Sometimes we get a list of values (e.g. waves)
    if ';' in value:
        # Ignore empty values
        values = [val for val in value.split(';') if val != '']

        if unit:
            return [Observation(v, unit.group(1), dt) for v in values]
        else:
            return values

    # Sometimes there's no value! Sometimes there's no unit!
    if not value or not unit:
        return value or None

    return Observation(value, unit.group(1), dt)
1270410
def _parse_proplist(data):
    '''
    
    '''
    out = {}
    for line in data.split("\n"):
        line = re.split(r"\s+", line, 1)
        if len(line) == 2:
            out[line[0]] = line[1]

    return out
895623
def _matches_node_set_props(type_info, node_set_props):
    
    matches = None
    for key in node_set_props:
        ns_val = node_set_props[key]
        if key in type_info:
            if ns_val==type_info[key]:
                if matches:
                    matches = matches and True
                else:
                    matches = True
            else:
                matches = False
    return matches
649910
def _make_suffix(cov):
    """"""
    # Check if coverage object has data_suffix:
    if cov and cov.data_suffix is not None:
        # If True, the suffix will be autogenerated by coverage.py.
        # The suffixed data files will be automatically combined later.
        if cov.data_suffix is True:
            return True
        # Has a suffix, but we add our own extension
        return cov.data_suffix + '.nbval'
    return 'nbval'
1316342
def with_suffix(self, suffix):
        
        obj = super(ArtifactoryPath, self).with_suffix(suffix)
        obj.auth = self.auth
        obj.verify = self.verify
        obj.cert = self.cert
        obj.session = self.session
        return obj
885693
def match_mstring(self, tokens, item, use_bytes=None):
        """"""
        prefix, name, suffix = tokens
        if use_bytes is None:
            if prefix.startswith("b") or suffix.startswith("b"):
                if prefix.startswith("b") and suffix.startswith("b"):
                    use_bytes = True
                else:
                    raise CoconutDeferredSyntaxError("string literals and byte literals cannot be added in patterns", self.loc)
        if use_bytes:
            self.add_check("_coconut.isinstance(" + item + ", _coconut.bytes)")
        else:
            self.add_check("_coconut.isinstance(" + item + ", _coconut.str)")
        if prefix is not None:
            self.add_check(item + ".startswith(" + prefix + ")")
        if suffix is not None:
            self.add_check(item + ".endswith(" + suffix + ")")
        if name != wildcard:
            self.add_def(
                name + " = " + item + "[" +
                ("" if prefix is None else "_coconut.len(" + prefix + ")") + ":"
                + ("" if suffix is None else "-_coconut.len(" + suffix + ")") + "]",
            )
1293519
def process_prop(prop_type: PT, value, build_context):
    """"""
    if prop_type in (PT.Target, PT.TargetList):
        return hashify_targets(value, build_context)
    elif prop_type in (PT.File, PT.FileList):
        return hashify_files(value)
    return value
565088
def match_indices(match):
    """"""
    a, b, size = match
    for i in range(size):
        yield a + i, b + i
1082232
def with_suffix(self, suffix):
        """"""
        # XXX if suffix is None, should the current suffix be removed?
        drv, root, parts = self._flavour.parse_parts((suffix,))
        if drv or root or len(parts) != 1:
            raise ValueError("Invalid suffix %r" % (suffix))
        suffix = parts[0]
        if not suffix.startswith('.'):
            raise ValueError("Invalid suffix %r" % (suffix))
        name = self.name
        if not name:
            raise ValueError("%r has an empty name" % (self,))
        old_suffix = self.suffix
        if not old_suffix:
            name = name + suffix
        else:
            name = name[:-len(old_suffix)] + suffix
        return self._from_parsed_parts(self._drv, self._root,
                                       self._parts[:-1] + [name])
8544
def _compare_suffix(self, other):
        """"""

        # If suffix is omitted, assume a match
        if not self.suffix or not other.suffix:
            return True

        # Check if more than one unique suffix
        suffix_set = set(self.suffix_list + other.suffix_list)
        unique_suffixes = suffix_set & UNIQUE_SUFFIXES
        for key in EQUIVALENT_SUFFIXES:
            if key in unique_suffixes:
                unique_suffixes.remove(key)
                unique_suffixes.add(EQUIVALENT_SUFFIXES[key])

        return len(unique_suffixes) < 2
431316
def set_ytick_suffix(self, suffix):
        
        if suffix == 'degree':
            suffix = r'^\circ'
        elif suffix == 'percent':
            suffix = r'\%'

        self.ticks['ysuffix'] = suffix
1022991
function(key) {
    if (!key.match(suffixRegex)) {
      return key + '2';
    }

    return key.replace(suffixRegex, function(suffix) {
      return Number(suffix) + 1;
    });
  }
709943
def prefix(tokens, operator_table):
    """"""
    operator, matched_tokens = operator_table.prefix.match(tokens)
    if operator:
        return TokenMatch(operator, None, matched_tokens)
38298
def _get_fuzzy_tc_matches(text, full_text, options):
    '''
    
    '''
    print("text: {}, full: {}, options: {}".format(text, full_text, options))
    # get the options which match the full text
    matching_options = _get_fuzzy_matches(full_text, options)
    # need to only return the individual words which:
    # - match the 'text'
    # - are not exclusively matched by other input in full_text
    # - when matched, still allows all other input in full_text to be matched
    # get the input tokens
    input_tokens = full_text.split()
    # remove one instance of the text to be matched
    initial_tokens = input_tokens.remove(text)
    # track the final matches:
    final_matches = []
    # find matches per option
    for option in options:
        option_tokens = option.split()
        # get tokens which match the text
        matches = [t for t in option_tokens if text in t]
        # get input tokens which match one of the matches
        input_tokens_which_match = [t for t in input_tokens for m in matches if t in m]
        # if any input token ONLY matches a match, remove that match
        for token in input_tokens_which_match:
            token_matches = [t for t in option_tokens if token in t]
            if len(token_matches) == 1:
                match = token_matches[0]
                if match in matches:
                    matches.remove(match)
        # for the remaining matches, if the input tokens can be fuzzily matched without
        # the match, it's ok to return it.
        for match in matches:
            # copy option tokens
            option_tokens_minus_match = option_tokens[:]
            # remove the match
            option_tokens_minus_match.remove(match)
            option_minus_match = ' '.join(option_tokens_minus_match)
            if _get_fuzzy_matches(' '.join(input_tokens), [option_minus_match]):
                if match not in final_matches:
                    final_matches.append(match)
    return final_matches
751727
def dict_match(self, match_dict):
        '''
        
        '''
        ret = {}
        cur_keys = self.list_keys()
        for status, keys in six.iteritems(match_dict):
            for key in salt.utils.data.sorted_ignorecase(keys):
                for keydir in (self.ACC, self.PEND, self.REJ, self.DEN):
                    if keydir and fnmatch.filter(cur_keys.get(keydir, []), key):
                        ret.setdefault(keydir, []).append(key)
        return ret
1221190
def _fuzzily_matches(response, candidate):
    ''''''
    r_words = response.split()
    c_words = candidate.split()
    # match whole words first
    for word in r_words:
        if word in c_words:
            r_words.remove(word)
            c_words.remove(word)
    # match partial words, fewest matches first
    match_pairs = []
    for partial in sorted(r_words, key=lambda p: len(p), reverse=True):
        matches = [w for w in c_words if partial in w]
        match_pairs.append((partial, matches))
    # if all items can be uniquly matched, the match is passed
    while len(match_pairs):
        min_pair = min(match_pairs, key=lambda x:len(x[1]))
        # this is the partial and matches with the shortest match list
        # if there are ever no matches for something, the match is failed
        if len(min_pair[1]) == 0:
            return False
        # choose the match with the fewest matches to remaining partials.
        # that way we leave more options for more partials, for the best
        # chance of a full match
        partials_left = [p[0] for p in match_pairs]
        min_option = min(min_pair[1], key=lambda x:len([p for p in partials_left if x in p]))
        # remove the current pair - we've matched it now
        match_pairs.remove(min_pair)
        # remove the matched option from all pairs' options so it won't be matched again
        for pair in match_pairs:
            pair_options = pair[1]
            if min_option in pair_options:
                pair_options.remove(min_option)
    # if all the items in the response were matched, this is match
    return True
253350
def suffix(self):
        """"""
        name = self.name
        i = name.rfind('.')
        if 0 < i < len(name) - 1:
            return name[i:]
        else:
            return ''