Skip to content

Commit

Permalink
Fix TypeError when printing color codes to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawka committed Oct 9, 2019
1 parent d71df50 commit 29542f6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions safaribooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ def log(self, message):
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)
Expand Down Expand Up @@ -417,7 +423,7 @@ def requests_provider(

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:
Expand Down

0 comments on commit 29542f6

Please sign in to comment.