Ejemplo n.º 1
0
def gethash_view(request):
    try:
        parsed = parse_gethash(request)
    except ParseError as e:
        annotate_request(request, "shavar.gethash.unknown.format", 1)
        raise HTTPBadRequest(str(e))

    full = lookup_prefixes(request, parsed)

    # Nothing found?  Return a 204
    if len(full) == 0:
        return HTTPNoContent()

    # FIXME MAC handling
    body = b''
    for lname, chunk_data in full.items():
        for chunk_num, hashes in sorted(chunk_data.items()):
            h = b''.join(hashes)
            body += '{list_name}:{chunk_number}:{data_len}\n' \
                .format(list_name=lname, chunk_number=chunk_num,
                        data_len=len(h)).encode()
            body += h

    return HTTPOk(content_type="application/octet-stream", body=body)
Ejemplo n.º 2
0
 def test_1_lookup_prefixes(self):
     dumdum = dummy(body='4:4\n%s' % hashes['goog'][:4], path='/gethash')
     prefixes = lookup_prefixes(dumdum, [self.hg[:4]])
     self.assertEqual(prefixes, {'moz-abp-shavar': {17: [hashes['goog']]}})
Ejemplo n.º 3
0
                data = 'u:{0}\n'.format(fudge)
            body += data
    return body


#
# gethash
#
def gethash_view(request):
    try:
        parsed = parse_gethash(request)
    except ParseError, e:
        annotate_request(request, "shavar.gethash.unknown.format", 1)
        raise HTTPBadRequest(str(e))

    full = lookup_prefixes(request, parsed)

    # Nothing found?  Return a 204
    if len(full) == 0:
        return HTTPNoContent()

    # FIXME MAC handling
    body = ''
    for lname, chunk_data in full.items():
        for chunk_num, hashes in chunk_data.iteritems():
            h = ''.join(hashes)
            body += '{list_name}:{chunk_number}:{data_len}\n{data}' \
                .format(list_name=lname, chunk_number=chunk_num,
                        data_len=len(h), data=h)

    return HTTPOk(content_type="application/octet-stream", body=body)
Ejemplo n.º 4
0
 def test_1_lookup_prefixes(self):
     dumdum = dummy(body='4:4\n%s' % hashes['goog'][:4], path='/gethash')
     prefixes = lookup_prefixes(dumdum, [self.hg[:4]])
     self.assertEqual(prefixes, {'moz-abp-shavar': {17: [hashes['goog']]}})
Ejemplo n.º 5
0
                data = 'u:{0}\n'.format(fudge)
            body += data
    return body


#
# gethash
#
def gethash_view(request):
    try:
        parsed = parse_gethash(request)
    except ParseError, e:
        annotate_request(request, "shavar.gethash.unknown.format", 1)
        raise HTTPBadRequest(str(e))

    full = lookup_prefixes(request, parsed)

    # Nothing found?  Return a 204
    if len(full) == 0:
        return HTTPNoContent()

    # FIXME MAC handling
    body = ''
    for lname, chunk_data in full.items():
        for chunk_num, hashes in chunk_data.iteritems():
            h = ''.join(hashes)
            body += '{list_name}:{chunk_number}:{data_len}\n{data}' \
                .format(list_name=lname, chunk_number=chunk_num,
                        data_len=len(h), data=h)

    return HTTPOk(content_type="application/octet-stream", body=body)