Skip to content

Commit 937a020

Browse files
Ruff: Add PLC1901 to dojo/models (DefectDojo#13178)
* Ruff: Add PLC1901 to dojo/models * update
1 parent 8d92288 commit 937a020

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

dojo/models.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,16 +1826,16 @@ def clean(self):
18261826
errors = []
18271827
null_char_list = ["0x00", "\x00"]
18281828
db_type = connection.vendor
1829-
if self.protocol or self.protocol == "":
1829+
if self.protocol is not None:
18301830
if not re.match(r"^[A-Za-z][A-Za-z0-9\.\-\+]+$", self.protocol): # https://tools.ietf.org/html/rfc3986#section-3.1
18311831
errors.append(ValidationError(f'Protocol "{self.protocol}" has invalid format'))
1832-
if self.protocol == "":
1832+
if not self.protocol:
18331833
self.protocol = None
18341834

1835-
if self.userinfo or self.userinfo == "":
1835+
if self.userinfo is not None:
18361836
if not re.match(r"^[A-Za-z0-9\.\-_~%\!\$&\'\(\)\*\+,;=:]+$", self.userinfo): # https://tools.ietf.org/html/rfc3986#section-3.2.1
18371837
errors.append(ValidationError(f'Userinfo "{self.userinfo}" has invalid format'))
1838-
if self.userinfo == "":
1838+
if not self.userinfo:
18391839
self.userinfo = None
18401840

18411841
if self.host:
@@ -1847,7 +1847,7 @@ def clean(self):
18471847
else:
18481848
errors.append(ValidationError("Host must not be empty"))
18491849

1850-
if self.port or self.port == 0:
1850+
if self.port is not None:
18511851
try:
18521852
int_port = int(self.port)
18531853
if not (0 <= int_port < 65536):
@@ -1856,7 +1856,7 @@ def clean(self):
18561856
except ValueError:
18571857
errors.append(ValidationError(f'Port "{self.port}" has invalid format - it is not a number'))
18581858

1859-
if self.path or self.path == "":
1859+
if self.path is not None:
18601860
while len(self.path) > 0 and self.path[0] == "/": # Endpoint store "root-less" path
18611861
self.path = self.path[1:]
18621862
if any(null_char in self.path for null_char in null_char_list):
@@ -1866,10 +1866,10 @@ def clean(self):
18661866
for remove_str in null_char_list:
18671867
self.path = self.path.replace(remove_str, "%00")
18681868
logger.error('Path "%s" has invalid format - It contains the NULL character. The following action was taken: %s', old_value, action_string)
1869-
if self.path == "":
1869+
if not self.path:
18701870
self.path = None
18711871

1872-
if self.query or self.query == "":
1872+
if self.query is not None:
18731873
if len(self.query) > 0 and self.query[0] == "?":
18741874
self.query = self.query[1:]
18751875
if any(null_char in self.query for null_char in null_char_list):
@@ -1879,10 +1879,10 @@ def clean(self):
18791879
for remove_str in null_char_list:
18801880
self.query = self.query.replace(remove_str, "%00")
18811881
logger.error('Query "%s" has invalid format - It contains the NULL character. The following action was taken: %s', old_value, action_string)
1882-
if self.query == "":
1882+
if not self.query:
18831883
self.query = None
18841884

1885-
if self.fragment or self.fragment == "":
1885+
if self.fragment is not None:
18861886
if len(self.fragment) > 0 and self.fragment[0] == "#":
18871887
self.fragment = self.fragment[1:]
18881888
if any(null_char in self.fragment for null_char in null_char_list):
@@ -1892,7 +1892,7 @@ def clean(self):
18921892
for remove_str in null_char_list:
18931893
self.fragment = self.fragment.replace(remove_str, "%00")
18941894
logger.error('Fragment "%s" has invalid format - It contains the NULL character. The following action was taken: %s', old_value, action_string)
1895-
if self.fragment == "":
1895+
if not self.fragment:
18961896
self.fragment = None
18971897

18981898
if errors:
@@ -2050,13 +2050,13 @@ def from_uri(uri):
20502050
query_parts.append(f"{k}={v}")
20512051
query_string = "&".join(query_parts)
20522052

2053-
protocol = url.scheme if url.scheme != "" else None
2053+
protocol = url.scheme or None
20542054
userinfo = ":".join(url.userinfo) if url.userinfo not in {(), ("",)} else None
2055-
host = url.host if url.host != "" else None
2055+
host = url.host or None
20562056
port = url.port
20572057
path = "/".join(url.path)[:500] if url.path not in {None, (), ("",)} else None
2058-
query = query_string[:1000] if query_string is not None and query_string != "" else None
2059-
fragment = url.fragment[:500] if url.fragment is not None and url.fragment != "" else None
2058+
query = query_string[:1000] if query_string is not None and query_string else None
2059+
fragment = url.fragment[:500] if url.fragment is not None and url.fragment else None
20602060

20612061
return Endpoint(
20622062
protocol=protocol,

ruff.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ preview = true
115115
"S108", # tmp paths mentioned in tests are fine
116116
]
117117

118-
"dojo/models.py" = [
119-
"PLC1901", # fix later, causes some problems
120-
]
121-
122118
[lint.flake8-boolean-trap]
123119
extend-allowed-calls = ["dojo.utils.get_system_setting"]
124120

0 commit comments

Comments
 (0)