'Exports a workflow to myExperiment website.'

@web.expose
@web.require_login('use    workflows')
def export_to_myexp(self, trans, id, myexp_username, myexp_password):

    trans.workflow_building_mode = True
    stored = self.get_stored_workflow(trans, id, check_ownership=False, check_accessible=True)
    workflow_dict = self._workflow_to_dict(trans, stored)
    workflow_content = json.dumps(workflow_dict, indent=4, sort_keys=True)
    request_raw = trans.fill_template('workflow/myexp_export.mako', workflow_name=workflow_dict['name'], workflow_description=workflow_dict['annotation'], workflow_content=workflow_content, workflow_svg=self._workflow_to_svg_canvas(trans, stored).tostring())
    request = unicodify(request_raw.strip(), 'utf-8')
    auth_header = base64.b64encode(('%s:%s' % (myexp_username, myexp_password)))
    headers = {'Content-type': 'text/xml', 'Accept': 'text/xml', 'Authorization': ('Basic    %s' % auth_header)}
    myexp_url = trans.app.config.get('myexperiment_url', self.__myexp_url)
    conn = httplib.HTTPConnection(myexp_url)
    conn.request('POST', '/workflow.xml', request, headers)
    response = conn.getresponse()
    response_data = response.read()
    conn.close()
    parser = SingleTagContentsParser('id')
    parser.feed(response_data)
    myexp_workflow_id = parser.tag_content
    workflow_list_str = ("    <br>Return    to    <a    href='%s'>workflow    list." % url_for(controller='workflow', action='list'))
    if myexp_workflow_id:
        return trans.show_message(('Workflow    \'%s\'    successfully    exported    to    myExperiment.    <br/>\n                                                                <a    href="http://%s/workflows/%s">Click    here    to    view    the    workflow    on    myExperiment</a>    %s\n                                                                ' % (stored.name, myexp_url, myexp_workflow_id, workflow_list_str)), use_panels=True)
    else:
        return trans.show_error_message(("Workflow    '%s'    could    not    be    exported    to    myExperiment.    Error:    %s    %s" % (stored.name, response_data, workflow_list_str)), use_panels=True)
