diff --git a/pdfmajor/execptions.py b/pdfmajor/execptions.py index ac60c68..fa8cdf6 100644 --- a/pdfmajor/execptions.py +++ b/pdfmajor/execptions.py @@ -48,6 +48,23 @@ class CMapNotFound(ParserError): class PSException(ParserError): pass +class PDFValueError(ParserError): + pass + +class PDFObjectNotFound(ParserError): + pass + +class PDFException(ParserError): + pass + +class PDFTypeError(PDFException): + pass + +class PDFSyntaxError(PDFException): + pass + +class PDFTextExtractionNotAllowed(PDFException): + pass class PSEOF(PSException): pass diff --git a/pdfmajor/interpreter/commands/state/PDFTextState/PDFFont/Type1FontHeaderParser.py b/pdfmajor/interpreter/commands/state/PDFTextState/PDFFont/Type1FontHeaderParser.py index 498a952..bb4122e 100644 --- a/pdfmajor/interpreter/commands/state/PDFTextState/PDFFont/Type1FontHeaderParser.py +++ b/pdfmajor/interpreter/commands/state/PDFTextState/PDFFont/Type1FontHeaderParser.py @@ -1,5 +1,6 @@ +from pdfmajor.execptions import PSEOF from pdfmajor.parser.PSStackParser import PSStackParser -from pdfmajor.parser.PSStackParser import PSEOF, KWD +from pdfmajor.parser.PSStackParser import KWD from pdfmajor.parser.PSStackParser import PSLiteral from pdfmajor.parser.PSStackParser import literal_name from pdfmajor.parser.EncodingDB import name2unicode diff --git a/pdfmajor/parser/PDFDocument/PDFXRef.py b/pdfmajor/parser/PDFDocument/PDFXRef.py index cb2bdaa..07b507e 100644 --- a/pdfmajor/parser/PDFDocument/PDFXRef.py +++ b/pdfmajor/parser/PDFDocument/PDFXRef.py @@ -2,7 +2,7 @@ import re from logging import getLogger from typing import Tuple, Optional, Dict -from pdfmajor.execptions import PSEOF +from pdfmajor.execptions import PSEOF, PDFSyntaxError from ...utils import settings, choplist, nunpack from ..PSStackParser import KWD @@ -105,7 +105,7 @@ class PDFXRef(PDFBaseXRef): try: return self.offsets[objid] except KeyError: - raise PDFSyntaxError + raise ## PDFXRefFallback diff --git a/pdfmajor/parser/PDFDocument/__init__.py b/pdfmajor/parser/PDFDocument/__init__.py index 4130649..44790cb 100644 --- a/pdfmajor/parser/PDFDocument/__init__.py +++ b/pdfmajor/parser/PDFDocument/__init__.py @@ -8,16 +8,18 @@ from pdfmajor.execptions import ( ParserError, PDFNoOutlines, PDFDestinationNotFound, - PDFNoValidXRef + PDFNoValidXRef, + PSEOF, + PDFObjectNotFound, + PDFTypeError, + PDFSyntaxError ) from ...utils import settings, choplist, decode_text from ..PSStackParser import KWD from ..PSStackParser import literal_name -from ..PSStackParser import PSEOF from ..PDFStream import int_value, str_value, dict_value, list_value, decipher_all -from ..PDFStream import PDFObjectNotFound, PDFTypeError -from ..PDFParser import PDFStreamParser, PDFStream, PDFSyntaxError +from ..PDFParser import PDFStreamParser, PDFStream from .PDFSecurityHandler import PDFStandardSecurityHandler from .PDFSecurityHandler import PDFStandardSecurityHandlerV4 diff --git a/pdfmajor/parser/PDFPage.py b/pdfmajor/parser/PDFPage.py index 60980aa..c9844e9 100644 --- a/pdfmajor/parser/PDFPage.py +++ b/pdfmajor/parser/PDFPage.py @@ -1,13 +1,12 @@ import logging -from ..execptions import PDFTextExtractionNotAllowed +from pdfmajor.execptions import PDFTextExtractionNotAllowed, PDFObjectNotFound from ..utils import settings from .constants import LIT -from .PDFStream import PDFObjectNotFound from .PDFStream import resolve1, int_value, list_value, dict_value from .PDFParser import PDFParser -from .PDFDocument import PDFDocument, PDFTextExtractionNotAllowed +from .PDFDocument import PDFDocument from ..utils import get_logger diff --git a/pdfmajor/parser/PDFParser.py b/pdfmajor/parser/PDFParser.py index 0610dd1..daf443d 100644 --- a/pdfmajor/parser/PDFParser.py +++ b/pdfmajor/parser/PDFParser.py @@ -5,10 +5,10 @@ from ..utils import settings from pdfmajor.execptions import ( PSSyntaxError, PSEOF, + PDFSyntaxError ) from .PSStackParser import PSStackParser from .PSStackParser import KWD -from .PDFStream import PDFException from .PDFStream import PDFStream from .PDFStream.PDFObjRef import PDFObjRef from .PDFStream import int_value @@ -17,11 +17,6 @@ from .PDFStream import dict_value log = logging.getLogger(__name__) -## Exceptions -## -class PDFSyntaxError(PDFException): - pass - ## PDFParser ## diff --git a/pdfmajor/parser/PDFStream/PDFObjRef.py b/pdfmajor/parser/PDFStream/PDFObjRef.py index 2d7652e..78b053e 100644 --- a/pdfmajor/parser/PDFStream/PDFObjRef.py +++ b/pdfmajor/parser/PDFStream/PDFObjRef.py @@ -1,6 +1,6 @@ import zlib -from ..PSStackParser import PSException +from pdfmajor.execptions import PDFValueError, PDFObjectNotFound from ..PSStackParser import PSObject from ...utils import lzwdecode, settings diff --git a/pdfmajor/parser/PSStackParser/__init__.py b/pdfmajor/parser/PSStackParser/__init__.py index e8b4d5c..7b790f1 100644 --- a/pdfmajor/parser/PSStackParser/__init__.py +++ b/pdfmajor/parser/PSStackParser/__init__.py @@ -1,7 +1,7 @@ import logging from io import TextIOWrapper -from pdfmajor.execptions import PSSyntaxError, PSTypeError +from pdfmajor.execptions import PSSyntaxError, PSTypeError, PSEOF from ...utils import choplist, settings diff --git a/tests/pdfmajor b/tests/pdfmajor deleted file mode 120000 index 0b558f8..0000000 --- a/tests/pdfmajor +++ /dev/null @@ -1 +0,0 @@ -../pdfmajor \ No newline at end of file diff --git a/tests/test_bad_unicode.py b/tests/test_bad_unicode.py index fb986ce..fcaf674 100644 --- a/tests/test_bad_unicode.py +++ b/tests/test_bad_unicode.py @@ -1,7 +1,8 @@ from pathlib import Path from unittest import TestCase, main -from pdfmajor.interpreter import PDFInterpreter, exceptions +from pdfmajor.interpreter import PDFInterpreter +from pdfmajor.execptions import UnicodeNotDefined CURRENT_FOLDER = Path("./") @@ -9,7 +10,7 @@ class BadUnicode(TestCase): def test_ensure_failure(self): pdf = PDFInterpreter(CURRENT_FOLDER / "tests" / "samples" / "pdf" / "bad-unicode.pdf", ignore_bad_chars=False) pages = list(pdf) - with self.assertRaises(exceptions.PDFUnicodeNotDefined): + with self.assertRaises(UnicodeNotDefined): list(pages[2]) def test_ensure_no_failure(self): diff --git a/tests/test_pdfmajor_psparser.py b/tests/test_pdfmajor_psparser.py index eeab634..76f976f 100644 --- a/tests/test_pdfmajor_psparser.py +++ b/tests/test_pdfmajor_psparser.py @@ -5,7 +5,8 @@ import logging from unittest import TestCase, main from io import BytesIO -from pdfmajor.parser.PSStackParser import KWD, LIT, PSBaseParser, PSEOF, PSStackParser +from pdfmajor.parser.PSStackParser import KWD, LIT, PSBaseParser, PSStackParser +from pdfmajor.execptions import PSEOF ## Simplistic Test cases ##