Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions openedx_tagging/core/tagging/import_export/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@
"""
from __future__ import annotations

from io import BytesIO
from typing import BinaryIO

from django.utils.translation import gettext as _

from ..models import TagImportTask, TagImportTaskState, Taxonomy
from .exceptions import TagImportError
from .import_plan import TagImportPlan, TagImportTask
from .parsers import ParserFormat, get_parser


def import_tags(
taxonomy: Taxonomy,
file: BytesIO,
file: BinaryIO,
parser_format: ParserFormat,
replace=False,
) -> bool:
Expand Down Expand Up @@ -116,7 +115,7 @@ def import_tags(
tag_import_plan.execute(task)
task.end_success()
return True
except (TagImportError, ValueError) as exception:
except Exception as exception: # pylint: disable=broad-exception-caught
# Log any exception
task.log_exception(exception)
return False
Expand Down
11 changes: 6 additions & 5 deletions openedx_tagging/core/tagging/import_export/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import csv
import json
from enum import Enum
from io import BytesIO, StringIO, TextIOWrapper
from io import StringIO, TextIOWrapper
from typing import BinaryIO

from django.utils.translation import gettext as _

Expand Down Expand Up @@ -51,7 +52,7 @@ class Parser:
inital_row = 1

@classmethod
def parse_import(cls, file: BytesIO) -> tuple[list[TagItem], list[TagParserError]]:
def parse_import(cls, file: BinaryIO) -> tuple[list[TagItem], list[TagParserError]]:
"""
Parse tags in file an returns tags ready for use in TagImportPlan

Expand Down Expand Up @@ -79,7 +80,7 @@ def export(cls, taxonomy: Taxonomy) -> str:
return cls._export_data(tags, taxonomy)

@classmethod
def _load_data(cls, file: BytesIO) -> tuple[list[dict], list[TagParserError]]:
def _load_data(cls, file: BinaryIO) -> tuple[list[dict], list[TagParserError]]:
"""
Each parser implements this function according to its format.
This function reads the file and returns a list with the values of each tag.
Expand Down Expand Up @@ -206,7 +207,7 @@ class JSONParser(Parser):
inital_row = 0

@classmethod
def _load_data(cls, file: BytesIO) -> tuple[list[dict], list[TagParserError]]:
def _load_data(cls, file: BinaryIO) -> tuple[list[dict], list[TagParserError]]:
"""
Read a .json file and validates the root structure of the json
"""
Expand Down Expand Up @@ -259,7 +260,7 @@ class CSVParser(Parser):
inital_row = 2

@classmethod
def _load_data(cls, file: BytesIO) -> tuple[list[dict], list[TagParserError]]:
def _load_data(cls, file: BinaryIO) -> tuple[list[dict], list[TagParserError]]:
"""
Read a .csv file and validates the header fields
"""
Expand Down