def __init__(self, author: str, filename: str, date: datetime.date | datetime.datetime | None=None, content: str | bytes='', description: str='', downloads: int=0):
"""Initialize the document with the provided parameters.
When the document is created, it is saved in a folder with the following format:
author_date_filetype_filename
:Example:
>>> # Create a document without the extension in the filename (default: txt):
>>> doc = Document("Alice", "Doc1", "Your_content", date=datetime.datetime(2023, 1, 1))
>>> # Create a document with the extension in the filename:
>>> doc2 = Document("Alice", "Doc1.txt", "Your_content", date=datetime.date(2023, 1, 1))
>>> # Create a document without a date and filetype:
>>> doc1 = Document("Alice", "Doc1", "Your_content")
:param filename: (str) The name of the file provided with the extension
:param author: (str) The author of the file
:param content: (str) The content of the file (optional)
:param date: (datetime|date) The date of the file (optional) (default: today)
:param description: (str) The description of the file (optional)
:raises: ValueError: if the filename is too short
:raises: TypeError: if the parameters are not in the correct format
"""
if len(filename) < ws.MIN_FILE_NAME_LENGTH:
raise ValueError('Document.__init__: filename must be at least 4 characters long.')
if len(author) < 1 or len(filename) < 1:
raise ValueError('Document.__init__: author and filename must be at least 1 character long.')
TypesDealer.check_types('Document.__init__', [(author, str), (filename, str), (description, (str, type(None)))])
TypesDealer.check_types('Document.__init__', [(content, (str, bytes))])
TypesDealer.check_types('Document.__init__', [(downloads, int)])
if date is not None:
TypesDealer.check_types('Document.__init__', [(date, (datetime.datetime, datetime.date))])
self.__author = DocumentUtils.format_author(author)
self.__filename = DocumentUtils.format_filename(filename)
self.__filetype = DocumentUtils.get_filetype(filename)
self.__date = DocumentUtils.format_date(date)
self.__downloads = downloads
self.__content = ''
self.__description = ''
self.set_description(description)
self.set_content(content)