"""
import codecs
from m_lib.defenc import default_encoding
current_charset = default_encoding.replace("windows-", "cp")
"""
import codecs
from m_lib.defenc import default_encoding
current_charset = default_encoding.replace("windows-", "cp")
def recode_entities(title, charset):
output = []
for part in entity_re.split(title):
if entity_re.match(part):
def recode_entities(title, charset):
output = []
for part in entity_re.split(title):
if entity_re.match(part):
try:
part = unichr(int(part[2:-1])).encode(charset)
except UnicodeEncodeError:
pass # Leave the entity as is
try:
part = unichr(int(part[2:-1])).encode(charset)
except UnicodeEncodeError:
pass # Leave the entity as is
try:
if parser.meta_charset:
if log: log(" META charset : %s" % parser.charset)
else:
if log: log(" HTTP charset : %s" % parser.charset)
try:
if parser.meta_charset:
if log: log(" META charset : %s" % parser.charset)
else:
if log: log(" HTTP charset : %s" % parser.charset)
parser.charset = DEFAULT_CHARSET
if log: log(" incorrect conversion from cp1252, converting from %s" % DEFAULT_CHARSET)
parser.charset = DEFAULT_CHARSET
if log: log(" incorrect conversion from cp1252, converting from %s" % DEFAULT_CHARSET)
- converted_title = unicode(save_title, DEFAULT_CHARSET, "replace").encode(current_charset, "replace")
+ converted_title = unicode(save_title, DEFAULT_CHARSET, "replace").encode(universal_charset, "replace")
- converted_title = unicode(title, parser.charset, "replace").encode(current_charset, "replace")
+ converted_title = unicode(title, parser.charset, "replace").encode(universal_charset, "replace")
parts = [s.strip() for s in final_title.replace('\r', '').split('\n')]
final_title = ' '.join([s for s in parts if s])
if log and (final_title <> converted_title): log(" final title : %s" % final_title)
parts = [s.strip() for s in final_title.replace('\r', '').split('\n')]
final_title = ' '.join([s for s in parts if s])
if log and (final_title <> converted_title): log(" final title : %s" % final_title)