Skip to content

Commit

Permalink
Merge code cleanup changes. Version bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Sep 23, 2012
2 parents 77e3fff + cb21c1a commit b9b795f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion deploy.sh
Expand Up @@ -12,7 +12,7 @@ if [[ "$status" != "nothing to commit (working directory clean)" ]]; then
exit 1
fi

version=$(python -c "import praw; print praw.__version__")
version=$(python -c "import praw; print(praw.__version__)")

read -p "Do you want to deploy $version? [y/n] " input
case $input in
Expand Down
22 changes: 8 additions & 14 deletions praw/__init__.py
Expand Up @@ -27,7 +27,7 @@
urljoin)
from praw.settings import CONFIG

__version__ = '1.0.7'
__version__ = '1.0.8'
UA_STRING = '%%s PRAW/%s Python/%s %s' % (__version__,
sys.version.split()[0],
platform.platform(True))
Expand Down Expand Up @@ -144,8 +144,8 @@ def short_domain(self):
"""
Return the short domain of the reddit.
Used to generate the shortlink. For reddit the short_domain is redd.it
and generate shortlinks like http://redd.it/y3r8u
Used to generate the shortlink. For reddit.com the short_domain is
redd.it and generate shortlinks like http://redd.it/y3r8u
"""
if self._short_domain:
return self._short_domain
Expand Down Expand Up @@ -399,16 +399,13 @@ def get_contributors(self, subreddit):
return self.request_json(self.config['contributors'] %
six.text_type(subreddit))

@decorators.require_login
@decorators.require_moderator
def get_flair(self, subreddit, redditor):
"""Gets the flair for a user on the given subreddit."""
url_data = {'name': six.text_type(redditor)}
data = self.request_json(self.config['flairlist'] %
six.text_type(subreddit), url_data=url_data)
return data['users'][0]

@decorators.require_login
def get_moderators(self, subreddit):
"""Get the list of moderators for the given subreddit."""
return self.request_json(self.config['moderators'] %
Expand Down Expand Up @@ -509,9 +506,6 @@ def set_settings(self, subreddit, title, public_description='',
prev_public_description_id=None, wikimode='disabled',
wiki_edit_age=30, wiki_edit_karma=100, **kwargs):
"""Set the settings for the given subreddit."""
def bool_str(item):
return 'on' if item else 'off'

params = {'r': six.text_type(subreddit),
'sr': subreddit.content_id,
'title': title,
Expand All @@ -520,12 +514,12 @@ def bool_str(item):
'lang': language,
'type': subreddit_type,
'link_type': content_options,
'over_18': bool_str(over_18),
'allow_top': bool_str(default_set),
'show_media': bool_str(show_media),
'over_18': 'on' if over_18 else 'off',
'allow_top': 'on' if default_set else 'off',
'show_media': 'on' if show_media else 'off',
'domain': domain or '',
'domain_css': bool_str(domain_css),
'domain_sidebar': bool_str(domain_sidebar),
'domain_css': 'on' if domain_css else 'off',
'domain_sidebar': 'on' if domain_sidebar else 'off',
'header-title': header_hover_text or '',
'wikimode': wikimode,
'wiki_edit_age': six.text_type(wiki_edit_age),
Expand Down
11 changes: 6 additions & 5 deletions praw/objects.py
Expand Up @@ -513,9 +513,9 @@ def get_info(reddit_session, url, comments_only=False):
comment_sort = reddit_session.config.comment_sort
if comment_limit:
if reddit_session.user and reddit_session.user.is_gold:
limit_max = 1500
limit_max = reddit_session.config.gold_comment_max
else:
limit_max = 500
limit_max = reddit_session.config.regular_comment_max
if comment_limit > limit_max:
warnings.warn_explicit('comment_limit %d is too high (max: %d)'
% (comment_limit, limit_max),
Expand Down Expand Up @@ -544,6 +544,7 @@ def __init__(self, reddit_session, json_dict):
self._comments_flat = None
self._orphaned = {}

@limit_chars()
def __unicode__(self):
title = self.title.replace('\r\n', ' ')
return six.text_type('{0} :: {1}').format(self.score, title)
Expand All @@ -558,7 +559,7 @@ def _insert_comment(self, comment):
comment.replies.extend(self._orphaned[comment.name])
del self._orphaned[comment.name]

if comment.parent_id == self.content_id: # Top-level comment
if comment.is_root:
self._comments.append(comment)
elif comment.parent_id in self._comments_by_id:
self._comments_by_id[comment.parent_id].replies.append(comment)
Expand Down Expand Up @@ -665,7 +666,7 @@ def comments(self): # pylint: disable-msg=E0202
instead. Use comment's replies to walk down the tree. To get
an unnested, flat list of comments use comments_flat.
"""
if self._comments == None:
if self._comments is None:
self.comments = Submission.get_info(self.reddit_session,
self.permalink,
comments_only=True)
Expand Down Expand Up @@ -708,7 +709,7 @@ def short_link(self):
Return a short link to the submission.
The short link points to a page on the short_domain that redirects to
the main. http://redd.it/y3r8u is a short link for reddit.
the main. http://redd.it/y3r8u is a short link for reddit.com.
"""
return urljoin(self.reddit_session.config.short_domain, self.id)

Expand Down
19 changes: 13 additions & 6 deletions praw/praw.ini
Expand Up @@ -6,11 +6,18 @@ api_request_delay: 2.0
# Time, a float, in seconds, to save the results of a get/post request.
cache_timeout: 30

# The number of comments (integer) to fetch along with submissions. The max for
# a regular or non-authenticated session is 500. The max for a user with gold
# is 1500. Runtime warnings will occur if the value is too large for the
# requesting user. Specifying a negative value means to use the maximum number
# for the user class. A zero value means use the reddit default.
# The maximum amount of comments (integer) that can be fetched with either
# a non-authenticated session or a regular account.
regular_comment_max: 500

# The maximum amount of comments (integer) that can be fetched with a gold
# account.
gold_comment_max: 1500

# The number of comments (integer) to fetch along with submissions. Runtime
# warnings will occur if the value is too large for the requesting user.
# Specifying a negative value means to use the maximum number for the user
# class. A zero value means use the reddit default.
comment_limit: 0

# The comment sort order to use when fetching submissions. Possible values are:
Expand Down Expand Up @@ -39,7 +46,7 @@ redditor_kind: t2
submission_kind: t3
subreddit_kind: t5

# log the API calls
# Log the API calls
# 0: no logging
# 1: log only the request URIs
# 2: log the request URIs as well as any POST data
Expand Down
4 changes: 2 additions & 2 deletions praw/tests.py
Expand Up @@ -173,7 +173,7 @@ def setUp(self):

def test_author_encoding(self):
# pylint: disable-msg=E1101
a1 = six_next(self.r.get_front_page()).author
a1 = six_next(self.r.get_new()).author
a2 = self.r.get_redditor(text_type(a1))
self.assertEqual(a1, a2)
s1 = six_next(a1.get_submitted())
Expand Down Expand Up @@ -810,7 +810,7 @@ def test_save(self):
self.fail('Could not find submission in saved links.')

def test_short_link(self):
submission = six_next(self.r.get_front_page())
submission = six_next(self.r.get_new())
if self.r.config.is_reddit:
self.assertTrue(submission.id in submission.short_link)
else:
Expand Down

0 comments on commit b9b795f

Please sign in to comment.