Example #1
0
def test_custom_views():
    class ViewNoop(cv.View):
        name = "noop"
        prompt = ("noop", "n")
        content_types = ["text/none"]

        def __call__(self, data, **metadata):
            return "noop", cv.format_text(data)

    view_obj = ViewNoop()

    cv.add(view_obj)

    assert cv.get("noop")

    r = cv.get_content_view(cv.get("noop"),
                            "[1, 2, 3]",
                            headers=Headers(content_type="text/plain"))
    assert "noop" in r[0]

    # now try content-type matching
    r = cv.get_content_view(cv.get("Auto"),
                            "[1, 2, 3]",
                            headers=Headers(content_type="text/none"))
    assert "noop" in r[0]

    # now try removing the custom view
    cv.remove(view_obj)
    r = cv.get_content_view(cv.get("Auto"),
                            "[1, 2, 3]",
                            headers=Headers(content_type="text/none"))
    assert "noop" not in r[0]
def test_custom_views():
    class ViewNoop(cv.View):
        name = "noop"
        prompt = ("noop", "n")
        content_types = ["text/none"]

        def __call__(self, data, **metadata):
            return "noop", cv.format_text(data)


    view_obj = ViewNoop()

    cv.add(view_obj)

    assert cv.get("noop")

    r = cv.get_content_view(
        cv.get("noop"),
        "[1, 2, 3]",
        headers=Headers(
            content_type="text/plain"
        )
    )
    assert "noop" in r[0]

    # now try content-type matching
    r = cv.get_content_view(
        cv.get("Auto"),
        "[1, 2, 3]",
        headers=Headers(
            content_type="text/none"
        )
    )
    assert "noop" in r[0]

    # now try removing the custom view
    cv.remove(view_obj)
    r = cv.get_content_view(
        cv.get("Auto"),
        "[1, 2, 3]",
        headers=Headers(
            content_type="text/none"
        )
    )
    assert "noop" not in r[0]
Example #3
0
    def test_get_content_view(self):
        r = cv.get_content_view(
            cv.get("Raw"),
            "[1, 2, 3]",
            headers=Headers(content_type="application/json")
        )
        assert "Raw" in r[0]

        r = cv.get_content_view(
            cv.get("Auto"),
            "[1, 2, 3]",
            headers=Headers(content_type="application/json")
        )
        assert r[0] == "JSON"

        r = cv.get_content_view(
            cv.get("Auto"),
            "[1, 2",
            headers=Headers(content_type="application/json")
        )
        assert "Raw" in r[0]

        tutils.raises(
            ContentViewException,
            cv.get_content_view,
            cv.get("AMF"),
            "[1, 2",
            headers=Headers()
        )

        r = cv.get_content_view(
            cv.get("Auto"),
            encoding.encode('gzip', "[1, 2, 3]"),
            headers=Headers(
                content_type="application/json",
                content_encoding="gzip"
            )
        )
        assert "decoded gzip" in r[0]
        assert "JSON" in r[0]

        r = cv.get_content_view(
            cv.get("XML"),
            encoding.encode('gzip', "[1, 2, 3]"),
            headers=Headers(
                content_type="application/json",
                content_encoding="gzip"
            )
        )
        assert "decoded gzip" in r[0]
        assert "Raw" in r[0]
