def optimal_data_chunks(data, minimum=4):
 data = to_bytestring(data)
 re_repeat = ((six.b('{') + six.text_type(minimum).encode('ascii')) + six.b(',}'))
 num_pattern = re.compile((six.b('\\d') + re_repeat))
 num_bits = _optimal_split(data, num_pattern)
 alpha_pattern = re.compile((((six.b('[') + re.escape(ALPHA_NUM)) + six.b(']')) + re_repeat))
 for (is_num, chunk) in num_bits:
  if is_num:
   (yield QRData(chunk, mode=MODE_NUMBER, check_data=False))
  else:
   for (is_alpha, sub_chunk) in _optimal_split(chunk, alpha_pattern):
    if is_alpha:
     mode = MODE_ALPHA_NUM
    else:
     mode = MODE_8BIT_BYTE
    (yield QRData(sub_chunk, mode=mode, check_data=False))

def optimal_data_chunks ( data , minimum = 4 ) : data = to_bytestring ( data ) re_repeat = ( ( six . b ( '{' ) + six . text_type ( minimum ) . encode ( 'ascii' ) ) + six . b ( ',}' ) ) num_pattern = re . compile ( ( six . b ( '\\d' ) + re_repeat ) ) num_bits = _optimal_split ( data , num_pattern ) alpha_pattern = re . compile ( ( ( ( six . b ( '[' ) + re . escape ( ALPHA_NUM ) ) + six . b ( ']' ) ) + re_repeat ) ) for ( is_num , chunk ) in num_bits : if is_num : ( yield QRData ( chunk , mode = MODE_NUMBER , check_data = False ) ) else : for ( is_alpha , sub_chunk ) in _optimal_split ( chunk , alpha_pattern ) : if is_alpha : mode = MODE_ALPHA_NUM else : mode = MODE_8BIT_BYTE ( yield QRData ( sub_chunk , mode = mode , check_data = False ) )
an iterator returning qrdata chunks optimized to the data content .