From 9e43d7ed65bfb1bf255d145b5fbf4042c14735a7 Mon Sep 17 00:00:00 2001 From: John Helmert Date: Mon, 29 Jul 2019 18:34:18 -0500 Subject: [PATCH] Explicitly print format data as strings SubredditPage._draw_item_format now explicitly converts everything it prints to a string. This fixes crashing on Redditor pages when the Redditor object was split() before converting it to a string. Modified variable names to reflect different types. --- tuir/subreddit_page.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tuir/subreddit_page.py b/tuir/subreddit_page.py index 6c68987..9bb5f4c 100644 --- a/tuir/subreddit_page.py +++ b/tuir/subreddit_page.py @@ -411,7 +411,7 @@ class SubredditPage(Page): for get_data, get_attr, first in self.format: # add_line wants strings, make sure we give it strings if callable(get_data): - string = get_data(data) + print_data = get_data(data) else: # Start writing to the next line if we hit a newline if get_data == "\n": @@ -419,16 +419,18 @@ class SubredditPage(Page): continue # Otherwise, proceed on the same line - string = get_data + print_data = get_data # Don't try to write None strings to the screen. This happens in # places like user pages, where data['comments'] is None - if not string and first is False: + if not print_data and first is False: continue - # We only want to print a maximum of one line of data + # We only want to print a maximum of one line of data, + # and we want to cast to a string, since sometimes 'data' is not a + # string, but a Redditor object # TODO - support line wrapping - string = string.split('\n')[0] + string = str(print_data).split('\n')[0] if string == ' ': # Make sure spaces aren't treated like normal strings and print