GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#334)
by
unknown
37s
created

ConnectionThrottler.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
from datetime import datetime, timedelta
2
3
CONN_ATTEMPTS = 10
4
CONN_TIME = timedelta(minutes=1)
5
6
class ConnectionThrottler:
7
    """Simple Connection throttler to limit bruteforce attacks
8
9
    Records the number of connection attempts from remote hosts in a specified
10
    timespan, allowing to deny connections if there have been too many
11
    """
12
    def __init__(self):
13
        self.conn_attempts = {}
14
        self.ts = datetime.now()
15
16
    def attempt(self, ip):
17
        """Record a connection attempt
18
19
        Returns True if number of recorded attempts smaller than allowed number,
20
        False otherwise
21
        """
22
        # Check for time window rollover
23
        now = datetime.now()
24
        if now - self.ts > CONN_TIME:
25
            # Reset everything if we're rolled over
26
            self.conn_attempts = {}
27
            self.ts = now
28
29
        self.conn_attempts[ip] = self.conn_attempts.get(ip, 0) + 1
30
31
        return self.conn_attempts[ip] <= CONN_ATTEMPTS
32