Passed
Push — master ( 93d9de...ed78e2 )
by Abouzar
02:31
created

api.decorators   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 170
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 136
dl 0
loc 170
rs 10
c 0
b 0
f 0
wmc 24

7 Functions

Rating   Name   Duplication   Size   Complexity  
A no_cache() 0 2 1
A hit_count() 0 16 2
B json() 0 20 6
A rate_limit() 0 24 4
B etag() 0 23 7
B paginate() 0 53 3
A cache_control() 0 12 1
1
import functools
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import hashlib
3
from flask import jsonify, request, url_for, current_app, make_response, g
4
from .rate_limit import RateLimit
5
from .errors import too_many_requests, precondition_failed, not_modified
6
7
8
def json(f):
0 ignored issues
show
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
9
  @functools.wraps(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
10
  def wrapped(*args, **kwargs):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
11
    rv = f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
    status_or_headers = None
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
13
    headers = None
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
14
    if isinstance(rv, tuple):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
15
      rv, status_or_headers, headers = rv + (None, ) * (3 - len(rv))
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
16
    if isinstance(status_or_headers, (dict, list)):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
17
      headers, status_or_headers = status_or_headers, None
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
18
    if not isinstance(rv, dict):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
19
      rv = rv.to_json()
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
20
    rv = jsonify(rv)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
21
    if status_or_headers is not None:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
22
      rv.status_code = status_or_headers
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
23
    if headers is not None:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
24
      rv.headers.extend(headers)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
25
    return rv
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
26
27
  return wrapped
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
28
29
30
def hit_count(f):
0 ignored issues
show
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
31
  @functools.wraps(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
32
  def wrapped(*args, **kwargs):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
33
    rv = f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
34
35
    if current_app.config['TESTING']:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
36
      from .rate_limit import FakeRedis
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
37
      redis = FakeRedis()
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
38
    else:  # pragma: no cover
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
39
      from redis import Redis
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
40
      redis = Redis()
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
41
42
    key = 'hit-count%s' % (request.path)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
43
    redis.incr(key)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
44
    return rv
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
45
  return wrapped
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
46
47
48
def rate_limit(limit, per, scope_func=lambda: request.remote_addr):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable request does not seem to be defined.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
49
  def decorator(f):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
50
    @functools.wraps(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
51
    def wrapped(*args, **kwargs):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
52
      if current_app.config['USE_RATE_LIMITS']:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
53
        key = 'rate-limit/%s/%s/' % (f.__name__, scope_func())
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
54
        limiter = RateLimit(key, limit, per)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
55
        if not limiter.over_limit:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
56
          rv = f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 20 spaces were expected, but 10 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
57
        else:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
58
          rv = too_many_requests('You have exceeded your request rate')
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 20 spaces were expected, but 10 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
59
        # rv = make_response(rv)
60
        g.headers = {
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
61
            'X-RateLimit-Remaining': str(limiter.remaining),
62
            'X-RateLimit-Limit': str(limiter.limit),
63
            'X-RateLimit-Reset': str(limiter.reset)
64
        }
65
        return rv
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
66
      else:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
67
        return f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
68
69
    return wrapped
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
70
71
  return decorator
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
72
73
74
def paginate(max_per_page=10):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
75
  def decorator(f):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
76
    @functools.wraps(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
77
    def wrapped(*args, **kwargs):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
78
      page = request.args.get('page', 1, type=int)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
79
      per_page = min(
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
80
          request.args.get('per_page', max_per_page, type=int), max_per_page)
81
      query = f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
82
      p = query.paginate(page, per_page)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
83
      pages = {
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
84
          'page': page,
85
          'per_page': per_page,
86
          'total': p.total,
87
          'pages': p.pages
88
      }
89
      if p.has_prev:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
90
        pages['prev'] = url_for(
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
91
            request.endpoint,
92
            page=p.prev_num,
93
            per_page=per_page,
94
            _external=True,
95
            **kwargs)
96
      else:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
97
        pages['prev'] = None
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
98
      if p.has_next:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
99
        pages['next'] = url_for(
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
100
            request.endpoint,
101
            page=p.next_num,
102
            per_page=per_page,
103
            _external=True,
104
            **kwargs)
105
      else:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
106
        pages['next'] = None
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
107
      pages['first'] = url_for(
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
108
          request.endpoint,
109
          page=1,
110
          per_page=per_page,
111
          _external=True,
112
          **kwargs)
113
      pages['last'] = url_for(
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
114
          request.endpoint,
115
          page=p.pages,
116
          per_page=per_page,
117
          _external=True,
118
          **kwargs)
119
      return jsonify({
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
120
          'urls': [item.get_url() for item in p.items],
121
          'meta': pages
122
      })
123
124
    return wrapped
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
125
126
  return decorator
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
127
128
129
def cache_control(*directives):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
130
  def decorator(f):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
131
    @functools.wraps(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
132
    def wrapped(*args, **kwargs):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
133
      rv = f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
134
      rv = make_response(rv)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
135
      rv.headers['Cache-Control'] = ', '.join(directives)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
136
      return rv
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
137
138
    return wrapped
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
139
140
  return decorator
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
141
142
143
def no_cache(f):
0 ignored issues
show
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
144
  return cache_control('no-cache', 'no-store', 'max-age=0')(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
145
146
147
def etag(f):
0 ignored issues
show
Coding Style Naming introduced by
The name f does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
148
  @functools.wraps(f)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
149
  def wrapped(*args, **kwargs):
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
150
    # only for HEAD and GET requests
151
    assert request.method in ['HEAD', 'GET'],\
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
152
        '@etag is only supported for GET requests'
153
    rv = f(*args, **kwargs)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
154
    rv = make_response(rv)
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
155
    etag = '"' + hashlib.md5(rv.get_data()).hexdigest() + '"'
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
Comprehensibility Bug introduced by
etag is re-defining a name which is already available in the outer-scope (previously defined on line 147).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
156
    rv.headers['ETag'] = etag
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
157
    if_match = request.headers.get('If-Match')
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
158
    if_none_match = request.headers.get('If-None-Match')
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
159
    if if_match:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
160
      etag_list = [tag.strip() for tag in if_match.split(',')]
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
161
      if etag not in etag_list and '*' not in etag_list:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
162
        rv = precondition_failed()
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
163
    elif if_none_match:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
164
      etag_list = [tag.strip() for tag in if_none_match.split(',')]
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
165
      if etag in etag_list or '*' in etag_list:
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 6 were found.
Loading history...
166
        rv = not_modified()
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 16 spaces were expected, but 8 were found.
Loading history...
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
167
    return rv
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
168
169
  return wrapped
1 ignored issue
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
170