Example #1
0
 def check(self, url):
     if self.whitelist is None and self.blacklist is None:
         GLog.fatal("You should input whitelist or blacklist at least")
         return 0
     v1 = 0
     if self.whitelist is not None:
         v1 = self.check_by_whitelist(url)
     v2 = 0
     if self.blacklist is not None:
         v2 = self.check_by_blacklist(url)
     if v1 + v2 == 0:
         return (0, '')
     else:
         return (1, self.err_msg)
Example #2
0
    def check_url(self, url):
        #使用所有的checker检查某个url
        parent = url.parent if isinstance(url, URL) else None
        url = url.url if isinstance(url, URL) else url
        GLog.debug("Checking url: %s", url)

        failed_checker = 0
        for checker in self.checkers:
            failed_checker += checker.check(url)
        #如果所有checker检查返回0(正常),直接返回0
        if failed_checker == 0:
            return 0
        #有checker检查失败了
        if not self.is_white_url(url):
            GLog.fatal("URL check failed: %s, parent url: %s", url, parent)
            return 1
        else:
            GLog.warning("URL check failed: %s, parent url: %s", url, parent)
            return 0