Skip to content

Commit 77f4405

Browse files
authored
Merge pull request #3406 from JdeRobot/add-filesystem
Change structure to make it generic
2 parents c17667f + e4340c2 commit 77f4405

File tree

618 files changed

+1566
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

618 files changed

+1566
-1160
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ build/
1313
develop-eggs/
1414
dist/
1515
downloads/
16+
filesystem/
1617
eggs/
1718
.eggs/
1819
lib/
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.apps import AppConfig
22

33

4-
class ExercisesConfig(AppConfig):
4+
class AcademyConfig(AppConfig):
55
default_auto_field = "django.db.models.BigAutoField"
6-
name = "exercises"
6+
name = "academy"

academy/constants.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
base_py_code = """import WebGUI
2+
import HAL
3+
import Frequency
4+
# Enter sequential code!
5+
6+
while True:
7+
# Enter iterative code!
8+
Frequency.tick()
9+
"""
10+
11+
base_cpp_code = """#include "HAL.hpp"
12+
#include "WebGUI.hpp"
13+
#include "Frequency.hpp"
14+
15+
void exercise() {
16+
Frequency freq = Frequency();
17+
// Enter sequential code!
18+
19+
while (true)
20+
{
21+
// Enter iterative code!
22+
freq.tick();
23+
24+
25+
}
26+
}
27+
"""
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from functools import wraps
1212
import json
1313
from .exceptions import (
14+
BinaryNotSupported,
1415
ResourceNotExists,
1516
ResourceAlreadyExists,
1617
ParameterInvalid,
@@ -22,10 +23,11 @@
2223
ResourceAlreadyExists,
2324
ParameterInvalid,
2425
InvalidPath,
26+
BinaryNotSupported,
2527
)
2628

2729

28-
def error_wrapper(type: str, param: list[str | tuple] = []):
30+
def error_wrapper(fal, type: str, param: list[str | tuple] = []):
2931
"""
3032
Decorator for API views with parameter validation and error handling.
3133
@@ -36,37 +38,26 @@ def error_wrapper(type: str, param: list[str | tuple] = []):
3638
Returns:
3739
function: Wrapped API view.
3840
"""
41+
3942
def decorated(func):
4043
@wraps(func)
4144
@api_view([type])
4245
def wrapper(request):
4346
try:
44-
check_parameters(
45-
request.data if type == "POST" else request.GET,
46-
param
47-
)
47+
check_parameters(request.data if type == "POST" else request.GET, param)
4848
return func(request)
4949
except CUSTOM_EXCEPTIONS as e:
5050
print(str(e))
51-
return Response({"error": str(e)}, status=e.error_code)
51+
return Response({"message": str(e)}, status=e.error_code)
5252
except json.JSONDecodeError as e:
5353
print(str(e))
54-
return Response(
55-
{"error": f"Invalid JSON format: {str(e)}"},
56-
status=422
57-
)
54+
return Response({"error": f"Invalid JSON format: {str(e)}"}, status=422)
5855
except (binascii.Error, ValueError) as e:
5956
print(str(e))
60-
return Response(
61-
{"error": f"Invalid B64 format: {str(e)}"},
62-
status=422
63-
)
57+
return Response({"error": f"Invalid B64 format: {str(e)}"}, status=422)
6458
except Exception as e:
6559
print(str(e))
66-
return Response(
67-
{"error": f"An error occurred: {str(e)}"},
68-
status=500
69-
)
60+
return Response({"error": f"An error occurred: {str(e)}"}, status=500)
7061

7162
return wrapper
7263

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ def __init__(self, msg):
4444

4545
def __str__(self):
4646
return f"{self.message}"
47+
48+
49+
class BinaryNotSupported(Exception):
50+
"""Exception raised for trying to read a binary file."""
51+
52+
def __init__(self, msg):
53+
self.message = f"Reading {msg} is not supported"
54+
super().__init__(self.message)
55+
self.error_code = 415
56+
57+
def __str__(self):
58+
return f"{self.message}"

0 commit comments

Comments
 (0)