Skip to content

Commit

Permalink
refactor!: there can be only one (parser)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Oct 29, 2024
1 parent 2b375b8 commit 8aaf9ab
Show file tree
Hide file tree
Showing 16 changed files with 642 additions and 642 deletions.
2 changes: 1 addition & 1 deletion playa/cmapdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from playa.encodingdb import name2unicode
from playa.exceptions import PDFException, PDFTypeError, PSSyntaxError
from playa.psparser import KWD, Parser, PSKeyword, PSLiteral, literal_name
from playa.parser import KWD, Parser, PSKeyword, PSLiteral, literal_name
from playa.utils import choplist, nunpack

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion playa/color.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import collections
from typing import Dict

from playa.psparser import LIT
from playa.parser import LIT

LITERAL_DEVICE_GRAY = LIT("DeviceGray")
LITERAL_DEVICE_RGB = LIT("DeviceRGB")
Expand Down
38 changes: 24 additions & 14 deletions playa/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@
PDFTypeError,
PSException,
)
from playa.font import (
PDFCIDFont,
PDFFont,
PDFTrueTypeFont,
PDFType1Font,
PDFType3Font,
)
from playa.font import PDFCIDFont, PDFFont, PDFTrueTypeFont, PDFType1Font, PDFType3Font
from playa.page import PDFPage
from playa.parser import KEYWORD_XREF, PDFParser, ContentStreamParser
from playa.parser import (
KEYWORD_OBJ,
KEYWORD_TRAILER,
KEYWORD_XREF,
LIT,
ContentStreamParser,
PDFParser,
PSLiteral,
literal_name,
)
from playa.pdftypes import (
ContentStream,
DecipherCallable,
ObjRef,
ContentStream,
decipher_all,
dict_value,
int_value,
Expand All @@ -66,7 +69,6 @@
stream_value,
uint_value,
)
from playa.psparser import KWD, LIT, PSLiteral, literal_name
from playa.utils import (
choplist,
decode_text,
Expand All @@ -88,7 +90,6 @@
LITERAL_CATALOG = LIT("Catalog")
LITERAL_PAGE = LIT("Page")
LITERAL_PAGES = LIT("Pages")
KEYWORD_OBJ = KWD(b"obj")
INHERITABLE_PAGE_ATTRS = {"Resources", "MediaBox", "CropBox", "Rotate"}


Expand Down Expand Up @@ -149,8 +150,14 @@ def _load(self, parser: PDFParser) -> None:
def _load_trailer(self, parser: PDFParser) -> None:
try:
(_, kwd) = parser.nexttoken()
if kwd is not KWD(b"trailer"):
raise PDFSyntaxError("Expected b'trailer', got %r", kwd)
if kwd is not KEYWORD_TRAILER:
raise PDFSyntaxError(
"Expected %r, got %r"
% (
KEYWORD_TRAILER,
kwd,
)
)
(_, dic) = next(parser)
except StopIteration:
x = parser.pop(1)
Expand Down Expand Up @@ -241,7 +248,10 @@ def _load(self, parser: PDFParser) -> None:
(_, genno) = parser.nexttoken() # ignored
(_, kwd) = parser.nexttoken()
(_, stream) = next(parser)
if not isinstance(stream, ContentStream) or stream.get("Type") is not LITERAL_XREF:
if (
not isinstance(stream, ContentStream)
or stream.get("Type") is not LITERAL_XREF
):
raise PDFNoValidXRef(f"Invalid PDF stream spec {stream!r}")
size = stream["Size"]
index_array = stream.get("Index", (0, size))
Expand Down
2 changes: 1 addition & 1 deletion playa/encodingdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from playa.exceptions import PDFKeyError
from playa.glyphlist import glyphname2unicode
from playa.latin_enc import ENCODING
from playa.psparser import PSLiteral
from playa.parser import PSLiteral

HEXADECIMAL = re.compile(r"[0-9a-fA-F]+")

Expand Down
16 changes: 8 additions & 8 deletions playa/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
PDFValueError,
)
from playa.fontmetrics import FONT_METRICS
from playa.parser import (
KWD,
LIT,
Parser,
PSKeyword,
PSLiteral,
literal_name,
)
from playa.pdftypes import (
ContentStream,
dict_value,
Expand All @@ -44,14 +52,6 @@
resolve_all,
stream_value,
)
from playa.psparser import (
KWD,
LIT,
Parser,
PSKeyword,
PSLiteral,
literal_name,
)
from playa.utils import Matrix, Point, Rect, apply_matrix_norm, choplist, nunpack

log = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions playa/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from io import BytesIO
from typing import BinaryIO, Literal, Tuple

from playa.exceptions import PDFValueError
from playa.jbig2 import JBIG2StreamReader, JBIG2StreamWriter
from playa.layout import LTImage
from playa.color import (
LITERAL_DEVICE_CMYK,
LITERAL_DEVICE_GRAY,
LITERAL_DEVICE_RGB,
LITERAL_INLINE_DEVICE_GRAY,
LITERAL_INLINE_DEVICE_RGB,
)
from playa.exceptions import PDFValueError
from playa.jbig2 import JBIG2StreamReader, JBIG2StreamWriter
from playa.layout import LTImage
from playa.pdftypes import (
LITERALS_DCT_DECODE,
LITERALS_FLATE_DECODE,
Expand Down
2 changes: 1 addition & 1 deletion playa/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
cast,
)

from playa.exceptions import PDFValueError
from playa.color import PDFColorSpace
from playa.exceptions import PDFValueError
from playa.font import PDFFont
from playa.pdftypes import ContentStream
from playa.utils import (
Expand Down
26 changes: 10 additions & 16 deletions playa/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

from playa import settings
from playa.casting import safe_float
from playa.color import PREDEFINED_COLORSPACE, PDFColorSpace
from playa.exceptions import (
PDFInterpreterError,
PDFSyntaxError,
PDFUnicodeNotDefined,
PDFValueError,
PSTypeError,
)
from playa.font import PDFFont
from playa.layout import (
Color,
LTChar,
Expand All @@ -35,31 +37,23 @@
LTRect,
PDFGraphicState,
)
from playa.color import PREDEFINED_COLORSPACE, PDFColorSpace
from playa.font import (
PDFFont,
)
from playa.parser import Parser, PSBaseParserToken, PSStackType
from playa.pdftypes import (
KWD,
LIT,
LITERALS_ASCII85_DECODE,
ObjRef,
ContentStream,
ObjRef,
PSKeyword,
PSLiteral,
dict_value,
int_value,
keyword_name,
list_value,
literal_name,
resolve1,
stream_value,
)
from playa.psparser import (
KWD,
LIT,
Parser,
PSBaseParserToken,
PSKeyword,
PSLiteral,
PSStackType,
keyword_name,
literal_name,
)
from playa.utils import (
MATRIX_IDENTITY,
Matrix,
Expand Down
Loading

0 comments on commit 8aaf9ab

Please sign in to comment.