[docs]def__init__(self,file_path:Union[str,Path]):"""Initialize with file path."""self.file_path=str(file_path)if"~"inself.file_path:self.file_path=os.path.expanduser(self.file_path)# If the file is a web path, download it to a temporary file, and use thatifnotos.path.isfile(self.file_path)andself._is_valid_url(self.file_path):r=requests.get(self.file_path)ifr.status_code!=200:raiseValueError("Check the url of your file; returned status code %s"%r.status_code)self.web_path=self.file_pathself.temp_file=tempfile.NamedTemporaryFile()self.temp_file.write(r.content)self.file_path=self.temp_file.nameelifnotos.path.isfile(self.file_path):raiseValueError("File path %s is not a valid file or url"%self.file_path)self.parser=VsdxParser()# type: ignore[misc]
def__del__(self)->None:ifhasattr(self,"temp_file"):self.temp_file.close()@staticmethoddef_is_valid_url(url:str)->bool:"""Check if the url is valid."""parsed=urlparse(url)returnbool(parsed.netloc)andbool(parsed.scheme)