(self, urls, platforms, types)
return results
URL lookup against the Safe Browsing API.

        Args:
            urls: URLs
            platforms: platformTypes field of threatInfo
            types: threatTypes field of threatInfo
        Returns:
            Dict of URLs with the hits
URL lookup against the Safe Browsing API.
URL lookup against the Safe Browsing API .
def _do_safebrowsing_lookup(self, urls, platforms, types):
        """URL lookup against the Safe Browsing API.

        Args:
            urls: URLs
            platforms: platformTypes field of threatInfo
            types: threatTypes field of threatInfo
        Returns:
            Dict of URLs with the hits
        """
        results = {}

        api_client = {
            'clientId': self._google_client_id,
            'clientVersion': self._google_client_version,
        }

        for index in range(0, len(urls), self._SAFE_BROWSING_BULK_LIMIT):
            body = {
                'client': api_client,
                'threatInfo': {
                    'platformTypes': platforms,
                    'threatTypes': types,
                    'threatEntryTypes': ['URL'],
                    'threatEntries': [
                        {'url': url}
                        for url in urls[
                            index:index + self._SAFE_BROWSING_BULK_LIMIT]
                    ],
                },
            }

            response = requests.post(
                self._SAFE_BROWSING_THREATMATCHING_ENDPOINT,
                params={'key': self._safebrowsing_api_key},
                json=body,
            )

            try:
                response.raise_for_status()
            except requests.exceptions.HTTPError as e:
                logger.error(e)
                continue

            result = response.json()

            if not result:
                continue

            if 'matches' not in result:
                continue

            for match in result.get('matches'):
                result_url = match.get('threat', {}).get('url')

                if not result_url:
                    continue

                # Removing all key/values that are not defined in
                # the _SAFEBROWSING_ENTRY_KEEP.
                threat_result = match.copy()
                for key in match.keys():
                    if key not in self._SAFEBROWSING_ENTRY_KEEP:
                        threat_result.pop(key)

                results[result_url] = threat_result

        return results
def _do_safebrowsing_lookup ( self , urls , platforms , types ) : results = { } api_client = { 'clientId' : self . _google_client_id , 'clientVersion' : self . _google_client_version , } for index in range ( 0 , len ( urls ) , self . _SAFE_BROWSING_BULK_LIMIT ) : body = { 'client' : api_client , 'threatInfo' : { 'platformTypes' : platforms , 'threatTypes' : types , 'threatEntryTypes' : [ 'URL' ] , 'threatEntries' : [ { 'url' : url } for url in urls [ index : index + self . _SAFE_BROWSING_BULK_LIMIT ] ] , } , } response = requests . post ( self . _SAFE_BROWSING_THREATMATCHING_ENDPOINT , params = { 'key' : self . _safebrowsing_api_key } , json = body , ) try : response . raise_for_status ( ) except requests . exceptions . HTTPError as e : logger . error ( e ) continue result = response . json ( ) if not result : continue if 'matches' not in result : continue for match in result . get ( 'matches' ) : result_url = match . get ( 'threat' , { } ) . get ( 'url' ) if not result_url : continue # Removing all key/values that are not defined in # the _SAFEBROWSING_ENTRY_KEEP. threat_result = match . copy ( ) for key in match . keys ( ) : if key not in self . _SAFEBROWSING_ENTRY_KEEP : threat_result . pop ( key ) results [ result_url ] = threat_result return results