python类getPage()的实例源码

recipe-500263.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def validate(self, data, request):
        # We need only the body
        data = data[data.find('\r\n\r\n') + 4:]

        # Build the request for the validator service, using the
        # original request as the base
        headers = request.received_headers
        data, contentType = encodeFormData(self.arg, data)

        headers['content-type'] = contentType
        headers.pop('cookie', None)
        headers.pop('referer', None)
        headers.pop('host', None)

        return client.getPage(
            self.uri, method='POST', headers=headers, postdata=data 
            )
test_twisted.py 文件源码 项目:Tinychat-Bot--Discontinued 作者: Tinychat 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def doRequest(self, service, body=missing, type=pyamf.AMF3, raw=False,
                  decode=True):
        if not raw:
            if body is self.missing:
                body = []
            else:
                body = [body]

            env = remoting.Envelope(type)
            request = remoting.Request(service, body=body)
            env['/1'] = request

            body = remoting.encode(env).getvalue()

        d = self.getPage(body)

        if decode:
            d.addCallback(lambda result: remoting.decode(result))

        return d
imitation_scrapy.py 文件源码 项目:Spider 作者: Ctrlsman 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _next_request(self):
        while self.start_requests:
            try:
                request = next(self.start_requests)
            except StopIteration:
                self.start_requests = None
            else:
                self.scheduler.enqueue_request(request)

        while len(self.inprogress) < 5 and self.scheduler.size() > 0:  # ??????5

            request = self.scheduler.next_request()
            if not request:
                break

            self.inprogress.add(request)
            d = getPage(bytes(request.url, encoding='utf-8'))
            d.addBoth(self._handle_downloader_output, request)
            d.addBoth(lambda x, req: self.inprogress.remove(req), request)
            d.addBoth(lambda x: self._next_request())

        if len(self.inprogress) == 0 and self.scheduler.size() == 0:
            self._closewait.callback(None)
util.py 文件源码 项目:qualisys_python_sdk 作者: qualisys 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _get_page(self, method, url, data=None):
    try:
        response = yield getPage(url, method=method,
                                 headers={b'Content-Type': b'application/json'},
                                 postdata=data)
    except Error as e:
        raise RestError(int(e.status), e.response)
    except Exception as e:
        raise RestError(-1, str(e))

    try:
        obj = json.loads(response.decode('utf-8'))
    except Exception as e:
        raise RestError(-1, response)

    defer.returnValue(obj)


# rpc wrapper, only usable for QRest class members
test_webclient.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_afterFoundGet(self):
        """
        Enabling unsafe redirection behaviour overwrites the method of
        redirected C{POST} requests with C{GET}.
        """
        url = self.getURL('extendedRedirect?code=302')
        f = client.HTTPClientFactory(url, followRedirect=True, method=b"POST")
        self.assertFalse(
            f.afterFoundGet,
            "By default, afterFoundGet must be disabled")

        def gotPage(page):
            self.assertEqual(
                self.extendedRedirect.lastMethod,
                b"GET",
                "With afterFoundGet, the HTTP method must change to GET")

        d = client.getPage(
            url, followRedirect=True, afterFoundGet=True, method=b"POST")
        d.addCallback(gotPage)
        return d
test_webclient.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_downloadAfterFoundGet(self):
        """
        Passing C{True} for C{afterFoundGet} to L{client.downloadPage} invokes
        the same kind of redirect handling as passing that argument to
        L{client.getPage} invokes.
        """
        url = self.getURL('extendedRedirect?code=302')

        def gotPage(page):
            self.assertEqual(
                self.extendedRedirect.lastMethod,
                b"GET",
                "With afterFoundGet, the HTTP method must change to GET")

        d = client.downloadPage(url, "downloadTemp",
            followRedirect=True, afterFoundGet=True, method=b"POST")
        d.addCallback(gotPage)
        return d
test_webclient.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_getPageDeprecated(self):
        """
        L{client.getPage} is deprecated.
        """
        port = reactor.listenTCP(
            0, server.Site(Data(b'', 'text/plain')), interface="127.0.0.1")
        portno = port.getHost().port
        self.addCleanup(port.stopListening)
        url = networkString("http://127.0.0.1:%d" % (portno,))

        d = client.getPage(url)
        warningInfo = self.flushWarnings([self.test_getPageDeprecated])
        self.assertEqual(len(warningInfo), 1)
        self.assertEqual(warningInfo[0]['category'], DeprecationWarning)
        self.assertEqual(
            warningInfo[0]['message'],
            "twisted.web.client.getPage was deprecated in "
            "Twisted 16.7.0; please use https://pypi.org/project/treq/ or twisted.web.client.Agent instead")

        return d.addErrback(lambda _: None)
