def _get_map_string(map,
                    pattern,
                    wildcard_escape_char='\\',
                    unconditionally_case_insensitive=True):
    pattern_was_quoted = True
    if (not isinstance(pattern, str)):
        if (pattern.quote_token is None):
            pattern_was_quoted = False
        pattern = pattern.value
        if (not pattern_was_quoted): pattern = pattern.strip()
        if (unconditionally_case_insensitive): pattern = pattern.upper()
    result = []

    def match():
        for key, value in map.items():
            if (not pattern_was_quoted): key = key.strip()
            if (unconditionally_case_insensitive): key = key.upper()
            if (wildcard.is_match(string=key,
                                  pattern=pattern,
                                  escape_char=wildcard_escape_char)):
                result.append(value)

    match()
    if (len(result) == 0 and not pattern_was_quoted
            and not unconditionally_case_insensitive
            and _character_case_id(strings=[pattern]) != 0):
        keys_case_id = _character_case_id(strings=map.keys())
        if (keys_case_id != 0):
            if (keys_case_id > 0):
                pattern = pattern.upper()
            else:
                pattern = pattern.lower()
            match()
    return result
Пример #2
0
def _get_map_string(
      map,
      pattern,
      wildcard_escape_char='\\',
      unconditionally_case_insensitive=True):
  pattern_was_quoted = True
  if (not isinstance(pattern, str)):
    if (pattern.quote_token is None):
      pattern_was_quoted = False
    pattern = pattern.value
    if (not pattern_was_quoted): pattern = pattern.strip()
    if (unconditionally_case_insensitive): pattern = pattern.upper()
  result = []
  def match():
    for key,value in map.items():
      if (not pattern_was_quoted): key = key.strip()
      if (unconditionally_case_insensitive): key = key.upper()
      if (wildcard.is_match(
            string=key,
            pattern=pattern,
            escape_char=wildcard_escape_char)):
        result.append(value)
  match()
  if (    len(result) == 0
      and not pattern_was_quoted
      and not unconditionally_case_insensitive
      and _character_case_id(strings=[pattern]) != 0):
    keys_case_id = _character_case_id(strings=map.keys())
    if (keys_case_id != 0):
      if (keys_case_id > 0):
        pattern = pattern.upper()
      else:
        pattern = pattern.lower()
      match()
  return result