Support legacy encodings better for synchronization

I have encountered another piece of code, which hangs the
sync process due to incompatibility with my legacy non-UTF8
locale. So I've added one more function to gpodder.util
which just cleans strings from possible further errors.
This commit is contained in:
Leonid Ponomarev 2008-08-03 22:41:19 +02:00 committed by Thomas Perl
parent c70be5e355
commit f6d8406a3d
2 changed files with 10 additions and 1 deletions

View File

@ -490,7 +490,7 @@ class MP3PlayerDevice(Device):
else:
folder = self.destination
from_file = episode.local_filename()
from_file = util.sanitize_encoding(episode.local_filename())
filename_base = util.sanitize_filename(episode.sync_filename(), self.MAX_FILENAME_LENGTH)
to_file = filename_base + os.path.splitext(from_file)[1].lower()

View File

@ -934,6 +934,15 @@ def open_website(url):
"""
threading.Thread(target=webbrowser.open, args=(url,)).start()
def sanitize_encoding(filename):
"""
Generate a sanitized version of a string (i.e.
remove invalid characters and encode in the
detected native language encoding)
"""
global encoding
return filename.encode(encoding, 'ignore')
def sanitize_filename(filename, max_length=0):
"""