From f26ed2d5d493b34e0f4a8183ccbec779decb0dbb Mon Sep 17 00:00:00 2001 From: Firas Moosvi Date: Thu, 17 Aug 2023 14:01:00 -0700 Subject: [PATCH 1/3] Update problem_bank_helpers.py I changed the names of these two functions to make them simpler to use (and so the type isn't part of the function name) I'll do a find and replace in instructor_datascience_bank to fix this on any questions that are currently using this. --- src/problem_bank_helpers/problem_bank_helpers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/problem_bank_helpers/problem_bank_helpers.py b/src/problem_bank_helpers/problem_bank_helpers.py index a96c876..060f0c6 100644 --- a/src/problem_bank_helpers/problem_bank_helpers.py +++ b/src/problem_bank_helpers/problem_bank_helpers.py @@ -369,14 +369,14 @@ def backticks_to_code_tags(data): value = value.replace("\\`", "`") # Replace escaped backticks data["params"][param][answer]["value"] = value -def base64_encode_string(string): - """Encode a string into a base64 representation to act as a file for prarielearn +def base64_encode(string): + """Encode a regular string into a base64 representation to act as a file for prarielearn to store """ # Based off of https://github.com/PrairieLearn/PrairieLearn/blob/2ff7c5cc2435bae80c0ba512631749f9c3eadb43/exampleCourse/questions/demo/autograder/python/leadingTrailing/server.py#L9-L11 return base64.b64encode(string.encode("utf-8")).decode("utf-8") -def base64_decode_file(file): - """Decode a base64 string which is a file from prairielearn into a useable string +def base64_decode(file): + """Decode a base64 string (which is a file) from prairielearn into a useable string """ # symetrical to base64_encode_string return base64.b64decode(to_decode.encode("utf-8")).decode("utf-8") @@ -427,4 +427,4 @@ def choose_el(x, i, j): html += "\n".join(elements) html += "\n" html += "\n" - return html \ No newline at end of file + return html From 70b5d0a403ad4af0185d5319f0713093edca1873 Mon Sep 17 00:00:00 2001 From: Firas Moosvi Date: Thu, 17 Aug 2023 14:07:26 -0700 Subject: [PATCH 2/3] Fix error in base64_decode and simplify file names --- src/problem_bank_helpers/problem_bank_helpers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/problem_bank_helpers/problem_bank_helpers.py b/src/problem_bank_helpers/problem_bank_helpers.py index 060f0c6..3579005 100644 --- a/src/problem_bank_helpers/problem_bank_helpers.py +++ b/src/problem_bank_helpers/problem_bank_helpers.py @@ -369,17 +369,17 @@ def backticks_to_code_tags(data): value = value.replace("\\`", "`") # Replace escaped backticks data["params"][param][answer]["value"] = value -def base64_encode(string): +def base64_encode(s): """Encode a regular string into a base64 representation to act as a file for prarielearn to store """ # Based off of https://github.com/PrairieLearn/PrairieLearn/blob/2ff7c5cc2435bae80c0ba512631749f9c3eadb43/exampleCourse/questions/demo/autograder/python/leadingTrailing/server.py#L9-L11 - return base64.b64encode(string.encode("utf-8")).decode("utf-8") + return base64.b64encode(s.encode("utf-8")).decode("utf-8") -def base64_decode(file): +def base64_decode(f): """Decode a base64 string (which is a file) from prairielearn into a useable string """ # symetrical to base64_encode_string - return base64.b64decode(to_decode.encode("utf-8")).decode("utf-8") + return base64.b64decode(f.encode("utf-8")).decode("utf-8") def string_to_pl_user_file(string, data): """Encode a string to base64 and add it as the user submitted code file From 8c1e3721da6b293f2bd231da6c3b7c9e787648ed Mon Sep 17 00:00:00 2001 From: Gavin Kendal-Freedman <68259537+Bluesy1@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:43:10 -0800 Subject: [PATCH 3/3] Update string_to_pl_user_file function --- src/problem_bank_helpers/problem_bank_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/problem_bank_helpers/problem_bank_helpers.py b/src/problem_bank_helpers/problem_bank_helpers.py index 3579005..23e3ab7 100644 --- a/src/problem_bank_helpers/problem_bank_helpers.py +++ b/src/problem_bank_helpers/problem_bank_helpers.py @@ -385,7 +385,7 @@ def string_to_pl_user_file(string, data): """Encode a string to base64 and add it as the user submitted code file """ # partially based off of https://github.com/PrairieLearn/PrairieLearn/blob/2ff7c5cc2435bae80c0ba512631749f9c3eadb43/apps/prairielearn/elements/pl-file-upload/pl-file-upload.py#L114C1-L119 - parsed_file = {"name": "user_code.py", "contents": base64_encode_string(answer)} + parsed_file = {"name": "user_code.py", "contents": base64_encode(string)} if isinstance(data["submitted_answers"].get("_files", None), list): data["submitted_answers"]["_files"].append(parsed_file) else: