mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
Fix pycodestyle errors
Mainly two kind of errors: * pokemon exceptions * invalid escape sequences
This commit is contained in:
parent
6dde0f030a
commit
4e09b32dd9
@ -34,7 +34,7 @@ from .models import (
|
|||||||
RackRole, Region, Site, VirtualChassis
|
RackRole, Region, Site, VirtualChassis
|
||||||
)
|
)
|
||||||
|
|
||||||
DEVICE_BY_PK_RE = '{\d+\}'
|
DEVICE_BY_PK_RE = r'{\d+\}'
|
||||||
|
|
||||||
INTERFACE_MODE_HELP_TEXT = """
|
INTERFACE_MODE_HELP_TEXT = """
|
||||||
Access: One untagged VLAN<br />
|
Access: One untagged VLAN<br />
|
||||||
|
@ -1205,8 +1205,8 @@ class ConsoleServerPortManager(models.Manager):
|
|||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
# Pad any trailing digits to effect natural sorting
|
# Pad any trailing digits to effect natural sorting
|
||||||
return super(ConsoleServerPortManager, self).get_queryset().extra(select={
|
return super(ConsoleServerPortManager, self).get_queryset().extra(select={
|
||||||
'name_padded': "CONCAT(REGEXP_REPLACE(dcim_consoleserverport.name, '\d+$', ''), "
|
'name_padded': r"CONCAT(REGEXP_REPLACE(dcim_consoleserverport.name, '\d+$', ''), "
|
||||||
"LPAD(SUBSTRING(dcim_consoleserverport.name FROM '\d+$'), 8, '0'))",
|
r"LPAD(SUBSTRING(dcim_consoleserverport.name FROM '\d+$'), 8, '0'))",
|
||||||
}).order_by('device', 'name_padded')
|
}).order_by('device', 'name_padded')
|
||||||
|
|
||||||
|
|
||||||
@ -1287,8 +1287,8 @@ class PowerOutletManager(models.Manager):
|
|||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
# Pad any trailing digits to effect natural sorting
|
# Pad any trailing digits to effect natural sorting
|
||||||
return super(PowerOutletManager, self).get_queryset().extra(select={
|
return super(PowerOutletManager, self).get_queryset().extra(select={
|
||||||
'name_padded': "CONCAT(REGEXP_REPLACE(dcim_poweroutlet.name, '\d+$', ''), "
|
'name_padded': r"CONCAT(REGEXP_REPLACE(dcim_poweroutlet.name, '\d+$', ''), "
|
||||||
"LPAD(SUBSTRING(dcim_poweroutlet.name FROM '\d+$'), 8, '0'))",
|
r"LPAD(SUBSTRING(dcim_poweroutlet.name FROM '\d+$'), 8, '0'))",
|
||||||
}).order_by('device', 'name_padded')
|
}).order_by('device', 'name_padded')
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class TopologyMapViewSet(ModelViewSet):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = tmap.render(img_format=img_format)
|
data = tmap.render(img_format=img_format)
|
||||||
except:
|
except Exception:
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
"There was an error generating the requested graph. Ensure that the GraphViz executables have been "
|
"There was an error generating the requested graph. Ensure that the GraphViz executables have been "
|
||||||
"installed correctly."
|
"installed correctly."
|
||||||
|
@ -19,7 +19,7 @@ def verify_postgresql_version(apps, schema_editor):
|
|||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute("SELECT VERSION()")
|
cursor.execute("SELECT VERSION()")
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
pg_version = re.match('^PostgreSQL (\d+\.\d+(\.\d+)?)', row[0]).group(1)
|
pg_version = re.match(r'^PostgreSQL (\d+\.\d+(\.\d+)?)', row[0]).group(1)
|
||||||
if StrictVersion(pg_version) < StrictVersion('9.4.0'):
|
if StrictVersion(pg_version) < StrictVersion('9.4.0'):
|
||||||
raise Exception("PostgreSQL 9.4.0 or higher is required ({} found). Upgrade PostgreSQL and then run migrations again.".format(pg_version))
|
raise Exception("PostgreSQL 9.4.0 or higher is required ({} found). Upgrade PostgreSQL and then run migrations again.".format(pg_version))
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ class IOSSSH(SSHClient):
|
|||||||
|
|
||||||
sh_ver = self._send('show version').split('\r\n')
|
sh_ver = self._send('show version').split('\r\n')
|
||||||
return {
|
return {
|
||||||
'serial': parse(sh_ver, 'Processor board ID ([^\s]+)'),
|
'serial': parse(sh_ver, r'Processor board ID ([^\s]+)'),
|
||||||
'description': parse(sh_ver, 'cisco ([^\s]+)')
|
'description': parse(sh_ver, r'cisco ([^\s]+)')
|
||||||
}
|
}
|
||||||
|
|
||||||
def items(chassis_serial=None):
|
def items(chassis_serial=None):
|
||||||
@ -172,9 +172,9 @@ class IOSSSH(SSHClient):
|
|||||||
for i in cmd:
|
for i in cmd:
|
||||||
i_fmt = i.replace('\r\n', ' ')
|
i_fmt = i.replace('\r\n', ' ')
|
||||||
try:
|
try:
|
||||||
m_name = re.search('NAME: "([^"]+)"', i_fmt).group(1)
|
m_name = re.search(r'NAME: "([^"]+)"', i_fmt).group(1)
|
||||||
m_pid = re.search('PID: ([^\s]+)', i_fmt).group(1)
|
m_pid = re.search(r'PID: ([^\s]+)', i_fmt).group(1)
|
||||||
m_serial = re.search('SN: ([^\s]+)', i_fmt).group(1)
|
m_serial = re.search(r'SN: ([^\s]+)', i_fmt).group(1)
|
||||||
# Omit built-in items and those with no PID
|
# Omit built-in items and those with no PID
|
||||||
if m_serial != chassis_serial and m_pid.lower() != 'unspecified':
|
if m_serial != chassis_serial and m_pid.lower() != 'unspecified':
|
||||||
yield {
|
yield {
|
||||||
@ -208,7 +208,7 @@ class OpengearSSH(SSHClient):
|
|||||||
try:
|
try:
|
||||||
stdin, stdout, stderr = self.ssh.exec_command("showserial")
|
stdin, stdout, stderr = self.ssh.exec_command("showserial")
|
||||||
serial = stdout.readlines()[0].strip()
|
serial = stdout.readlines()[0].strip()
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError("Failed to glean chassis serial from device.")
|
raise RuntimeError("Failed to glean chassis serial from device.")
|
||||||
# Older models don't provide serial info
|
# Older models don't provide serial info
|
||||||
if serial == "No serial number information available":
|
if serial == "No serial number information available":
|
||||||
@ -217,7 +217,7 @@ class OpengearSSH(SSHClient):
|
|||||||
try:
|
try:
|
||||||
stdin, stdout, stderr = self.ssh.exec_command("config -g config.system.model")
|
stdin, stdout, stderr = self.ssh.exec_command("config -g config.system.model")
|
||||||
description = stdout.readlines()[0].split(' ', 1)[1].strip()
|
description = stdout.readlines()[0].split(' ', 1)[1].strip()
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError("Failed to glean chassis description from device.")
|
raise RuntimeError("Failed to glean chassis description from device.")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -281,5 +281,5 @@ INTERNAL_IPS = (
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
HOSTNAME = socket.gethostname()
|
HOSTNAME = socket.gethostname()
|
||||||
except:
|
except Exception:
|
||||||
HOSTNAME = 'localhost'
|
HOSTNAME = 'localhost'
|
||||||
|
@ -26,7 +26,7 @@ def validate_rsa_key(key, is_secret=True):
|
|||||||
raise forms.ValidationError("This looks like a private key. Please provide your public RSA key.")
|
raise forms.ValidationError("This looks like a private key. Please provide your public RSA key.")
|
||||||
try:
|
try:
|
||||||
PKCS1_OAEP.new(key)
|
PKCS1_OAEP.new(key)
|
||||||
except:
|
except Exception:
|
||||||
raise forms.ValidationError("Error validating RSA key. Please ensure that your key supports PKCS#1 OAEP.")
|
raise forms.ValidationError("Error validating RSA key. Please ensure that your key supports PKCS#1 OAEP.")
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class UserKey(CreatedUpdatedModel):
|
|||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'public_key': "Invalid RSA key format."
|
'public_key': "Invalid RSA key format."
|
||||||
})
|
})
|
||||||
except:
|
except Exception:
|
||||||
raise ValidationError("Something went wrong while trying to save your key. Please ensure that you're "
|
raise ValidationError("Something went wrong while trying to save your key. Please ensure that you're "
|
||||||
"uploading a valid RSA public key in PEM format (no SSH/PGP).")
|
"uploading a valid RSA public key in PEM format (no SSH/PGP).")
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ COLOR_CHOICES = (
|
|||||||
('607d8b', 'Dark grey'),
|
('607d8b', 'Dark grey'),
|
||||||
('111111', 'Black'),
|
('111111', 'Black'),
|
||||||
)
|
)
|
||||||
NUMERIC_EXPANSION_PATTERN = '\[((?:\d+[?:,-])+\d+)\]'
|
NUMERIC_EXPANSION_PATTERN = r'\[((?:\d+[?:,-])+\d+)\]'
|
||||||
ALPHANUMERIC_EXPANSION_PATTERN = '\[((?:[a-zA-Z0-9]+[?:,-])+[a-zA-Z0-9]+)\]'
|
ALPHANUMERIC_EXPANSION_PATTERN = r'\[((?:[a-zA-Z0-9]+[?:,-])+[a-zA-Z0-9]+)\]'
|
||||||
IP4_EXPANSION_PATTERN = '\[((?:[0-9]{1,3}[?:,-])+[0-9]{1,3})\]'
|
IP4_EXPANSION_PATTERN = r'\[((?:[0-9]{1,3}[?:,-])+[0-9]{1,3})\]'
|
||||||
IP6_EXPANSION_PATTERN = '\[((?:[0-9a-f]{1,4}[?:,-])+[0-9a-f]{1,4})\]'
|
IP6_EXPANSION_PATTERN = r'\[((?:[0-9a-f]{1,4}[?:,-])+[0-9a-f]{1,4})\]'
|
||||||
|
|
||||||
|
|
||||||
def parse_numeric_range(string, base=10):
|
def parse_numeric_range(string, base=10):
|
||||||
@ -407,7 +407,7 @@ class FlexibleModelChoiceField(forms.ModelChoiceField):
|
|||||||
try:
|
try:
|
||||||
if not self.to_field_name:
|
if not self.to_field_name:
|
||||||
key = 'pk'
|
key = 'pk'
|
||||||
elif re.match('^\{\d+\}$', value):
|
elif re.match(r'^\{\d+\}$', value):
|
||||||
key = 'pk'
|
key = 'pk'
|
||||||
value = value.strip('{}')
|
value = value.strip('{}')
|
||||||
else:
|
else:
|
||||||
|
@ -23,9 +23,9 @@ class NaturalOrderByManager(Manager):
|
|||||||
id3 = '_{}_{}3'.format(db_table, primary_field)
|
id3 = '_{}_{}3'.format(db_table, primary_field)
|
||||||
|
|
||||||
queryset = super(NaturalOrderByManager, self).get_queryset().extra(select={
|
queryset = super(NaturalOrderByManager, self).get_queryset().extra(select={
|
||||||
id1: "CAST(SUBSTRING({}.{} FROM '^(\d{{1,9}})') AS integer)".format(db_table, primary_field),
|
id1: r"CAST(SUBSTRING({}.{} FROM '^(\d{{1,9}})') AS integer)".format(db_table, primary_field),
|
||||||
id2: "SUBSTRING({}.{} FROM '^\d*(.*?)\d*$')".format(db_table, primary_field),
|
id2: r"SUBSTRING({}.{} FROM '^\d*(.*?)\d*$')".format(db_table, primary_field),
|
||||||
id3: "CAST(SUBSTRING({}.{} FROM '(\d{{1,9}})$') AS integer)".format(db_table, primary_field),
|
id3: r"CAST(SUBSTRING({}.{} FROM '(\d{{1,9}})$') AS integer)".format(db_table, primary_field),
|
||||||
})
|
})
|
||||||
ordering = fields[0:-1] + (id1, id2, id3)
|
ordering = fields[0:-1] + (id1, id2, id3)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class EnhancedURLValidator(URLValidator):
|
|||||||
A fake URL list which "contains" all scheme names abiding by the syntax defined in RFC 3986 section 3.1
|
A fake URL list which "contains" all scheme names abiding by the syntax defined in RFC 3986 section 3.1
|
||||||
"""
|
"""
|
||||||
def __contains__(self, item):
|
def __contains__(self, item):
|
||||||
if not item or not re.match('^[a-z][0-9a-z+\-.]*$', item.lower()):
|
if not item or not re.match(r'^[a-z][0-9a-z+\-.]*$', item.lower()):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user