Explorar el Código

chore: rm password

Byaidu hace 1 año
padre
commit
1e1335b900
Se han modificado 2 ficheros con 18 adiciones y 29 borrados
  1. 18 22
      pdf2zh/high_level.py
  2. 0 7
      pdf2zh/pdf2zh.py

+ 18 - 22
pdf2zh/high_level.py

@@ -14,7 +14,7 @@ from pdf2zh.converter import TranslateConverter
 from pdf2zh.pdfinterp import PDFPageInterpreterEx
 from pdf2zh.doclayout import DocLayoutModel
 from pathlib import Path
-from typing import Any, Iterable, List
+from typing import Any, List, Optional
 import urllib.request
 import requests
 import tempfile
@@ -73,8 +73,7 @@ def check_files(files: List[str]) -> List[str]:
 
 def translate_patch(
     inf: BinaryIO,
-    pages=None,
-    password: str = "",
+    pages: Optional[list[int]] = None,
     vfont: str = "",
     vchar: str = "",
     thread: int = 0,
@@ -102,7 +101,7 @@ def translate_patch(
         total_pages = doc_zh.page_count
 
     parser = PDFParser(inf)
-    doc = PDFDocument(parser, password=password)
+    doc = PDFDocument(parser)
     with tqdm.tqdm(total=total_pages) as progress:
         for pageno, page in enumerate(PDFPage.create_pages(doc)):
             if pages and (pageno not in pages):
@@ -153,16 +152,14 @@ def translate_patch(
 
 
 def translate_stream(
-    stream,
-    pages=None,
-    password: str = "",
-    vfont: str = "",
-    vchar: str = "",
-    thread: int = 0,
-    doc_zh: Document = None,
+    stream: bytes,
+    pages: Optional[list[int]] = None,
     lang_in: str = "",
     lang_out: str = "",
     service: str = "",
+    thread: int = 0,
+    vfont: str = "",
+    vchar: str = "",
     callback: object = None,
     **kwarg: Any,
 ):
@@ -187,8 +184,6 @@ def translate_stream(
         font_list.append(("china-ss", None))
 
     doc_en = Document(stream=stream)
-    if doc_en.is_encrypted:
-        doc_en.authenticate(password)
     doc_zh = Document(stream=stream)
     page_count = doc_zh.page_count
     # font_list = [("china-ss", None), ("tiro", None)]
@@ -232,16 +227,15 @@ def translate_stream(
 
 
 def translate(
-    files: Iterable[str] = [],
+    files: list[str],
     output: str = "",
-    pages=None,
-    password: str = "",
-    vfont: str = "",
-    vchar: str = "",
-    thread: int = 0,
+    pages: Optional[list[int]] = None,
     lang_in: str = "",
     lang_out: str = "",
     service: str = "",
+    thread: int = 0,
+    vfont: str = "",
+    vchar: str = "",
     callback: object = None,
     **kwarg: Any,
 ):
@@ -280,9 +274,11 @@ def translate(
         doc_raw = open(file, "rb")
         s_raw = doc_raw.read()
         s_mono, s_dual = translate_stream(s_raw, **locals())
-        doc_mono = open(Path(output) / f"{filename}-mono.pdf", "wb")
-        doc_dual = open(Path(output) / f"{filename}-dual.pdf", "wb")
+        file_mono = Path(output) / f"{filename}-mono.pdf"
+        file_dual = Path(output) / f"{filename}-dual.pdf"
+        doc_mono = open(file_mono, "wb")
+        doc_dual = open(file_dual, "wb")
         doc_mono.write(s_mono)
         doc_dual.write(s_dual)
 
-    return
+    return str(file_mono), str(file_dual)

+ 0 - 7
pdf2zh/pdf2zh.py

@@ -45,13 +45,6 @@ def create_parser() -> argparse.ArgumentParser:
         type=str,
         help="The list of page numbers to parse.",
     )
-    parse_params.add_argument(
-        "--password",
-        "-P",
-        type=str,
-        default="",
-        help="The password to use for decrypting PDF file.",
-    )
     parse_params.add_argument(
         "--vfont",
         "-f",