Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXES: #2961 #2962

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,7 @@ def __exit__(self, *args):
self.close()

def __getitem__(self, i: int =0):
assert isinstance(i, int) or (isinstance(i, tuple) and len(i) == 2 and all(isinstance(x, int) for x in i))
if i not in self:
raise IndexError(f"page {i} not in document")
return self.load_page(i)
Expand Down
1 change: 1 addition & 0 deletions src_classic/fitz_old.i
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,7 @@ if basestate:


def __getitem__(self, i: int =0)->"Page":
assert isinstance(i, int) or (isinstance(i, tuple) and len(i) == 2 and all(isinstance(x, int) for x in i))
if i not in self:
raise IndexError("page not in document")
return self.load_page(i)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pixmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import platform
import sys
import tempfile
import pytest

scriptdir = os.path.abspath(os.path.dirname(__file__))
epub = os.path.join(scriptdir, "resources", "Bezier.epub")
Expand Down Expand Up @@ -132,3 +133,10 @@ def test_2369():
img_bytes = img["image"]
fitz.Pixmap(img_bytes)

def test_page_idx_int():
doc = fitz.open(pdf)
with pytest.raises(AssertionError):
doc["0"]
assert doc[0]
assert doc[(0,0)]

Loading