fetcher.py 文件源码 项目:hls-player 作者: weimingtom 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _get_page(self, url):
        def got_page(content):
            logging.debug("Cookies: %r" % self._cookies)
            return content
        def got_page_error(e, url):
            logging.error(url)
            log.err(e)
            return e

        url = url.encode("utf-8")
        if 'HLS_RESET_COOKIES' in os.environ.keys():
            self._cookies = {}
        headers = {}
        if self.referer:
            headers['Referer'] = self.referer
        d = client.getPage(url, cookies=self._cookies, headers=headers)
        d.addCallback(got_page)
        d.addErrback(got_page_error, url)
        return d
GoogleReader.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def login(self):
        print("[GoogleReader] login")
        if not self.username or not self.password:
            return

        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
        data = {
            'service': 'reader',
            'Email': self.username,
            'Passwd': self.password,
            'source': 'enigma2-plugin-extensions-simplerss',
            'continue': 'http://www.google.com/',
        }

        defer = Deferred()
        getPage('https://www.google.com/accounts/ClientLogin', method = 'POST', headers = headers, postdata = urlencode(data)).addCallback(self.loginFinished, defer).addErrback(self.loginFailed, defer)
        return defer
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _login(self, callback=None):
        self.debug("")
        if self._callScreen:
            self._callScreen.updateStatus(_("login"))
        if self._md5LoginTimestamp and ((time.time() - self._md5LoginTimestamp) < float(9.5 * 60)) and self._md5Sid != '0000000000000000':  # new login after 9.5 minutes inactivity
            self.debug("[FritzCallFBF] renew timestamp: " + time.ctime(self._md5LoginTimestamp) + " time: " + time.ctime())
            self._md5LoginTimestamp = time.time()
            callback(None)
        else:
            self.debug("not logged in or outdated login")
            # http://fritz.box/cgi-bin/webcm?getpage=../html/login_sid.xml
            parms = urlencode({'getpage': '../html/login_sid.xml'})
            url = "http://%s/cgi-bin/webcm" % (config.plugins.FritzCall.hostname.value)
            self.debug("'" + url + "' parms: '" + parms + "'")
            getPage(url,
                method="POST",
                headers={'Content-Type': "application/x-www-form-urlencoded", 'Content-Length': str(len(parms))},
                postdata=parms).addCallback(lambda x: self._md5Login(callback, x)).addErrback(lambda x: self._oldLogin(callback, x))
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def getCalls(self, callScreen, callback, callType):
        #
        # call sequence must be:
        # - login
        # - getPage -> _gotPageLogin
        # - loginCallback (_getCalls)
        # - getPage -> _getCalls1
        self.debug("")
        self._callScreen = callScreen
        self._callType = callType
        if (time.time() - self._callTimestamp) > 180:
            self.debug("outdated data, login and get new ones: " + time.ctime(self._callTimestamp) + " time: " + time.ctime())
            self._callTimestamp = time.time()
            self._login(lambda x: self._getCalls(callback, x))
        elif not self._callList:
            self.debug("time is ok, but no callList")
            self._getCalls1(callback)
        else:
            self.debug("time is ok, callList is ok")
            self._gotPageCalls(callback)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _selectFritzBoxPhonebook(self, html):
        # first check for login error
        if html:
            start = html.find('<p class="errorMessage">FEHLER:&nbsp;')
            if start != -1:
                start = start + len('<p class="errorMessage">FEHLER:&nbsp;')
                self._errorLoad('Login: ' + html[start, html.find('</p>', start)])
                return
        # look for phonebook called dreambox or Dreambox
        parms = urlencode({
                        'sid':self._md5Sid,
                        })
        url = "http://%s/fon_num/fonbook_select.lua" % (config.plugins.FritzCall.hostname.value)
        self.debug("[FritzCallFBF_05_27] _selectPhonebook: '" + url + "' parms: '" + parms + "'")
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {'Content-Type': "application/x-www-form-urlencoded", 'Content-Length': str(len(parms))},
            postdata = parms).addCallback(self._loadFritzBoxPhonebook).addErrback(self._errorLoad)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _loadFritzBoxPhonebook(self, html):
        # Firmware 05.27 onwards
        # look for phonebook called [dD]reambox and get bookid
        found = re.match(r'.*<label for="uiBookid:([\d]+)">' + config.plugins.FritzCall.fritzphonebookName.value, html, re.S)
        if found:
            bookid = found.group(1)
            self.debug("[FritzCallFBF_05_27] _loadFritzBoxPhonebook: found dreambox phonebook %s", bookid)
        else:
            bookid = 1
        # http://192.168.178.1/fon_num/fonbook_list.lua?sid=2faec13b0000f3a2
        parms = urlencode({
                        'bookid':bookid,
                        'sid':self._md5Sid,
                        })
        url = "http://%s/fon_num/fonbook_list.lua" % (config.plugins.FritzCall.hostname.value)
        self.debug("[FritzCallFBF_05_27] _loadFritzBoxPhonebookNew: '" + url + "' parms: '" + parms + "'")
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {'Content-Type': "application/x-www-form-urlencoded", 'Content-Length': str(len(parms))},
            postdata = parms).addCallback(self._parseFritzBoxPhonebook).addErrback(self._errorLoad)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _getInfo(self, callback, html):
        self.debug("[FritzCallFBF_05_27] _getInfo: verify login")
        if html:
            start = html.find('<p class="errorMessage">FEHLER:&nbsp;')
            if start != -1:
                start = start + len('<p class="errorMessage">FEHLER:&nbsp;')
                self._errorGetInfo('Login: ' + html[start, html.find('</p>', start)])
                return

        self._readBlacklist()

        url = "http://%s/home/home.lua" % config.plugins.FritzCall.hostname.value
        parms = urlencode({
            'sid':self._md5Sid
            })
        self.debug("[FritzCallFBF_05_27] _getInfo url: '" + url + "' parms: '" + parms + "'")
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {
                    'Content-Type': "application/x-www-form-urlencoded",
                    'Content-Length': str(len(parms))},
            postdata = parms).addCallback(lambda x:self._okGetInfo(callback, x)).addErrback(self._errorGetInfo)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _loadFritzBoxPhonebook(self, html, md5Sid):
        # Firmware 05.27 onwards
        # look for phonebook called [dD]reambox and get bookid
        found = re.match(r'.*<label for="uiBookid:([\d]+)">' + config.plugins.FritzCall.fritzphonebookName.value, html, re.S)
        if found:
            bookid = found.group(1)
        else:
            bookid = 1
        self.debug("phonebook %s", bookid)

        # http://192.168.178.1/fon_num/fonbook_list.lua?sid=2faec13b0000f3a2
        parms = urlencode({
                        'bookid':bookid,
                        'sid':md5Sid,
                        'cancel':'',
                        'apply':'uiApply',
                        })
        url = "http://%s/fon_num/fonbook_select.lua" % (config.plugins.FritzCall.hostname.value)
        self.debug(url + "?" + parms)
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {'Content-Type': "application/x-www-form-urlencoded", 'Content-Length': str(len(parms))},
            postdata = parms).addCallback(self._parseFritzBoxPhonebook, md5Sid).addErrback(self._errorLoad, md5Sid)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _dial(self, number, md5Sid):
        url = "http://%s/cgi-bin/webcm" % config.plugins.FritzCall.hostname.value
        parms = urlencode({
            'getpage':'../html/de/menus/menu2.html',
            'var:pagename':'fonbuch',
            'var:menu':'home',
            'telcfg:settings/UseClickToDial':'1',
            'telcfg:settings/DialPort':config.plugins.FritzCall.extension.value,
            'telcfg:command/Dial':number,
            'sid':md5Sid
            })
        self.info("url: " + url + "?" + parms)
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {
                    'Content-Type': "application/x-www-form-urlencoded",
                    'Content-Length': str(len(parms))},
            postdata = parms).addCallback(self._okDial, md5Sid).addErrback(self._errorDial, md5Sid)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _getInfo(self, callback, md5Sid):
        self.debug("verify login")

        self._login(self._readBlacklist)

        url = "http://%s/home/home.lua" % config.plugins.FritzCall.hostname.value
        parms = urlencode({
            'sid':md5Sid
            })
        self.debug("url: " + url + "?" + parms)
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {
                    'Content-Type': "application/x-www-form-urlencoded",
                    'Content-Length': str(len(parms))},
            postdata = parms).addCallback(lambda x:self._okGetInfo(callback, x, md5Sid)).addErrback(self._errorGetInfo, md5Sid)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _reset(self, md5Sid):
        if self._callScreen:
            self._callScreen.close()

        url = "http://%s/system/reboot.lua" % config.plugins.FritzCall.hostname.value
        parms = urlencode({
            'reboot':'',
            'sid':md5Sid
            })
        self.debug("url: " + url + "?" + parms)
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {
                    'Content-Type': "application/x-www-form-urlencoded"},
            postdata = parms).addCallback(self._okReset, md5Sid).addErrback(self._errorReset, md5Sid)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _getInfo(self, callback, md5Sid):
        self.debug("verify login")

        self._login(self._readBlacklist)

        url = "http://%s/data.lua" % config.plugins.FritzCall.hostname.value
        parms = urlencode({
            'sid':md5Sid,
            'page':'overview',
            'type':'all'
            })
        self.debug("url: " + url + "?" + parms)
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {
                    'Content-Type': "application/x-www-form-urlencoded",
                    'Content-Length': str(len(parms))},
            postdata = parms).addCallback(lambda x:self._okGetInfo(callback, x, md5Sid)).addErrback(self._errorGetInfo, md5Sid)
