From 0048c43a9e50945f4da829b24b1acdef34083795 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 20 Jun 2019 22:43:33 -0400 Subject: [PATCH] py3: use unicode literals for casting strings Since unicode_type cannot be used in dynamically updated code, cast to the same type as type('') -- which we know will be unicode because of unicode_literals. --- src/calibre/ebooks/metadata/sources/amazon.py | 2 +- src/calibre/ebooks/metadata/sources/edelweiss.py | 4 ++-- src/calibre/ebooks/metadata/sources/google.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/amazon.py b/src/calibre/ebooks/metadata/sources/amazon.py index 8555a85a8e..33ab6d7060 100644 --- a/src/calibre/ebooks/metadata/sources/amazon.py +++ b/src/calibre/ebooks/metadata/sources/amazon.py @@ -351,7 +351,7 @@ class Worker(Thread): # Get details {{{ if self.testing: import tempfile import uuid - with tempfile.NamedTemporaryFile(prefix=(asin or str(uuid.uuid4())) + '_', + with tempfile.NamedTemporaryFile(prefix=(asin or type('')(uuid.uuid4())) + '_', suffix='.html', delete=False) as f: f.write(raw) print('Downloaded html for', asin, 'saved in', f.name) diff --git a/src/calibre/ebooks/metadata/sources/edelweiss.py b/src/calibre/ebooks/metadata/sources/edelweiss.py index b9575663bf..8909491132 100644 --- a/src/calibre/ebooks/metadata/sources/edelweiss.py +++ b/src/calibre/ebooks/metadata/sources/edelweiss.py @@ -139,7 +139,7 @@ def get_basic_data(browser, log, *skus): 'orderID': '0', 'mailingID': '', 'tContentWidth': '926', - 'originalOrder': ','.join(str(i) for i in range(len(skus))), + 'originalOrder': ','.join(type('')(i) for i in range(len(skus))), 'selectedOrderID': '0', 'selectedSortColumn': '0', 'listType': '1', @@ -255,7 +255,7 @@ class Edelweiss(Source): return None params = { 'q': (' '.join(keywords)).encode('utf-8'), - '_': str(int(time.time())) + '_': type('')(int(time.time())) } return BASE_URL+urlencode(params) diff --git a/src/calibre/ebooks/metadata/sources/google.py b/src/calibre/ebooks/metadata/sources/google.py index 66f5787799..0f7a42e71c 100644 --- a/src/calibre/ebooks/metadata/sources/google.py +++ b/src/calibre/ebooks/metadata/sources/google.py @@ -121,7 +121,7 @@ def to_metadata(browser, log, entry_, timeout): # {{{ # ISBN isbns = [] for x in identifier(extra): - t = str(x.text).strip() + t = type('')(x.text).strip() if t[:5].upper() in ('ISBN:', 'LCCN:', 'OCLC:'): if t[:5].upper() == 'ISBN:': t = check_isbn(t[5:])