def chunk_xml(xml, depth=0):
 data = etree.tostring(xml)
 content_length = len(data)
 if (content_length < _CHUNK_SIZE):
  (yield data)
 else:
  depth += 1
  print ('WARNING: Chunking (depth=%s)' % depth)
  half = (len(xml) / 2)
  left_half = xml
  right_half = etree.Element('batch')
  right_half.extend(xml[half:])
  for chunk in chunk_xml(left_half, depth=depth):
   (yield chunk)
  for chunk in chunk_xml(right_half, depth=depth):
   (yield chunk)

def chunk_xml ( xml , depth = 0 ) : data = etree . tostring ( xml ) content_length = len ( data ) if ( content_length < _CHUNK_SIZE ) : ( yield data ) else : depth += 1 print ( 'WARNING: Chunking (depth=%s)' % depth ) half = ( len ( xml ) / 2 ) left_half = xml right_half = etree . Element ( 'batch' ) right_half . extend ( xml [ half : ] ) for chunk in chunk_xml ( left_half , depth = depth ) : ( yield chunk ) for chunk in chunk_xml ( right_half , depth = depth ) : ( yield chunk )
chunk post data into pieces that are smaller than the 20 mb limit .