From caf4b2350f4cb47eeca23dc574e24933f0a142b5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 11 Nov 2010 14:11:18 -0700 Subject: [PATCH] Sony driver: Ignore invalid strings when updating XML database --- src/calibre/devices/prs505/sony_cache.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index 17eea3a27c..c2899f54ee 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -619,6 +619,13 @@ class XMLCache(object): x.replace(u'\0', '') return x + def record_set(k, v): + try: + record.set(k, clean(v)) + except: + # v is not suitable for XML, ignore + pass + if not getattr(book, '_new_book', False): # book is not new if record.get('tz', None) is not None: use_tz_var = True @@ -641,20 +648,20 @@ class XMLCache(object): record.set('date', clean(date)) record.set('size', clean(str(os.stat(path).st_size))) title = book.title if book.title else _('Unknown') - record.set('title', clean(title)) + record_set('title', title) ts = book.title_sort if not ts: ts = title_sort(title) - record.set('titleSorter', clean(ts)) + record_set('titleSorter', ts) if self.use_author_sort: if book.author_sort: aus = book.author_sort else: debug_print('Author_sort is None for book', book.lpath) aus = authors_to_sort_string(book.authors) - record.set('author', clean(aus)) + record_set('author', aus) else: - record.set('author', clean(authors_to_string(book.authors))) + record_set('author', authors_to_string(book.authors)) ext = os.path.splitext(path)[1] if ext: ext = ext[1:].lower()