More pylint fixes, added pylint to the build process.

This commit is contained in:
Michael Lazar
2015-12-05 01:51:05 -08:00
parent 83b5187317
commit 8fd8dc549e
11 changed files with 422 additions and 38 deletions

View File

@@ -76,7 +76,7 @@ class Content(object):
if isinstance(comment, praw.objects.MoreComments):
data['type'] = 'MoreComments'
data['count'] = comment.count
data['body'] = 'More comments'.format(comment.count)
data['body'] = 'More comments'
else:
author = getattr(comment, 'author', '[deleted]')
name = getattr(author, 'name', '[deleted]')
@@ -89,7 +89,7 @@ class Content(object):
data['type'] = 'Comment'
data['body'] = comment.body
data['created'] = cls.humanize_timestamp(comment.created_utc)
data['score'] = '{} pts'.format(comment.score)
data['score'] = '{0} pts'.format(comment.score)
data['author'] = name
data['is_author'] = (name == sub_name)
data['flair'] = flair
@@ -113,7 +113,7 @@ class Content(object):
"""
reddit_link = re.compile(
'https?://(www\.)?(np\.)?redd(it\.com|\.it)/r/.*')
r'https?://(www\.)?(np\.)?redd(it\.com|\.it)/r/.*')
author = getattr(sub, 'author', '[deleted]')
name = getattr(author, 'name', '[deleted]')
flair = getattr(sub, 'link_flair_text', '')
@@ -124,8 +124,8 @@ class Content(object):
data['title'] = sub.title
data['text'] = sub.selftext
data['created'] = cls.humanize_timestamp(sub.created_utc)
data['comments'] = '{} comments'.format(sub.num_comments)
data['score'] = '{} pts'.format(sub.score)
data['comments'] = '{0} comments'.format(sub.num_comments)
data['score'] = '{0} pts'.format(sub.score)
data['author'] = name
data['permalink'] = sub.permalink
data['subreddit'] = six.text_type(sub.subreddit)
@@ -137,17 +137,17 @@ class Content(object):
data['index'] = None # This is filled in later by the method caller
if data['flair'] and not data['flair'].startswith('['):
data['flair'] = u'[{}]'.format(data['flair'].strip())
data['flair'] = u'[{0}]'.format(data['flair'].strip())
url_full = data['url_full']
if data['permalink'].split('/r/')[-1] == url_full.split('/r/')[-1]:
data['url_type'] = 'selfpost'
data['url'] = 'self.{}'.format(data['subreddit'])
data['url'] = 'self.{0}'.format(data['subreddit'])
elif reddit_link.match(url_full):
data['url_type'] = 'x-post'
# Strip the subreddit name from the permalink to avoid having
# submission.subreddit.url make a separate API call
data['url'] = 'self.{}'.format(url_full.split('/')[4])
data['url'] = 'self.{0}'.format(url_full.split('/')[4])
else:
data['url_type'] = 'external'
data['url'] = url_full
@@ -298,7 +298,7 @@ class SubmissionContent(Content):
comment['cache'] = cache
comment['count'] = count
comment['level'] = data['level']
comment['body'] = 'Hidden'.format(count)
comment['body'] = 'Hidden'
self._comment_data[index:index + len(cache)] = [comment]
elif data['type'] == 'HiddenComment':
@@ -354,7 +354,7 @@ class SubredditContent(Content):
if '/' in name:
name, name_order = name.split('/')
order = order or name_order
display_name = '/r/{}'.format(name)
display_name = '/r/{0}'.format(name)
if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]:
raise exceptions.SubredditError('Unrecognized order "%s"' % order)

View File

@@ -4,8 +4,8 @@ from __future__ import unicode_literals
import time
import uuid
from tornado import gen, ioloop, web, httpserver
from concurrent.futures import ThreadPoolExecutor
from tornado import gen, ioloop, web, httpserver
class OAuthHandler(web.RequestHandler):

View File

@@ -46,11 +46,10 @@ class Page(object):
self._content_window = None
self._subwindows = None
def refresh_content(self, order=None):
def refresh_content(self, order=None, name=None):
raise NotImplementedError
@staticmethod
def _draw_item(window, data, inverted):
def _draw_item(self, window, data, inverted):
raise NotImplementedError
def loop(self):

View File

@@ -48,11 +48,11 @@ class SubmissionPage(Page):
self.active = False
@SubmissionController.register(curses.KEY_F5, 'r')
def refresh_content(self, order=None):
def refresh_content(self, order=None, name=None):
"Re-download comments and reset the page index"
order = order or self.content.order
url = self.content.name
url = name or self.content.name
with self.term.loader():
self.content = SubmissionContent.from_url(
@@ -124,18 +124,18 @@ class SubmissionPage(Page):
else:
self.term.flash()
def _draw_item(self, win, data, inverted=False):
def _draw_item(self, win, data, inverted):
if data['type'] == 'MoreComments':
return self._draw_more_comments(win, data)
elif data['type'] == 'HiddenComment':
return self._draw_more_comments(win, data)
elif data['type'] == 'Comment':
return self._draw_comment(win, data, inverted=inverted)
return self._draw_comment(win, data, inverted)
else:
return self._draw_submission(win, data)
def _draw_comment(self, win, data, inverted=False):
def _draw_comment(self, win, data, inverted):
n_rows, n_cols = win.getmaxyx()
n_cols -= 1
@@ -172,9 +172,9 @@ class SubmissionPage(Page):
attr = Color.get_level(data['level'])
x = 0
for y in range(n_rows):
self.term.addch(win, y, x, curses.ACS_VLINE, attr)
self.term.addch(win, y, x, self.term.vline, attr)
return attr | curses.ACS_VLINE
return attr | self.term.vline
def _draw_more_comments(self, win, data):
@@ -185,9 +185,9 @@ class SubmissionPage(Page):
self.term.add_line(win, ' [{count}]'.format(**data), attr=curses.A_BOLD)
attr = Color.get_level(data['level'])
self.term.addch(win, 0, 0, curses.ACS_VLINE, attr)
self.term.addch(win, 0, 0, self.term.vline, attr)
return attr | curses.ACS_VLINE
return attr | self.term.vline
def _draw_submission(self, win, data):

View File

@@ -32,11 +32,11 @@ class SubredditPage(Page):
self.nav = Navigator(self.content.get)
@SubredditController.register(curses.KEY_F5, 'r')
def refresh_content(self, name=None, order=None):
def refresh_content(self, order=None, name=None):
"Re-download all submissions and reset the page index"
name = name or self.content.name
order = order or self.content.order
name = name or self.content.name
# Hack to allow an order specified in the name by prompt_subreddit() to
# override the current default
@@ -71,7 +71,7 @@ class SubredditPage(Page):
name = self.term.prompt_input('Enter Subreddit: /r/')
if name is not None:
self.refresh_content(name=name, order='ignore')
self.refresh_content(order='ignore', name=name)
@SubredditController.register(curses.KEY_RIGHT, 'l')
def open_submission(self, url=None):
@@ -161,10 +161,10 @@ class SubredditPage(Page):
# When the user has chosen a subreddit in the subscriptions list,
# refresh content with the selected subreddit
if page.subreddit_data is not None:
self.refresh_content(name=page.subreddit_data['name'],
order='ignore')
self.refresh_content(order='ignore',
name=page.subreddit_data['name'])
def _draw_item(self, win, data, inverted=False):
def _draw_item(self, win, data, inverted):
n_rows, n_cols = win.getmaxyx()
n_cols -= 1 # Leave space for the cursor in the first column

View File

@@ -24,7 +24,7 @@ class SubscriptionPage(Page):
self.subreddit_data = None
@SubscriptionController.register(curses.KEY_F5, 'r')
def refresh_content(self, order=None):
def refresh_content(self, order=None, name=None):
"Re-download all subscriptions and reset the page index"
# reddit.get_my_subreddits() does not support sorting by order

View File

@@ -60,6 +60,10 @@ class Terminal(object):
attr = curses.A_BOLD | Color.YELLOW
return symbol, attr
@property
def vline(self):
return getattr(curses, 'ACS_VLINE', ord('|'))
@property
def display(self):
"""
@@ -229,7 +233,7 @@ class Terminal(object):
n_rows, n_cols = self.stdscr.getmaxyx()
box_width = max(map(len, message)) + 2
box_width = max(len(m) for m in message) + 2
box_height = len(message) + 2
# Cut off the lines of the message that don't fit on the screen
@@ -291,9 +295,9 @@ class Terminal(object):
if self.display:
command = "import webbrowser; webbrowser.open_new_tab('%s')" % url
args = [sys.executable, '-c', command]
null = open(os.devnull, 'ab+', 0)
p = subprocess.Popen(args, stdout=null, stderr=null)
with self.loader(message='Opening page in a new window'):
with self.loader(message='Opening page in a new window'), \
open(os.devnull, 'ab+', 0) as null:
p = subprocess.Popen(args, stdout=null, stderr=null)
# Give the browser 5 seconds to open a new tab. Because the
# display is set, calling webbrowser should be non-blocking.
# If it blocks or returns an error, something went wrong.