Merge pull request #145 from Pawka/f-out

Fix TypeError when printing color codes to stdout
This commit is contained in:
Lorenzo Di Fuccia 2019-10-13 14:56:51 +02:00 • committed by GitHub
commit 86355e6f72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,7 +70,13 @@ class Display:
self.logger.info(str(message)) # TODO: "utf-8", "replace"
def out(self, put):
sys.stdout.write("\r" + " " * self.columns + "\r" + str(put, "utf-8", "replace") + "\n")
pattern = "\r{!s}\r{!s}\n"
try:
s = pattern.format(
" " * self.columns, str(put, "utf-8", "replace"))
except TypeError:
s = pattern.format(" " * self.columns, put)
sys.stdout.write(s)
def info(self, message, state=False):
self.log(message)
@ -417,7 +423,7 @@ class SafariBooks:
if update_referer:
# TODO Update Referer HTTP Header
# TODO How about Origin?
# TODO How about Origin?
self.HEADERS["referer"] = response.request.url
if response.is_redirect and perfom_redirect: