def indent_text(text, indent):
 regex = re.compile('(\\\\*)("""|\'\'\')')
 res = []
 in_quote = None
 for line in text.splitlines():
  if in_quote:
   res.append(line)
  else:
   res.append((indent + line))
  while line:
   match = regex.search(line)
   if match:
    if ((len(match.group(1)) % 2) == 0):
     if (not in_quote):
      in_quote = match.group(2)[0]
     elif (in_quote == match.group(2)[0]):
      in_quote = None
    line = line[match.end():]
   else:
    break
 return '\n'.join(res)

def indent_text ( text , indent ) : regex = re . compile ( '(\\\\*)("""|\'\'\')' ) res = [ ] in_quote = None for line in text . splitlines ( ) : if in_quote : res . append ( line ) else : res . append ( ( indent + line ) ) while line : match = regex . search ( line ) if match : if ( ( len ( match . group ( 1 ) ) % 2 ) == 0 ) : if ( not in_quote ) : in_quote = match . group ( 2 ) [ 0 ] elif ( in_quote == match . group ( 2 ) [ 0 ] ) : in_quote = None line = line [ match . end ( ) : ] else : break return '\n' . join ( res )
indent given lines of python code avoiding indenting multiline quoted content .