Skip to content

Commit

Permalink
support old Python without typing.Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabu committed Sep 3, 2021
1 parent dc24508 commit 893b9fb
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pdfminer/pdftypes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import zlib
import logging
from typing import (TYPE_CHECKING, Any, Dict, Iterable, Optional, Protocol,
Union, List, Tuple, cast)
import sys
from typing import (TYPE_CHECKING, Any, Dict, Iterable, Optional, Union, List,
Tuple, cast)
from .lzw import lzwdecode
from .ascii85 import ascii85decode
from .ascii85 import asciihexdecode
Expand Down Expand Up @@ -32,10 +33,16 @@
LITERALS_JBIG2_DECODE = (LIT('JBIG2Decode'),)


class DecipherCallable(Protocol):
def __call__(self, objid: int, genno: int, data: bytes,
attrs: Optional[Dict[str, Any]] = None) -> bytes:
raise NotImplementedError
if sys.version_info >= (3, 8):
from typing import Protocol
class DecipherCallable(Protocol):
"""Fully typed a decipher callback, with optional parameter."""
def __call__(self, objid: int, genno: int, data: bytes,
attrs: Optional[Dict[str, Any]] = None) -> bytes:
raise NotImplementedError
else: # Fallback for older Python
from typing import Callable
DecipherCallable = Callable[..., bytes]


class PDFObject(PSObject):
Expand Down

0 comments on commit 893b9fb

Please sign in to comment.