code: def rst_to_html(in_rst, stderr):
    
    if not in_rst:
      return '', 0
  
    # Unfortunately, docutils is really setup for command line use.
    # We're forced to patch the bits of sys its hardcoded to use so that we can call it in-process
    # and still reliably determine errors.
    # TODO(John Sirois): Move to a subprocess execution model utilizing a docutil chroot/pex.
    orig_sys_exit = sys.exit
    orig_sys_stderr = sys.stderr
    returncodes = []
    try:
      sys.exit = returncodes.append
      sys.stderr = stderr
      pp = publish_parts(in_rst,
                         writer_name='html',
                         # Report and exit at level 2 (warnings) or higher.
                         settings_overrides=dict(exit_status_level=2, report_level=2),
                         enable_exit_status=True)
    finally:
      sys.exit = orig_sys_exit
      sys.stderr = orig_sys_stderr
  
    return_value = ''
    if 'title' in pp and pp['title']:
      return_value += '<title>{0}</title>\n<p style="font: 200% bold">{0}</p>\n'.format(pp['title'])
    return_value += pp['body'].strip()
    return return_value, returncodes.pop() if returncodes else 0
docs: Renders HTML from an RST fragment.
  
    :param string in_rst: An rst formatted string.
    :param stderr: An open stream to use for docutils stderr output.
    :returns: A tuple of (html rendered rst, return code)