Skip to content

Commit

Permalink
Merge pull request #251 from alisaifee/linting-cleanup
Browse files Browse the repository at this point in the history
Linting cleanup
  • Loading branch information
alisaifee authored May 18, 2020
2 parents f6864c2 + 83b09dd commit fc3f127
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 210 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
pip install -r requirements/ci.txt
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10
6 changes: 6 additions & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PreCommit:
PythonFlake8RuboCop:
enabled: true
on_warn: fail
TrailingWhitespace:
enabled: true
10 changes: 5 additions & 5 deletions flask_limiter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Flask-Limiter extension for rate limiting
"""
"""Flask-Limiter extension for rate limiting."""
from ._version import get_versions
from .errors import RateLimitExceeded
from .extension import Limiter, HEADERS

__version__ = get_versions()['version']
del get_versions

from .errors import RateLimitExceeded
from .extension import Limiter, HEADERS
__all__ = ['RateLimitExceeded', 'Limiter', 'HEADERS']
8 changes: 3 additions & 5 deletions flask_limiter/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
errors and exceptions
"""
"""errors and exceptions."""

from distutils.version import LooseVersion
from pkg_resources import get_distribution
Expand All @@ -20,8 +18,8 @@


class RateLimitExceeded(werkzeug_exception):
"""
exception raised when a rate limit is hit.
"""exception raised when a rate limit is hit.
The exception results in ``abort(429)`` being called.
"""
code = 429
Expand Down
305 changes: 176 additions & 129 deletions flask_limiter/extension.py

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions flask_limiter/util.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
"""
"""
""""""

from flask import request


def get_ipaddr(): # pragma: no cover
def get_ipaddr(): # pragma: no cover
"""
:return: the ip address for the current request (or 127.0.0.1 if none found)
based on the X-Forwarded-For headers.
:return: the ip address for the current request
(or 127.0.0.1 if none found) based on the X-Forwarded-For headers.
.. deprecated:: 0.9.2
"""
"""
if request.access_route:
return request.access_route[0]
else:
Expand All @@ -20,6 +18,7 @@ def get_ipaddr(): # pragma: no cover

def get_remote_address():
"""
:return: the ip address for the current request (or 127.0.0.1 if none found)
:return: the ip address for the current request
(or 127.0.0.1 if none found)
"""
return request.remote_addr or '127.0.0.1'
12 changes: 8 additions & 4 deletions flask_limiter/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ def scope(self):
@property
def method_exempt(self):
"""Check if the limit is not applicable for this method"""
return self.methods is not None and request.method.lower() not in self.methods
return (
self.methods is not None
and request.method.lower() not in self.methods
)


class LimitGroup(object):
"""
represents a group of related limits either from a string or a callable that returns one
represents a group of related limits either from a string or a callable
that returns one
"""

def __init__(
Expand All @@ -65,6 +69,6 @@ def __iter__(self):
for limit in limit_items:
yield Limit(
limit, self.key_function, self.__scope, self.per_method,
self.methods, self.error_message, self.exempt_when, self.override_defaults,
self.deduct_when
self.methods, self.error_message, self.exempt_when,
self.override_defaults, self.deduct_when
)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ parentdir_prefix = flask-limiter-

[flake8]
exclude = build/**,doc/**,_version.py,version.py,versioneer.py
ignore = W503
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

from setuptools import setup, find_packages
import os
import versioneer

this_dir = os.path.abspath(os.path.dirname(__file__))
REQUIREMENTS = filter(None, open(
os.path.join(this_dir, 'requirements', 'main.txt')).read().splitlines())

import versioneer

setup(
name='Flask-Limiter',
Expand All @@ -31,4 +31,3 @@
long_description=open('README.rst').read() + open('HISTORY.rst').read(),
packages=find_packages(exclude=["tests*"]),
)

4 changes: 0 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def build_app(self, config={}, **limiter_args):
return app, limiter


def test_import():
import flask_limiter


def test_module_version():
import flask_limiter
assert flask_limiter.__version__ is not None
Expand Down
Loading

0 comments on commit fc3f127

Please sign in to comment.