Skip to content

Commit

Permalink
Avoid empty lists as default arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence committed Aug 19, 2020
1 parent b464adf commit 15ef8cb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions securedrop/upload-screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# filename into the canonical title we give that screenshot in Weblate.
#
# Example conversion: "source-session_timeout.png" -> "source: session timeout"
CANONICALIZATION_RULES = [(r"\.png$", ""), (r"-", ": "), (r"_", " ")]
CANONICALIZATION_RULES = ((r"\.png$", ""), (r"-", ": "), (r"_", " "))

# Weblate organizes internationalization work into projects and components,
# which are part of many URLs, and need to be referenced in some API requests.
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(
component,
files,
request_limit,
canonicalization_rules=[],
canonicalization_rules=(),
):

if len(token) != 40:
Expand Down Expand Up @@ -169,7 +169,7 @@ def _canonicalize(self, filename):
filename = re.sub(pattern, repl, filename)
return filename

def upload(self, existing_screenshots=[]):
def upload(self, existing_screenshots=None):
"""
Uploads all files using the screenshots endpoint. Optionally, checks
files against a list of existing screenshots and replaces them rather
Expand All @@ -179,11 +179,14 @@ def upload(self, existing_screenshots=[]):
basename = os.path.basename(file)
canonical_name = self._canonicalize(basename)
existing_screenshot_url = None
for screenshot in existing_screenshots:
if screenshot["name"] == canonical_name:
existing_screenshot_url = screenshot["file_url"]
break
image = {"image": open(file, "rb")}

if existing_screenshots is not None:
for screenshot in existing_screenshots:
if screenshot["name"] == canonical_name:
existing_screenshot_url = screenshot["file_url"]
break
image = {"image": open(file, "rb")}

if existing_screenshot_url is not None:
print("Replacing existing screenshot {}".format(basename))
response = self.session.post(existing_screenshot_url, files=image)
Expand Down

0 comments on commit 15ef8cb

Please sign in to comment.