'Detects string encoding and make it unicode'

def make_unicode(self, string):

    utf8_detector = re.compile('^(?:\n                                                [\\x09\\x0A\\x0D\\x20-\\x7E]                                                #    ASCII\n                                        |    [\\xC2-\\xDF][\\x80-\\xBF]                                                    #    non-overlong    2-byte\n                                        |        \\xE0[\\xA0-\\xBF][\\x80-\\xBF]                                #    excluding    overlongs\n                                        |    [\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}        #    straight    3-byte\n                                        |        \\xED[\\x80-\\x9F][\\x80-\\xBF]                                #    excluding    surrogates\n                                        |        \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2}                    #    planes    1-3\n                                        |    [\\xF1-\\xF3][\\x80-\\xBF]{3}                                        #    planes    4-15\n                                        |        \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2}                    #    plane    16\n                                    )*$', re.X)
    cp1252_detector = re.compile('^(?:[\\x80-\\xBF])*$', re.X)
    xa4_detector = re.compile('^(?:\\xA4)*$', re.X)
    try:
        if re.match(utf8_detector, string):
            return unicode(string, 'utf_8')
        if re.match(cp1252_detector, string):
            if re.match(xa4_detector, string):
                return smart_unicode(string, 'iso8859_15')
            else:
                return smart_unicode(string, 'cp1252')
        return smart_unicode(string, 'koi8-r', errors='ignore')
    except:
        return smart_unicode(string, 'utf-8', errors='ignore')
