Exemplo n.º 1
0
def write_output(results, arguments):
    """Format data based on the type.

    :param results: Result data from one of the various calls
    :param arguments: Supplied arguments from the CLI
    :return: Formatted list of output data
    """
    if arguments.cmd == 'pdns':
        if not arguments.format:
            arguments.format = 'table'
        if not arguments.unique:
            data = DnsResponse.process(results)
        else:
            data = DnsUniqueResponse.process(results)

        data = [getattr(data, arguments.format)]

    elif arguments.cmd == 'whois':
        if not arguments.format:
            arguments.format = 'text'
        if not arguments.field:
            tmp = WhoisResponse.process(results)
            data = [getattr(tmp, arguments.format)]
        else:
            data = list()
            results = WhoisSearchResponse(results)
            for record in results.get_records():
                data.append(getattr(record, arguments.format))

    elif arguments.cmd == 'ssl':
        if not arguments.format:
            arguments.format = 'text'
        if not arguments.type:
            tmp = SslResponse.process(results)
            data = [getattr(tmp, arguments.format)]
        elif arguments.type == 'search':
            data = list()
            for record in results.get('records', []):
                tmp = SslResponse.process(record)
                data.append(getattr(tmp, arguments.format))
        else:
            tmp = SslHistoryResponse.process(results)
            data = [getattr(tmp, arguments.format)]

    elif arguments.cmd == 'attribute':
        if not arguments.format:
            arguments.format = 'table'
        tmp = AttributeResponse.process(results)
        data = [getattr(tmp, arguments.format)]

    else:
        return [str(results)]

    return data
Exemplo n.º 2
0
 def test_process_whois_search(self):
     """Test processing search results."""
     payload = {'query': '18772064254', 'field': 'phone'}
     response = self.client.search_whois_by_field(**payload)
     results = WhoisSearchResponse(response)
     assert (results.get_records()[0].domain) == 'passivetotal.org'