def extract_eliot_from_twisted_log(twisted_log_line):
 open_brace = twisted_log_line.find('{')
 close_brace = twisted_log_line.rfind('}')
 if ((open_brace == (-1)) or (close_brace == (-1))):
  return None
 candidate = twisted_log_line[open_brace:(close_brace + 1)]
 try:
  fields = json.loads(candidate)
 except (ValueError, TypeError):
  return None
 if {'task_uuid', 'timestamp'}.difference(fields):
  return None
 return candidate

def extract_eliot_from_twisted_log ( twisted_log_line ) : open_brace = twisted_log_line . find ( '{' ) close_brace = twisted_log_line . rfind ( '}' ) if ( ( open_brace == ( - 1 ) ) or ( close_brace == ( - 1 ) ) ) : return None candidate = twisted_log_line [ open_brace : ( close_brace + 1 ) ] try : fields = json . loads ( candidate ) except ( ValueError , TypeError ) : return None if { 'task_uuid' , 'timestamp' } . difference ( fields ) : return None return candidate
given a line from a twisted log message .