Skip to content

Commit

Permalink
Merge pull request #374 from michael-lazar/submission_refresh
Browse files Browse the repository at this point in the history
Fix submission refresh parameters.
  • Loading branch information
bboe committed Mar 26, 2015
2 parents 63ab66b + 637885b commit dd83c2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion praw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def get_rising(self, *args, **kwargs):
return self.get_content(self.config['rising'], *args, **kwargs)

def get_submission(self, url=None, submission_id=None, comment_limit=0,
comment_sort=None, params={}):
comment_sort=None, params=None):
"""Return a Submission object for the given url or submission_id.
:param comment_limit: The desired number of comments to fetch. If <= 0
Expand Down
12 changes: 10 additions & 2 deletions praw/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,11 @@ def refresh(self):
params={'uniq': randint(0, 65536)})
other = sub.comments[0]
elif isinstance(self, Submission):
params = self._params.copy()
params['uniq'] = randint(0, 65536)
other = Submission.from_url(self.reddit_session, self.permalink,
params={'uniq': randint(0, 65536)})
comment_sort=self._comment_sort,
params=params)
elif isinstance(self, Subreddit):
other = Subreddit(self.reddit_session, self.display_name)
self.__dict__ = other.__dict__ # pylint: disable-msg=W0201
Expand Down Expand Up @@ -922,7 +925,7 @@ def from_id(reddit_session, subreddit_id):
@staticmethod
@restrict_access(scope='read')
def from_url(reddit_session, url, comment_limit=0, comment_sort=None,
comments_only=False, params={}):
comments_only=False, params=None):
"""Request the url and return a Submission object.
:param reddit_session: The session to make the request with.
Expand All @@ -936,6 +939,9 @@ def from_url(reddit_session, url, comment_limit=0, comment_sort=None,
:param params: dictionary containing extra GET data to put in the url.
"""
if params is None:
params = {}

parsed = urlparse(url)
query_pairs = parse_qs(parsed.query)
get_params = dict((k, ",".join(v)) for k, v in query_pairs.items())
Expand All @@ -954,6 +960,7 @@ def from_url(reddit_session, url, comment_limit=0, comment_sort=None,
submission = s_info['data']['children'][0]
submission.comments = c_info['data']['children']
submission._comment_sort = comment_sort # pylint: disable-msg=W0212
submission._params = params # pylint: disable-msg=W0212
return submission

def __init__(self, reddit_session, json_dict):
Expand All @@ -966,6 +973,7 @@ def __init__(self, reddit_session, json_dict):
self._comments = None
self._orphaned = {}
self._replaced_more = False
self._params = {}

@limit_chars
def __unicode__(self):
Expand Down

0 comments on commit dd83c2f

Please sign in to comment.