import json
import csv
from bs4 import BeautifulSoup


def read_file(path, mode="default"):
    """Open a file and return its content (parsed if possible)
    :param path: (abs) path to the file
    :param mode: "default|json"
    :type path: str
    :type mode: str
    :return: content of the file
    :rtype: str or dict
    """
    if mode == "default":
        with open(path, "r", encoding="utf-8") as fh:
            content = fh.read()
    elif mode == "json":
        with open(path, "r", encoding="utf-8") as fh:
            content = json.load(fh)
    elif mode == "csv":
        with open(path, "r", newline="", encoding="utf-8") as fh:
            content = [r for r in csv.reader(fh)]
    elif mode == "xml":
        with open(path, "r", encoding="utf-8") as fh:
            content = fh.read()
        content = BeautifulSoup(content, 'xml')
    else:
        content = False
    return content