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

def _batch_insert(self, inserts, intervals, **kwargs):
    '''
    Specialized batch insert
    '''
    if 'pipeline' in kwargs:
      pipe = kwargs.get('pipeline')
      own_pipe = False
    else:
      pipe = self._client.pipeline(transaction=False)
      kwargs['pipeline'] = pipe
      own_pipe = True

    ttl_batch = set()
    for timestamp,names in inserts.iteritems():
      for name,values in names.iteritems():
        for value in values:
          # TODO: support config param to flush the pipe every X inserts
          self._insert( name, value, timestamp, intervals, ttl_batch=ttl_batch, **kwargs )

    for ttl_args in ttl_batch:
      pipe.expire(*ttl_args)

    if own_pipe:
      kwargs['pipeline'].execute()