Returns the string without non ASCII characters
509912
def strip_non_ascii(string):
    ''' '''
    stripped = (c for c in string if 0 < ord(c) < 127)
    return ''.join(stripped)
170699
def chars(string: any) -> str:
        """"""
        return ''.join([c if c.isalpha() else '' for c in str(string)])
439527
def _needescape(c):
        

        return not ascii.isprint(c) or c == '"' or c == '\\' or ascii.isctrl(c)
1108928
def to_str(s):
    
    if bytes != str:
        """
        这里的比较在python2中是True，在Python3中是False
        """
        if type(s) == bytes:
            return s.decode('utf-8')
    return s
1263938
def force_ascii_values(data):
    """"""
    return {
        k: v.encode('utf8').decode('ascii', 'backslashreplace')
        for k, v in data.items()
    }
481135
def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
    
    if strings_only and isinstance(s, (types.NoneType, int)):
        return s
    # if isinstance(s, Promise):
    #     return unicode(s).encode(encoding, errors)
    if not isinstance(s, basestring):
        try:
            return str(s)
        except UnicodeEncodeError:
            if isinstance(s, Exception):
                # An Exception subclass containing non-ASCII data that doesn't
                # know how to print itself properly. We shouldn't raise a
                # further exception.
                return ' '.join([smart_str(arg, encoding, strings_only,
                        errors) for arg in s])
            return unicode(s).encode(encoding, errors)
    elif isinstance(s, unicode):
        return s.encode(encoding, errors)
    elif s and encoding != 'utf-8':
        return s.decode('utf-8', errors).encode(encoding, errors)
    else:
        return s
826015
def toStr (self, separator = ':'):
        
        return separator.join(('{:02x}'.format(x) for x in self.__value))
444650
def to_string(x):
    
    if isinstance(x, bytes):
        return x.decode('utf-8')
    if isinstance(x, basestring):
        return x
153611
def _recv_string(self,value):
        

        s = value.decode('ascii')

        # Strip null characters
        s = s.strip("\x00")

        # Strip other white space
        s = s.strip()

        return s
429796
function (string) {
			var ascii = "";

			for (var i = 0; i < string.length; i++) {
				ascii += string.charCodeAt(i) + ",";
			}

			// remove last ","
			ascii = ascii.substring(0, ascii.length - 1);

			return ascii;
		}
641975
def as_string(self, forsigning=False):
		
		ret = OutBuffer()
		self.serialize(ret, forsigning)
		return ret.getvalue()
348982
def u2b(string):
    
    if ((PY2 and isinstance(string, unicode)) or
        ((not PY2) and isinstance(string, str))):
        return string.encode('utf-8')
    return string
171330
def str_(name):
  """"""
  if isinstance(name, bytes) and not isinstance(name, str):
    return name.decode('utf8')
  else:
    return name
4178
def tostr(s, encoding='ascii'):
    
    if PY3K:
        if isinstance(s, str): # str == unicode in PY3K
            return s
        else: # s is type bytes
            return s.decode(encoding)
    else:
        # for py2.6 on (before 3.0), bytes is same as str;  2.5 has no bytes
        # but handle if unicode is passed
        if isinstance(s, unicode):
            return s.encode(encoding)
        else:
            return s
584712
def convert_to_ascii(statement):
    
    import unicodedata

    text = unicodedata.normalize('NFKD', statement.text)
    text = text.encode('ascii', 'ignore').decode('utf-8')

    statement.text = str(text)
    return statement
1148052
def strip_accents(s, encoding= 'utf-8'):
    """"""
    if sys.version < '3':
        if isinstance(s,unicode):
           return unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore')
        else:
           return unicodedata.normalize('NFKD', unicode(s,encoding)).encode('ASCII', 'ignore')
    else:
        if isinstance(s,bytes): s = str(s,encoding)
        return str(unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore'),'ascii')
1259522
def to_str(s):
    
    if isinstance(s, bytes):
        s = s.decode('utf-8')
    elif not isinstance(s, str):
        s = str(s)
    return s