request2doc_gui.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:request2doc 作者: kongxinchi 项目源码 文件源码
def on_request_transform_button_click(self, event):
        url = self.url_text.GetValue()
        method = self.method_choice.GetStringSelection()
        params_value = self.post_params_text.GetValue()
        headers_value = self.headers_text.GetValue()
        slice_startswith = self.slice_text.GetValue()
        template_path = self.get_template_path()

        request_forms = {k: v[0] for k, v in urlparse.parse_qs(params_value).items()}
        headers = headers_value.split('\n')
        handler = Request2Doc(url, method, request_forms)
        if slice_startswith:
            handler.set_slice_startswith(slice_startswith)
        if headers:
            handler.set_headers(headers)

        try:
            if not handler.validate():
                return wx.MessageDialog(None, handler.error_message(), u"Info", wx.OK | wx.ICON_INFORMATION).ShowModal()

            handler.request()

            if not handler.get_response_data():
                return wx.MessageDialog(None, u'Response body is not legal format', u"Information", wx.OK | wx.ICON_INFORMATION).ShowModal()

            res = handler.render_string(template_path)
            self.GetParent().set_response_content(json.dumps(handler.get_response_data(), indent=2))
            self.GetParent().set_document_content(res)

        except Exception, e:
            return wx.MessageDialog(None, traceback.format_exc(), u"Exception", wx.OK | wx.ICON_ERROR).ShowModal()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号