return only legal chars
971373
def onlylegalchar(name):
    """"""
    legalchar = ascii_letters + digits + ' '
    return ''.join([s for s in name[:] if s in legalchar])
679048
def unicodestr(s, encoding='utf-8', fallback='iso-8859-1'):
    """"""

    if isinstance(s, unicode):
        return s

    try:
        return s.decode(encoding)
    except UnicodeError:
        return s.decode(fallback)
879423
def get_char_type(ch):
    
    if re.match(en_p, ch):
        return 1
    elif re.match("\d+", ch):
        return 2
    elif re.match(re_han, ch):
        return 3
    else:
        return 4
364762
function chars_to_bytes(ac) {
        var retval = []
        for (var i = 0; i < ac.length; i++) {
            retval = retval.concat(str_to_bytes(ac[i]))
        }
        return retval
    }
537887
def _raw(s):
    """"""

    if isinstance(s, list):
        s = "\n".join(_raw(item) for item in s)

    if s == EOF:
        return "EOF"

    s = repr(s)  # Get raw representation of string
    s = s[1:-1]  # Strip away quotation marks
    if len(s) > 15:
        s = s[:15] + "..."  # Truncate if too long
    return s
1337134
def charset(self) -> Optional[str]:
        """"""
        raw = self._headers.get(hdrs.CONTENT_TYPE)  # type: ignore
        if self._stored_content_type != raw:
            self._parse_content_type(raw)
        return self._content_dict.get('charset')
978118
def cleanString(someText):
    
    ret = ''
    if someText is not None:
        ret = filter(unicode.isalnum, someText.lower())
    return ret
923196
def char_groups(self, t, i):
        """"""

        current = []
        pos = i.index - 1
        found = False
        escaped = False
        first = None
        found_property = False
        self.found_property = False
        self.found_named_unicode = False

        try:
            while True:
                # Prevent POSIX/Unicode class from being part of a range.
                if self.found_property and t == '-':
                    current.append(_re.escape(t))
                    pos += 1
                    t = next(i)
                    self.found_property = False
                    continue
                else:
                    self.found_property = False

                if not escaped and t == "\\":
                    escaped = True
                elif escaped:
                    escaped = False
                    idx = len(current) - 1
                    current.extend(self.reference(t, i, True))
                    if self.found_property:
                        # Prevent Unicode class from being part of a range.
                        if idx >= 0 and current[idx] == '-':
                            current[idx] = _re.escape('-')
                        found_property = True
                elif t == "[" and not found:
                    found = True
                    first = pos
                    current.append(t)
                elif t == "[":
                    posix = self.get_posix(i)
                    if posix:
                        # Prevent POSIX class from being part of a range.
                        if current[-1] == '-':
                            current[-1] = _re.escape('-')
                        current.extend(self.posix_props(posix, in_group=True))
                        found_property = True
                        pos = i.index - 2
                    else:
                        current.append(t)
                elif t == "^" and found and (pos == first + 1):
                    first = pos
                    current.append(t)
                elif t == "]" and found and (pos != first + 1):
                    found = False
                    current.append(t)
                    break
                else:
                    current.append(t)
                pos += 1
                t = next(i)
        except StopIteration:
            pass

        if escaped:
            current.append(t)

        # Handle properties that return an empty string.
        # This will occur when a property's values exceed
        # either the Unicode char limit on a narrow system,
        # or the ASCII limit in a byte string pattern.
        if found_property or self.found_named_unicode:
            value = "".join(current)
            if value == '[]':
                # We specified some properties, but they are all
                # out of reach.  Therefore we can match nothing.
                current = ['[^%s]' % ('\x00-\xff' if self.is_bytes else _uniprops.UNICODE_RANGE)]
            elif value == '[^]':
                current = ['[%s]' % ('\x00-\xff' if self.is_bytes else _uniprops.UNICODE_RANGE)]
            else:
                current = [value]

        return current
527015
def read_character_string(self):
        """"""
        length = ord(self.data[self.offset])
        self.offset += 1
        return self.read_string(length)
151084
def lowercase_chars(string: any) -> str:
        """"""
        return ''.join([c if c.islower() else '' for c in str(string)])
1263938
def force_ascii_values(data):
    """"""
    return {
        k: v.encode('utf8').decode('ascii', 'backslashreplace')
        for k, v in data.items()
    }
305669
def has_mixed_eol_chars(text):
    """"""
    eol_chars = get_eol_chars(text)
    if eol_chars is None:
        return False
    correct_text = eol_chars.join((text+eol_chars).splitlines())
    return repr(correct_text) != repr(text)
808083
def convert_string(string, chars=None):
    """"""
    if chars is None:
        chars = [',', '.', '-', '/', ':', '  ']

    for ch in chars:
        if ch in string:
            string = string.replace(ch, ' ')
    return string
171330
def str_(name):
  """"""
  if isinstance(name, bytes) and not isinstance(name, str):
    return name.decode('utf8')
  else:
    return name
410259
def processQueryString(self, s):
    
    char_blacklist = set(string.punctuation)
    char_blacklist.remove("'")
    char_blacklist.remove("&")
    char_blacklist = frozenset(char_blacklist)
    return __class__.unpunctuate(s.lower(), char_blacklist=char_blacklist)
665909
def _escape_char(c):
    ""
    if isinstance(c, int):
        c = _unichr(c)
    return c if c in LEGAL_CHARS else ESCAPE_FMT % ord(c)
290238
def match_any_char(self, chars, offset=0):
        """"""
        if not self.has_space(offset=offset):
            return ''
        current = self.string[self.pos + offset]
        return current if current in chars else ''