Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use raw strings for regexes in middleware.py #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions adminrestrict/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def valid_fqdn(dn):
dn = dn[:-1]
if len(dn) < 1 or len(dn) > 253:
return False
ldh_re = re.compile('^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$',
ldh_re = re.compile(r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
re.IGNORECASE)
return all(ldh_re.match(x) for x in dn.split('.'))

Expand Down Expand Up @@ -159,7 +159,7 @@ def request_ip_is_allowed(self, request):

# Check CIDR ranges if any first
if self.ipaddress_module_loaded:
for cidr_range in AllowedIP.objects.filter(ip_address__regex="\/\d+$"):
for cidr_range in AllowedIP.objects.filter(ip_address__regex=r"\/\d+$"):
try:
net = ipaddress.ip_network(cidr_range.ip_address)
ip = ipaddress.ip_address(str(request_ip))
Expand All @@ -175,7 +175,7 @@ def request_ip_is_allowed(self, request):
if re.match(regex_ip_range.ip_address.replace("*", ".*"), request_ip):
return True

for domain in AllowedIP.objects.filter(ip_address__regex="^[a-zA-Z]"):
for domain in AllowedIP.objects.filter(ip_address__regex=r"^[a-zA-Z]"):
if valid_fqdn(domain.ip_address) and \
request_ip == get_ip_address_for_fqdn(domain.ip_address):
return True
Expand Down