Example #4
0
    def test_get_content_view(self):
        r = cv.get_content_view(
            cv.get("Raw"),
            "[1, 2, 3]",
            headers=Headers(content_type="application/json")
        )
        assert "Raw" in r[0]

        r = cv.get_content_view(
            cv.get("Auto"),
            "[1, 2, 3]",
            headers=Headers(content_type="application/json")
        )
        assert r[0] == "JSON"

        r = cv.get_content_view(
            cv.get("Auto"),
            "[1, 2",
            headers=Headers(content_type="application/json")
        )
        assert "Raw" in r[0]

        tutils.raises(
            ContentViewException,
            cv.get_content_view,
            cv.get("AMF"),
            "[1, 2",
            headers=Headers()
        )

        r = cv.get_content_view(
            cv.get("Auto"),
            encoding.encode('gzip', "[1, 2, 3]"),
            headers=Headers(
                content_type="application/json",
                content_encoding="gzip"
            )
        )
        assert "decoded gzip" in r[0]
        assert "JSON" in r[0]

        r = cv.get_content_view(
            cv.get("XML"),
            encoding.encode('gzip', "[1, 2, 3]"),
            headers=Headers(
                content_type="application/json",
                content_encoding="gzip"
            )
        )
        assert "decoded gzip" in r[0]
        assert "Raw" in r[0]
    def handle_response(self, f):
        flow.FlowMaster.handle_response(self, f)
        if f:
            f.reply()
            if f.request.path.startswith('/api.php?action=get_player_data'):
                evt = custom_events.wxStatusEvent(message="Got box data, processing...")            
                wx.PostEvent(self.status_ctrl,evt)
                resp = f.response.content
                type, lines = contentviews.get_content_view(
                    contentviews.get("Raw"),
                    f.response.content,
                    headers=f.response.headers)

                def colorful(line):
                    for (style, text) in line:
                        yield text
                        
                content = u"\r\n".join(
                    u"".join(colorful(line)) for line in lines
                )
                
                cap = open('captured_data.txt', 'w')
                cap.write(content)
                cap.close()
                thread.start_new_thread(padherder_sync.do_sync, (content, self.status_ctrl, self.region))
            elif f.request.path.startswith('/api.php?action=get_user_mail'):
                resp = f.response.content
                type, lines = contentviews.get_content_view(
                    contentviews.get("Raw"),
                    f.response.content,
                    headers=f.response.headers)

                def colorful(line):
                    for (style, text) in line:
                        yield text
                        
                content = u"\r\n".join(
                    u"".join(colorful(line)) for line in lines
                )
                
                cap = open('captured_mail.txt', 'w')
                cap.write(content)
                cap.close()
                
                mails = parse_mail(content)
                mails.reverse()
                evt = custom_events.wxMailEvent(mails=mails)
                wx.PostEvent(self.mail_tab, evt)
                evt = custom_events.wxStatusEvent(message="Got mail data, processing...")            
                wx.PostEvent(self.status_ctrl,evt)
            else:
                config = wx.ConfigBase.Get()
                actions = config.Read("customcapture")
                if actions != "" and actions != None:
                    for act in actions.split(','):
                        act = act.strip()
                        if f.request.path.startswith('/api.php?action=%s' % act):
                            resp = f.response.content
                            type, lines = contentviews.get_content_view(
                                contentviews.get("Raw"),
                                f.response.content,
                                headers=f.response.headers)

                            def colorful(line):
                                for (style, text) in line:
                                    yield text
                                    
                            content = u"\r\n".join(
                                u"".join(colorful(line)) for line in lines
                            )
                            
                            cap = open('captured_%s.txt' % act, 'w')
                            cap.write(content)
                            cap.close()
                            
                            evt = custom_events.wxStatusEvent(message="Got custom capture %s" % act)            
                            wx.PostEvent(self.status_ctrl,evt)
                            
                
        return f
    def handle_response(self, f):
        flow.FlowMaster.handle_response(self, f)
        if f:
            f.reply()
            if f.request.path.startswith('/api.php?action=get_player_data'):
                evt = custom_events.wxStatusEvent(
                    message="Got box data, processing...")
                wx.PostEvent(self.status_ctrl, evt)
                resp = f.response.content
                type, lines = contentviews.get_content_view(
                    contentviews.get("Raw"),
                    f.response.content,
                    headers=f.response.headers)

                def colorful(line):
                    for (style, text) in line:
                        yield text

                content = u"\r\n".join(u"".join(colorful(line))
                                       for line in lines)

                cap = open('captured_data.txt', 'w')
                cap.write(content)
                cap.close()
                thread.start_new_thread(
                    padherder_sync.do_sync,
                    (content, self.status_ctrl, self.region))
            elif f.request.path.startswith('/api.php?action=get_user_mail'):
                resp = f.response.content
                type, lines = contentviews.get_content_view(
                    contentviews.get("Raw"),
                    f.response.content,
                    headers=f.response.headers)

                def colorful(line):
                    for (style, text) in line:
                        yield text

                content = u"\r\n".join(u"".join(colorful(line))
                                       for line in lines)

                cap = open('captured_mail.txt', 'w')
                cap.write(content)
                cap.close()

                mails = parse_mail(content)
                mails.reverse()
                evt = custom_events.wxMailEvent(mails=mails)
                wx.PostEvent(self.mail_tab, evt)
                evt = custom_events.wxStatusEvent(
                    message="Got mail data, processing...")
                wx.PostEvent(self.status_ctrl, evt)
            else:
                config = wx.ConfigBase.Get()
                actions = config.Read("customcapture")
                if actions != "" and actions != None:
                    for act in actions.split(','):
                        act = act.strip()
                        if f.request.path.startswith('/api.php?action=%s' %
                                                     act):
                            resp = f.response.content
                            type, lines = contentviews.get_content_view(
                                contentviews.get("Raw"),
                                f.response.content,
                                headers=f.response.headers)

                            def colorful(line):
                                for (style, text) in line:
                                    yield text

                            content = u"\r\n".join(u"".join(colorful(line))
                                                   for line in lines)

                            cap = open('captured_%s.txt' % act, 'w')
                            cap.write(content)
                            cap.close()

                            evt = custom_events.wxStatusEvent(
                                message="Got custom capture %s" % act)
                            wx.PostEvent(self.status_ctrl, evt)

        return f