'Break a PublishableEvent list into chunks to obey size limits.
Note that this yields lists of strings (the serialized data) to
publish directly, not PublishableEvent objects.'

def _chunk_events(self, events):

    to_send = []
    send_size = 0
    for event in events:
        event.truncate_data(self.max_event_size)
        if (len(event) > self.max_event_size):
            g.log.warning('Event    too    large    (%s);    dropping', len(event))
            g.log.warning('%r', event.data)
            g.stats.simple_event('eventcollector.oversize_dropped')
            continue
        send_size += len(event)
        if (len(to_send) > 0):
            send_size += len(',    ')
        if ((send_size + 2) >= self.max_content_length):
            (yield to_send)
            to_send = []
            send_size = len(event)
        to_send.append(event.data)
    if to_send:
        (yield to_send)
