Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix lint errors and restructure backports as compat.

  • Loading branch information...
commit 726442e70c0f80b1d85b165dfcecd55a5d178f4c 1 parent 40e56d3
@bboe bboe authored
View
22 .pylintrc
@@ -33,7 +33,7 @@ load-plugins=
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
-disable=C0111
+disable=C0111,I0011,W0142
[REPORTS]
@@ -43,7 +43,7 @@ disable=C0111
output-format=text
# Include message's id in output
-include-ids=no
+include-ids=yes
# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
@@ -211,35 +211,35 @@ int-import-graph=
[DESIGN]
# Maximum number of arguments for function / method
-max-args=5
+max-args=20
# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*
# Maximum number of locals for function / method body
-max-locals=15
+max-locals=25
# Maximum number of return / yield for function / method body
-max-returns=6
+# max-returns=0
# Maximum number of branch for function / method body
-max-branchs=12
+max-branchs=15
# Maximum number of statements in function / method body
-max-statements=50
+# max-statements=0
# Maximum number of parents for a class (see R0901).
-max-parents=7
+max-parents=10
# Maximum number of attributes for a class (see R0902).
-max-attributes=7
+max-attributes=20
# Minimum number of public methods for a class (see R0903).
-min-public-methods=2
+min-public-methods=1
# Maximum number of public methods for a class (see R0904).
-max-public-methods=20
+max-public-methods=30
[EXCEPTIONS]
View
1  lint.sh
@@ -15,6 +15,7 @@ output=$(pylint --rcfile=$dir/.pylintrc $dir/praw 2> /dev/null)
if [ -n "$output" ]; then
echo "--pylint--"
echo -e "$output"
+ exit 1
fi
echo "---pyflakes---"
View
20 praw/__init__.py
@@ -14,11 +14,6 @@
"""Reddit object."""
-from . import backport
-backport.add_moves()
-from six.moves import (HTTPCookieProcessor, HTTPError, build_opener,
- http_cookiejar, http_client, urljoin)
-
import json
import os
import platform
@@ -26,11 +21,11 @@
import sys
from warnings import warn, warn_explicit
-from . import decorators
-from . import errors
-from . import helpers
-from . import objects
-from .settings import CONFIG
+from praw import decorators, errors, helpers, objects
+from praw.compat import (HTTPCookieProcessor, # pylint: disable-msg=E0611
+ HTTPError, build_opener, http_cookiejar, http_client,
+ urljoin)
+from praw.settings import CONFIG
__version__ = '1.0.7'
UA_STRING = '%%s PRAW/%s Python/%s %s' % (__version__,
@@ -132,7 +127,7 @@ def __init__(self, site_name):
self._short_domain = None
self.timeout = float(obj['timeout'])
try:
- self.user = obj['user'] if obj['user'] or None
+ self.user = obj['user'] if obj['user'] else None
self.pswd = obj['pswd']
except KeyError:
self.user = self.pswd = None
@@ -522,7 +517,8 @@ def bool_str(item):
'public_description': public_description,
'description': description,
'prev_description_id': prev_description_id or '',
- 'prev_public_description_id': prev_public_description_id or '',
+ 'prev_public_description_id': (prev_public_description_id
+ or ''),
'lang': language,
'type': subreddit_type,
'link_type': content_options,
View
27 praw/backport.py
@@ -1,27 +0,0 @@
-# This file is part of PRAW.
-#
-# PRAW is free software: you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation, either version 3 of the License, or (at your option) any later
-# version.
-#
-# PRAW is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# PRAW. If not, see <http://www.gnu.org/licenses/>.
-
-from six import MovedAttribute, add_move
-
-
-def add_moves():
- add_move(MovedAttribute('HTTPError', 'urllib2', 'urllib.error'))
- add_move(MovedAttribute('HTTPCookieProcessor', 'urllib2',
- 'urllib.request'))
- add_move(MovedAttribute('Request', 'urllib2', 'urllib.request'))
- add_move(MovedAttribute('URLError', 'urllib2', 'urllib.error'))
- add_move(MovedAttribute('build_opener', 'urllib2', 'urllib.request'))
- add_move(MovedAttribute('quote', 'urllib2', 'urllib.parse'))
- add_move(MovedAttribute('urlencode', 'urllib', 'urllib.parse'))
- add_move(MovedAttribute('urljoin', 'urlparse', 'urllib.parse'))
View
50 praw/compat.py
@@ -0,0 +1,50 @@
+# This file is part of PRAW.
+#
+# PRAW is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# PRAW is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# PRAW. If not, see <http://www.gnu.org/licenses/>.
+import sys
+from six import MovedAttribute, add_move
+
+
+# Define additional moves for the six import
+add_move(MovedAttribute('HTTPError', 'urllib2', 'urllib.error'))
+add_move(MovedAttribute('HTTPCookieProcessor', 'urllib2', 'urllib.request'))
+add_move(MovedAttribute('Request', 'urllib2', 'urllib.request'))
+add_move(MovedAttribute('URLError', 'urllib2', 'urllib.error'))
+add_move(MovedAttribute('build_opener', 'urllib2', 'urllib.request'))
+add_move(MovedAttribute('quote', 'urllib2', 'urllib.parse'))
+add_move(MovedAttribute('urlencode', 'urllib', 'urllib.parse'))
+add_move(MovedAttribute('urljoin', 'urlparse', 'urllib.parse'))
+
+
+class CompatImporter(object):
+ @classmethod
+ def load_module(cls, fullname):
+ if fullname in sys.modules:
+ return sys.modules[fullname]
+ module = fullname.rsplit('.', 1)[1]
+ try:
+ package = __import__('six.moves', fromlist=[module])
+ mod = getattr(package, module)
+ return mod
+ except ImportError:
+ raise ImportError('No module named {0}'.format(fullname))
+
+ def find_module(self, fullname, path=None): # pylint: disable-msg=W0613
+ if fullname.startswith('praw.compat'):
+ return self
+ return None
+
+
+sys.meta_path.append(CompatImporter())
+sys.modules['praw.compat'].__path__ = []
+del CompatImporter
View
27 praw/decorators.py
@@ -20,17 +20,14 @@
length of output strings and parse json response for certain errors.
"""
-from . import backport # pylint: disable-msg=W0611
-backport.add_moves()
-
import six
import sys
import time
import warnings
from functools import wraps
-from six.moves import urljoin
-from . import errors
+from praw import errors
+from praw.compat import urljoin # pylint: disable-msg=E0611
class Memoize(object):
@@ -72,6 +69,16 @@ def evict(self, urls):
class RequireCaptcha(object):
"""Decorator for methods that require captchas."""
+
+ @staticmethod
+ def get_captcha(reddit_session, captcha_id):
+ url = urljoin(reddit_session.config['captcha'],
+ captcha_id + '.png')
+ sys.stdout.write('Captcha URL: %s\nCaptcha: ' % url)
+ sys.stdout.flush()
+ captcha = sys.stdin.readline().strip()
+ return {'iden': captcha_id, 'captcha': captcha}
+
def __init__(self, function):
wraps(function)(self)
self.function = function
@@ -97,14 +104,6 @@ def __call__(self, *args, **kwargs):
except errors.BadCaptcha as exception:
captcha_id = exception.response['captcha']
- def get_captcha(self, reddit_session, captcha_id):
- url = urljoin(reddit_session.config['captcha'],
- captcha_id + '.png')
- sys.stdout.write('Captcha URL: %s\nCaptcha: ' % url)
- sys.stdout.flush()
- captcha = sys.stdin.readline().strip()
- return {'iden': captcha_id, 'captcha': captcha}
-
class SleepAfter(object): # pylint: disable-msg=R0903
"""
@@ -205,6 +204,8 @@ def moderator_required_function(self, subreddit, *args, **kwargs):
if not self.user.is_mod:
raise errors.ModeratorRequired('%r is not moderator' %
six.text_type(self.user))
+
+ # pylint: disable-msg=W0212
if self.user._mod_subs is None:
self.user._mod_subs = {'mod': self.get_subreddit('mod')}
for sub in self.user.my_moderation(limit=None):
View
9 praw/helpers.py
@@ -14,13 +14,12 @@
"""Helper functions"""
-from . import backport
-backport.add_moves()
-
import sys
import six
-from six.moves import Request, quote, urlencode, urljoin
-from .decorators import Memoize, SleepAfter, require_login
+
+from praw.compat import (Request, quote, # pylint: disable-msg=E0611
+ urlencode, urljoin)
+from praw.decorators import Memoize, SleepAfter, require_login
def _get_section(subpath=''):
View
18 praw/objects.py
@@ -22,18 +22,15 @@
that it can be saved and unsaved in the context of a logged in user.
"""
-from . import backport
-backport.add_moves()
-
-
import six
import warnings
-from six.moves import urljoin
-from .decorators import limit_chars, require_login
-from .errors import ClientException
-from .helpers import (_get_section, _get_sorter, _modify_relationship,
- _request)
+from praw.compat import urljoin # pylint: disable-msg=E0611
+from praw.decorators import limit_chars, require_login
+from praw.errors import ClientException
+from praw.helpers import (_get_section, _get_sorter, _modify_relationship,
+ _request)
+
REDDITOR_KEYS = ('approved_by', 'author', 'banned_by', 'redditor')
@@ -587,7 +584,8 @@ def _replace_more_comments(self):
comment._replies = []
self._insert_comment(comment)
else:
- [queue.append((comm, x)) for x in comm.replies]
+ for item in comm.replies:
+ queue.append((comm, item))
if skipped:
warnings.warn_explicit('Skipped %d more comments objects on %r' %
View
6 praw/settings.py
@@ -12,12 +12,10 @@
# You should have received a copy of the GNU General Public License along with
# PRAW. If not, see <http://www.gnu.org/licenses/>.
-from . import backport # pylint: disable-msg=W0611
-backport.add_moves()
-
import os
import sys
-from six.moves import configparser
+
+from praw.compat import configparser # pylint: disable-msg=E0611
def _load_configuration():
View
9 praw/tests.py
@@ -19,18 +19,17 @@
"""Tests. Split into classes according to what they test."""
from __future__ import unicode_literals
-from . import backport
-backport.add_moves()
import random
import unittest
import uuid
import warnings
from six import advance_iterator as six_next, text_type
-from six.moves import HTTPError, URLError, urljoin
-from . import Reddit, errors, helpers
-from .objects import Comment, LoggedInRedditor, Message, MoreComments
+from praw import Reddit, errors, helpers
+from praw.compat import (HTTPError, URLError, # pylint: disable-msg=E0611
+ urljoin)
+from praw.objects import Comment, LoggedInRedditor, Message, MoreComments
USER_AGENT = 'PRAW_test_suite'
Please sign in to comment.
Something went wrong with that request. Please try again.