FritzCallFBF.py 文件源码 项目:enigma2-plugins 作者: opendreambox 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _readBlacklist(self, md5Sid):
        # http://fritz.box/cgi-bin/webcm?getpage=../html/de/menus/menu2.html&var:lang=de&var:menu=fon&var:pagename=sperre
        # https://217.245.196.140:699/data.lua?xhr=1&sid=e8fcf4f9a9186070&lang=de&no_sidrenew=&page=callLock
        url = "http://%s/data.lua" % config.plugins.FritzCall.hostname.value
        parms = urlencode({
            'sid':md5Sid,
            'page':'callLock'
            })
        self.debug("url: " + url + "?" + parms)
        getPage(url,
            method = "POST",
            agent = USERAGENT,
            headers = {
                    'Content-Type': "application/x-www-form-urlencoded",
                    'Content-Length': str(len(parms))},
            postdata = parms).addCallback(self._okBlacklist, md5Sid).addErrback(self._errorBlacklist, md5Sid)
recipe-576978.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def publicGetPage(*args, **kwargs):
        d = getPage(*args, **kwargs)
        return PublicDeferred(d)
test_twisted.py 文件源码 项目:Tinychat-Bot--Discontinued 作者: Tinychat 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def getPage(self, data=None, **kwargs):
        kwargs.setdefault('method', 'POST')
        kwargs['postdata'] = data

        return client.getPage("http://127.0.0.1:%d/" % (self.port,), **kwargs)
