def Parse(self): if (self.Status != ListStatus.Success): Logger.LogInfo("Will not parse list {0}: Staus is {1} ".format( self.LocalName, self.Status)) return False if (self.MimeType == MimeType.Pdf): self.TSLType = TrustListType.Pdf Logger.LogInfo("Ignoring file {0}".format(self.LocalName)) return False try: tree = ET.parse(self.LocalPath) node = tree.find(TrustList.xpOperatorTeritory) self.OperatorTeritory = node.text node = tree.find(TrustList.xpVersion) self.TypeVersion = node.text if (self.TypeVersion != "5"): Logger.logError( "Will not parse list {0}. it has an unknown type version {1}" .format(self.LocalName, self.TypeVersion)) self.Status = ListStatus.StructureError return False node = tree.find(TrustList.xpSqNumber) self.SeqNumber = node.text # After Brexit, UK lists have an empty NextUpdate node = tree.find(TrustList.xpNextUpdate) self.NextUpdate = node.text if node is not None else "" node = tree.find(TrustList.xpType) self.TSLType = TrustListType.get_type_from_string(node.text) node = tree.find(TrustList.xpOperatorName) self.OperatorName = node.text except AttributeError as ex: Logger.LogException( "Failed to parse list {0}".format(self.LocalName), ex) self.Status = ListStatus.StructureError return False if (self.TSLType == TrustListType.ListOfTheLists): self.__parse_list_of_lists(tree) elif (self.TSLType == TrustListType.Generic): self.__parse_list_of_generic(tree) return True
def Download(self, localwd, force): if (self.UrlLocation is None): raise "TrustList.Download failed: Url is empty" self.ForceDownload = force self.LocalWD = localwd self.LocalPath = localwd / self.LocalName try: Logger.LogInfo("Downloading file {0} ...".format(self.UrlLocation)) download_file(self.UrlLocation, self.LocalPath, force) self.Status = ListStatus.Success except urllib.error.URLError as ex: self.Status = ListStatus.NotDownloaded Logger.LogException( "Failed to download list {0}".format(self.UrlLocation), ex)