44import base64
55import os .path
66import sys
7- import tempfile
87from datetime import datetime
98from pathlib import Path
109from shutil import copy
1110from time import sleep
12- from typing import Optional , List
11+ from typing import Dict , List , Optional
1312
1413import requests
1514from requests import Response
@@ -151,25 +150,28 @@ def get_pdf_from_html(driver, url) -> bytes:
151150 print ("html2pdf: executing print command with ChromeDriver." ) # noqa: T201
152151 result = driver .execute_cdp_cmd ("Page.printToPDF" , calculated_print_options )
153152
154- class Done (Exception ): pass
153+ class Done (Exception ):
154+ pass
155155
156156 datetime_start = datetime .today ()
157157
158- logs = None
158+ logs : List [ Dict [ str , str ]] = []
159159 try :
160160 while True :
161161 logs = driver .get_log ("browser" )
162162 for entry_ in logs :
163163 if "HTML2PDF4DOC time" in entry_ ["message" ]:
164- print ("success: HTML2PDF completed its job." )
164+ print ("success: HTML2PDF completed its job." ) # noqa: T201
165165 raise Done
166166 if (datetime .today () - datetime_start ).total_seconds () > 60 :
167167 raise TimeoutError
168168 sleep (0.5 )
169169 except Done :
170170 pass
171171 except TimeoutError :
172- print ("error: could not receive a successful completion status from HTML2PDF." )
172+ print ( # noqa: T201
173+ "error: could not receive a successful completion status from HTML2PDF."
174+ )
173175 sys .exit (1 )
174176
175177 print ("html2pdf: JS logs from the print session:" ) # noqa: T201
@@ -244,19 +246,15 @@ def main():
244246 type = str ,
245247 help = "Optional path to a cache directory whereto the ChromeDriver is downloaded." ,
246248 )
247- parser .add_argument ("paths" , nargs = '+' , help = "Paths to input HTML file." )
249+ parser .add_argument ("paths" , nargs = "+" , help = "Paths to input HTML file." )
248250 args = parser .parse_args ()
249251
250252 paths : List [str ] = args .paths
251253
252254 path_to_cache_dir : str = (
253255 args .cache_dir
254256 if args .cache_dir is not None
255- else (
256- os .path .join (
257- Path .home (), ".hpdf" , "chromedriver"
258- )
259- )
257+ else (os .path .join (Path .home (), ".hpdf" , "chromedriver" ))
260258 )
261259 driver = create_webdriver (args .chromedriver , path_to_cache_dir )
262260
@@ -265,7 +263,9 @@ def exit_handler():
265263 print ("html2pdf: exit handler: quitting the ChromeDriver." ) # noqa: T201
266264 driver .quit ()
267265
268- assert len (paths ) % 2 == 0 , f"Expecting an even number of input/output path arguments: { paths } ."
266+ assert len (paths ) % 2 == 0 , (
267+ f"Expecting an even number of input/output path arguments: { paths } ."
268+ )
269269 for current_pair_idx in range (0 , 2 , len (paths )):
270270 path_to_input_html = paths [current_pair_idx ]
271271 path_to_output_pdf = paths [current_pair_idx + 1 ]
0 commit comments