'Remove fields from an oplog entry that should not be replicated.
NOTE: this does not support array indexing, for example \'a.b.2\''

def filter_oplog_entry(self, entry, include_fields=None, exclude_fields=None):

    if ((not include_fields) and (not exclude_fields)):
        return entry
    elif include_fields:
        filter_fields = self._copy_included_fields
    else:
        filter_fields = self._pop_excluded_fields
    fields = (include_fields or exclude_fields)
    entry_o = entry['o']
    if (entry['op'] == 'i'):
        entry['o'] = filter_fields(entry_o, fields)
    elif ((entry['op'] == 'u') and (('$set' in entry_o) or ('$unset' in entry_o))):
        if ('$set' in entry_o):
            entry['o']['$set'] = filter_fields(entry_o['$set'], fields, update=True)
        if ('$unset' in entry_o):
            entry['o']['$unset'] = filter_fields(entry_o['$unset'], fields, update=True)
        if (('$set' in entry_o) and (not entry_o['$set'])):
            entry_o.pop('$set')
        if (('$unset' in entry_o) and (not entry_o['$unset'])):
            entry_o.pop('$unset')
        if (not entry_o):
            return None
    elif (entry['op'] == 'u'):
        entry['o'] = filter_fields(entry_o, fields)
    return entry
