Skip to content

Commit

Permalink
Nox
Browse files Browse the repository at this point in the history
  • Loading branch information
pietermarsman committed Jul 8, 2024
1 parent d01f01a commit 7f75bb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pdfminer/pdfinterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def do_EI(self, obj: PDFStackT) -> None:

def do_Do(self, xobjid_arg: PDFStackT) -> None:
"""Invoke named XObject"""
xobjid = cast(str, literal_name(xobjid_arg))
xobjid = literal_name(xobjid_arg)
try:
xobj = stream_value(self.xobjmap[xobjid])
except KeyError:
Expand Down
18 changes: 11 additions & 7 deletions pdfminer/psparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ def intern(self, name: PSLiteral.NameType) -> _SymbolT:
KEYWORD_DICT_END = KWD(b">>")


def literal_name(x: object) -> str:
def literal_name(x: Any) -> str:
if isinstance(x, PSLiteral):
name = x.name
if isinstance(x.name, str):
return x.name
try:
return str(x.name, "utf-8")
except UnicodeDecodeError:
return str(x.name)
else:
if settings.STRICT:
raise PSTypeError(f"Literal required: {x!r}")
name = x

return str(name)
return str(x)


def keyword_name(x: object) -> Any:
def keyword_name(x: Any) -> Any:
if not isinstance(x, PSKeyword):
if settings.STRICT:
raise PSTypeError("Keyword required: %r" % x)
Expand Down Expand Up @@ -518,12 +521,13 @@ def nexttoken(self) -> Tuple[int, PSBaseParserToken]:


# Stack slots may by occupied by any of:
# * the name of a literal
# * the PSBaseParserToken types
# * list (via KEYWORD_ARRAY)
# * dict (via KEYWORD_DICT)
# * subclass-specific extensions (e.g. PDFStream, PDFObjRef) via ExtraT
ExtraT = TypeVar("ExtraT")
PSStackType = Union[float, bool, PSLiteral, bytes, List, Dict, ExtraT]
PSStackType = Union[str, float, bool, PSLiteral, bytes, List, Dict, ExtraT]
PSStackEntry = Tuple[int, PSStackType[ExtraT]]


Expand Down

0 comments on commit 7f75bb4

Please sign in to comment.