def is_page(cls, path: Path) -> bool: if not path.is_file(): return False if mimetypes.guess_type(path)[0] not in cls.FORMATS: return False try: page_number = int(path.stem) return page_number > 0 except ValueError: return False
def __init__(self, href: Path, mimetype: Optional[str] = None, manifest_properties: Optional[set[str]] = None, spine_properties: Optional[set[str]] = None) -> None: self.href: Path = href self.mimetype: str = (mimetype or mimetypes.guess_type(href)[0] or "application/octet-stream") self.id_count: int = 0 self.manifest_properties: set[str] = manifest_properties or set() self.spine_properties: set[str] = spine_properties or set()
def test_css(): actual = mimetypes.guess_type("css.css")[0] expected = "text/css" assert actual == expected
def test_ncx(): actual = mimetypes.guess_type("ncx.ncx")[0] expected = "application/x-dtbncx+xml" assert actual == expected
def test_xhtml(): actual = mimetypes.guess_type("xhtml.xhtml")[0] expected = "application/xhtml+xml" assert actual == expected
def test_js(): actual = mimetypes.guess_type("js.js")[0] expected = "application/javascript" assert actual == expected
def test_gif(): actual = mimetypes.guess_type("gif.gif")[0] expected = "image/gif" assert actual == expected
def test_jpg(): actual = mimetypes.guess_type("jpg.jpg")[0] expected = "image/jpeg" assert actual == expected
def test_svg(): actual = mimetypes.guess_type("svg.svg")[0] expected = "image/svg+xml" assert actual == expected
def test_png(): actual = mimetypes.guess_type("png.png")[0] expected = "image/png" assert actual == expected
def test_ttf(): actual = mimetypes.guess_type("ttf.ttf")[0] expected = "font/ttf" assert actual == expected
def test_otf(): actual = mimetypes.guess_type("otf.otf")[0] expected = "font/otf" assert actual == expected
def test_woff2(): actual = mimetypes.guess_type("woff2.woff2")[0] expected = "font/woff2" assert actual == expected