#NEWLINE# def unicodeToAscii( unicodeStr ) : #NEWLINE# #INDENT# '\n    Turns a unicode string to ascii code. When failing to do so for certain\n    characters, it replaces with a white space. This is particularly useful when\n    using simhash since it only works well for ascii code.\n    ' #NEWLINE# s = copy . copy ( unicodeStr ) #NEWLINE# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ret = codecs . encode ( s , 'ascii' ) #NEWLINE# return ret #NEWLINE# #UNINDENT# except UnicodeEncodeError as e : #NEWLINE# #INDENT# s = s . replace ( e . object [ e . start : e . end ] , ' ' ) #NEWLINE# #UNINDENT# #UNINDENT# return None