<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def filter_pem(data):
    '''Processes the bytes for PEM certificates.

    Returns:
        ``set`` containing each certificate
    '''
    assert isinstance(data, bytes), 'Expect bytes. Got {}.'.format(type(data))
    certs = set()
    new_list = []
    in_pem_block = False

    for line in re.split(br'[\r\n]+', data):
        if line == b'-----BEGIN CERTIFICATE-----':
            assert not in_pem_block
            in_pem_block = True
        elif line == b'-----END CERTIFICATE-----':
            assert in_pem_block
            in_pem_block = False

            content = b''.join(new_list)
            content = rewrap_bytes(content)

            certs.add(b'-----BEGIN CERTIFICATE-----\n' +
                      content +
                      b'\n-----END CERTIFICATE-----\n')

            new_list = []
        elif in_pem_block:
            new_list.append(line)

    return certs