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
예제 #2
0
 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()
예제 #3
0
def test_css():
    actual = mimetypes.guess_type("css.css")[0]
    expected = "text/css"
    assert actual == expected
예제 #4
0
def test_ncx():
    actual = mimetypes.guess_type("ncx.ncx")[0]
    expected = "application/x-dtbncx+xml"
    assert actual == expected
예제 #5
0
def test_xhtml():
    actual = mimetypes.guess_type("xhtml.xhtml")[0]
    expected = "application/xhtml+xml"
    assert actual == expected
예제 #6
0
def test_js():
    actual = mimetypes.guess_type("js.js")[0]
    expected = "application/javascript"
    assert actual == expected
예제 #7
0
def test_gif():
    actual = mimetypes.guess_type("gif.gif")[0]
    expected = "image/gif"
    assert actual == expected
예제 #8
0
def test_jpg():
    actual = mimetypes.guess_type("jpg.jpg")[0]
    expected = "image/jpeg"
    assert actual == expected
예제 #9
0
def test_svg():
    actual = mimetypes.guess_type("svg.svg")[0]
    expected = "image/svg+xml"
    assert actual == expected
예제 #10
0
def test_png():
    actual = mimetypes.guess_type("png.png")[0]
    expected = "image/png"
    assert actual == expected
예제 #11
0
def test_ttf():
    actual = mimetypes.guess_type("ttf.ttf")[0]
    expected = "font/ttf"
    assert actual == expected
예제 #12
0
def test_otf():
    actual = mimetypes.guess_type("otf.otf")[0]
    expected = "font/otf"
    assert actual == expected
예제 #13
0
def test_woff2():
    actual = mimetypes.guess_type("woff2.woff2")[0]
    expected = "font/woff2"
    assert actual == expected