@@ -67,17 +67,22 @@ def __init__(
67
67
self .patent_content : str = ""
68
68
self .parser : Optional [PatentUspto ] = None
69
69
70
- if isinstance (self .path_or_stream , BytesIO ):
71
- while line := self .path_or_stream .readline ().decode ("utf-8" ):
72
- if line .startswith ("<!DOCTYPE" ) or line == "PATN\n " :
73
- self ._set_parser (line )
74
- self .patent_content += line
75
- elif isinstance (self .path_or_stream , Path ):
76
- with open (self .path_or_stream , encoding = "utf-8" ) as file_obj :
77
- while line := file_obj .readline ():
70
+ try :
71
+ if isinstance (self .path_or_stream , BytesIO ):
72
+ while line := self .path_or_stream .readline ().decode ("utf-8" ):
78
73
if line .startswith ("<!DOCTYPE" ) or line == "PATN\n " :
79
74
self ._set_parser (line )
80
75
self .patent_content += line
76
+ elif isinstance (self .path_or_stream , Path ):
77
+ with open (self .path_or_stream , encoding = "utf-8" ) as file_obj :
78
+ while line := file_obj .readline ():
79
+ if line .startswith ("<!DOCTYPE" ) or line == "PATN\n " :
80
+ self ._set_parser (line )
81
+ self .patent_content += line
82
+ except Exception as exc :
83
+ raise RuntimeError (
84
+ f"Could not initialize USPTO backend for file with hash { self .document_hash } ."
85
+ ) from exc
81
86
82
87
def _set_parser (self , doctype : str ) -> None :
83
88
doctype_line = doctype .lower ()
0 commit comments