コード例 #1
0
    def run(self):

        try:

            config = UrlSpanSettings()

            bodyLength = len(self.body)
            print ("content-length: %s" % str(bodyLength))

            headers = {'user-agent': config.getUserAgent(), 'content-type': self.contentType, 'accept': self.accept}

            # request the raw response
            print "sending request to httplib2..."
            resp, content = httplib2.Http().request(self.url, self.method, headers=headers, body=self.body)
            print "received response from httplib2..."
        
            # parse the response
            self.respContent = content
            self.respStatus = resp['status']
            self.respContentLength = len(self.respContent)
            self.respContentType = resp['content-type']

        except Exception, e:
            print "Error in run()"
            self.error = e.message
コード例 #2
0
    def run(self):

        try:

            config = UrlSpanSettings()

            bodyLength = len(self.body)
            print("content-length: %s" % str(bodyLength))

            headers = {
                'user-agent': config.getUserAgent(),
                'content-type': self.contentType,
                'accept': self.accept
            }

            # request the raw response
            print "sending request to httplib2..."
            resp, content = httplib2.Http().request(self.url,
                                                    self.method,
                                                    headers=headers,
                                                    body=self.body)
            print "received response from httplib2..."

            # parse the response
            self.respContent = content
            self.respStatus = resp['status']
            self.respContentLength = len(self.respContent)
            self.respContentType = resp['content-type']

        except Exception, e:
            print "Error in run()"
            self.error = e.message
コード例 #3
0
class PreferencesUrlSpanDialog(PreferencesDialog):
    __gtype_name__ = "PreferencesUrlSpanDialog"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the preferences dialog"""
        super(PreferencesUrlSpanDialog, self).finish_initializing(builder)

        # Code for other intialization actions should be added here.
        self.cc = UrlSpanSettings()

        cmbUserAgent = self.builder.get_object("cmbUserAgent")       
        self.setComboBoxByValue(cmbUserAgent, self.cc.getUserAgent())

        cmbAccept = self.builder.get_object("cmbAccept")
        self.setComboBoxByValue(cmbAccept, self.cc.getAccept())

    def setComboBoxByValue(self, cmb, val):

        # default to something sensible
        cmb.set_active(0)

        # try to match on the method val
        model = cmb.get_model()
        iterTree = model.get_iter_first()

        for i, k in enumerate(model):
            itr = model.get_iter(i)
            title = model.get_value(itr, 0)

            if title == val:
                cmb.set_active(i)
                break

        
    def on_btnCancel_clicked(self, widget):
        self.destroy()

    def on_btnOk_clicked(self, widget):
        cmbUserAgent = self.builder.get_object("cmbUserAgent")
       
        if cmbUserAgent.get_active_text() != None:
            agent = cmbUserAgent.get_active_text()
            self.cc.setUserAgent(agent)

        cmbAccept = self.builder.get_object("cmbAccept")
       
        if cmbAccept.get_active_text() != None:
            accept = cmbAccept.get_active_text()
            self.cc.setAccept(accept)

        self.cc.save()
        self.destroy()