test_twisted.py 文件源码 项目:Tinychat-Bot--Discontinued 作者: Tinychat 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_invalid_method(self):
        """
        A classic GET on the xml server should return a NOT_ALLOWED.
        """
        d = self.getPage(method='GET')
        d = self.assertFailure(d, error.Error)
        d.addCallback(
            lambda exc: self.assertEqual(int(exc.args[0]), http.NOT_ALLOWED))

        return d
test_twisted.py 文件源码 项目:Tinychat-Bot--Discontinued 作者: Tinychat 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_bad_content(self):
        d = self.getPage('spamandeggs')
        d = self.assertFailure(d, error.Error)

        d.addCallback(
            lambda exc: self.assertEqual(int(exc.args[0]), http.BAD_REQUEST))

        return d
soap.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def callRemote(self, method, *args, **kwargs):
        payload = SOAPpy.buildSOAP(args=args, kw=kwargs, method=method,
                                   header=self.header, namespace=self.namespace)
        return client.getPage(self.url, postdata=payload, method="POST",
                              headers={'content-type': 'text/xml',
                                       'SOAPAction': method}
                              ).addCallback(self._cbGotResult)
test_cgi.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testCGI(self):
        cgiFilename = os.path.abspath(self.mktemp())
        cgiFile = file(cgiFilename, 'wt')
        cgiFile.write(DUMMY_CGI)
        cgiFile.close()

        portnum = self.startServer(cgiFilename)
        d = client.getPage("http://localhost:%d/cgi" % portnum)
        d.addCallback(self._testCGI_1)
        return d
test_cgi.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testReadEmptyInput(self):
        cgiFilename = os.path.abspath(self.mktemp())
        cgiFile = file(cgiFilename, 'wt')
        cgiFile.write(READINPUT_CGI)
        cgiFile.close()

        portnum = self.startServer(cgiFilename)
        d = client.getPage("http://localhost:%d/cgi" % portnum)
        d.addCallback(self._testReadEmptyInput_1)
        return d
test_cgi.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testReadInput(self):
        cgiFilename = os.path.abspath(self.mktemp())
        cgiFile = file(cgiFilename, 'wt')
        cgiFile.write(READINPUT_CGI)
        cgiFile.close()

        portnum = self.startServer(cgiFilename)
        d = client.getPage("http://localhost:%d/cgi" % portnum,
                           method="POST",
                           postdata="Here is your stdin")
        d.addCallback(self._testReadInput_1)
        return d
test_cgi.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def testReadAllInput(self):
        cgiFilename = os.path.abspath(self.mktemp())
        cgiFile = file(cgiFilename, 'wt')
        cgiFile.write(READALLINPUT_CGI)
        cgiFile.close()

        portnum = self.startServer(cgiFilename)
        d = client.getPage("http://localhost:%d/cgi" % portnum,
                           method="POST",
                           postdata="Here is your stdin")
        d.addCallback(self._testReadAllInput_1)
        return d
test_webclient.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def testPayload(self):
        s = "0123456789" * 10
        return client.getPage(self.getURL("payload"), postdata=s
            ).addCallback(self.assertEquals, s
            )


问题


面经


文章

微信
公众号

扫码关注公众号