Fetches CallDescriptor from the local database given a hash key representing the call. If it doesn't exist returns None.

    :param str hash: The sha1 hexdigest to look the CallDescriptor up by.

    :rtype: CallDescriptor corresponding to the hash passed or None if it wasn't found.

def fetch( call_hash ):
    """
    Fetches CallDescriptor from the local database given a hash key representing the call. If it doesn't exist returns None.

    :param str hash: The sha1 hexdigest to look the CallDescriptor up by.

    :rtype: CallDescriptor corresponding to the hash passed or None if it wasn't found.
    """
    res = select_expected_value(call_hash)
    if not res:
        return None

    last_packet_number = -1
    expected_value = ""
    for packet in res:
        call_hash, expected_value_fragment, packet_num = packet
        expected_value += expected_value_fragment
        if packet_num <= last_packet_number:
            raise Exception("Received expected_value data out of order!")

        last_packet_number = packet_num

    return ExpectedValue( call_hash      = call_hash,
                          expected_value = pickle.loads(str(expected_value)) )