Skip to content

Commit

Permalink
Delete docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
tjkuson committed Sep 28, 2024
1 parent 7896a8d commit 8d671a3
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 57 deletions.
5 changes: 0 additions & 5 deletions src/screener/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Screener entry-point script."""

import sys
from argparse import ArgumentParser
from pathlib import Path
Expand All @@ -10,7 +8,6 @@


def init_argparse() -> ArgumentParser:
"""Create argument parser for system args."""
parser = ArgumentParser(
prog="screener",
usage="%(prog)s [OPTION] [FILE]...",
Expand All @@ -27,7 +24,6 @@ def init_argparse() -> ArgumentParser:


def check_file(file: Path) -> Checker:
"""Check file."""
checker = Checker(file)
match extension := file.suffix:
case ".epub":
Expand All @@ -43,7 +39,6 @@ def check_file(file: Path) -> Checker:


def main() -> None:
"""Read system args and check e-book files."""
parser = init_argparse()
args = parser.parse_args()
if not args.files:
Expand Down
4 changes: 0 additions & 4 deletions src/screener/checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Checker class for checking the data."""

from dataclasses import dataclass, field
from pathlib import Path

Expand All @@ -8,7 +6,5 @@

@dataclass
class Checker:
"""Checker class for checking the data."""

file_path: Path
diagnostics: list[Diagnostic] = field(default_factory=list)
12 changes: 0 additions & 12 deletions src/screener/diagnostic.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
"""Diagnostic information about a file."""

from dataclasses import dataclass


@dataclass
class Diagnostic:
"""Diagnostic information about a file."""

file_name: str


@dataclass
class JavaScriptDiagnostic(Diagnostic):
"""Diagnostic information about a file with JavaScript."""

culprit: str

def __str__(self) -> str:
"""Return a string representation of the diagnostic."""
return (
f"JavaScript found in {self.file_name}: {self.culprit}"
if self.culprit
Expand All @@ -27,12 +20,9 @@ def __str__(self) -> str:

@dataclass
class ExternalImageDiagnostic(Diagnostic):
"""Diagnostic information about a file with external images."""

culprit: str

def __str__(self) -> str:
"""Return a string representation of the diagnostic."""
return (
f"External images found in {self.file_name}: {self.culprit}"
if self.culprit
Expand All @@ -42,6 +32,4 @@ def __str__(self) -> str:

@dataclass
class ParseErrorDiagnostic(Diagnostic):
"""Diagnostic information about a file that could not be parsed."""

msg: str
2 changes: 0 additions & 2 deletions src/screener/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Parse ebook files in different formats."""

from .epub import parse_epub
from .kindle import parse_kindle

Expand Down
6 changes: 0 additions & 6 deletions src/screener/parser/epub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Parse epub file to check that it is safe."""

from pathlib import Path

from ebooklib import ITEM_DOCUMENT
Expand All @@ -16,10 +14,6 @@ def parse_epub(
checker: Checker,
path_to_epub: Path,
) -> None:
"""Parse epub to check that it is safe.
Mutates the checker object to add diagnostics.
"""
with EpubFileReader(path_to_epub) as epub:
for item in epub.book.get_items_of_type(ITEM_DOCUMENT):
content = item.get_content()
Expand Down
3 changes: 0 additions & 3 deletions src/screener/parser/kindle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Parse kindle files."""

from pathlib import Path

from screener.checker import Checker
Expand All @@ -12,7 +10,6 @@ def parse_kindle(
checker: Checker,
path_to_kindle: Path | None,
) -> None:
"""Parse kindle to check that it is safe."""
if path_to_kindle is None:
msg = "path_to_kindle cannot be None"
raise ValueError(msg)
Expand Down
2 changes: 0 additions & 2 deletions src/screener/reader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Read epub files."""

from .epub import EpubFileReader
from .kindle import KindleFileReader

Expand Down
9 changes: 1 addition & 8 deletions src/screener/reader/abstract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Abstract reader class."""

from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -10,20 +8,15 @@


class AbstractReader:
"""Abstract class for reader classes."""

def __init__(self: AbstractReader, file_path: Path) -> None:
"""Initialize the class."""
self.file_path = file_path

def __enter__(self: AbstractReader) -> AbstractReader:
"""Virtual method to be overridden by subclasses."""
raise NotImplementedError

def __exit__(
self: AbstractReader,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
"""Run on exit of runtime context."""
) -> None: ...
6 changes: 0 additions & 6 deletions src/screener/reader/epub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Read epub files."""

from __future__ import annotations

import warnings
Expand All @@ -14,15 +12,11 @@


class EpubFileReader(AbstractReader):
"""Handle epub files."""

def __init__(self: EpubFileReader, file_path: Path) -> None:
"""Initialize the class."""
super().__init__(file_path)
self.book: epub.EpubBook

def __enter__(self: EpubFileReader) -> EpubFileReader:
"""Runtime context."""
with warnings.catch_warnings():
# Have to do this because of bug in ebooklib.
warnings.simplefilter("ignore")
Expand Down
7 changes: 0 additions & 7 deletions src/screener/reader/kindle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Contains methods to check a Kindle e-book file for security and privacy issues."""

from __future__ import annotations

import shutil
Expand All @@ -15,16 +13,12 @@


class KindleFileReader(AbstractReader):
"""Handle azw3 files."""

def __init__(self: KindleFileReader, file_path: Path) -> None:
"""Initialize the class."""
super().__init__(file_path)
self._temp_dir = None
self.generated_translation = None

def __enter__(self: KindleFileReader) -> KindleFileReader:
"""Runtime context."""
# The `mobi` library likes file paths as strings for whatever reason.
self._temp_dir, self.generated_translation = extract(str(self.file_path))
if self.generated_translation is None or self._temp_dir is None:
Expand All @@ -38,6 +32,5 @@ def __exit__(
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
"""Delete temp files."""
if self._temp_dir is not None:
shutil.rmtree(self._temp_dir)
2 changes: 0 additions & 2 deletions src/screener/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Screener utility functions."""

from bs4 import BeautifulSoup

from screener.checker import Checker
Expand Down

0 comments on commit 8d671a3

Please sign in to comment.