当前位置: 首页>>代码示例>>Python>>正文


Python xmlrpc.Proxy类代码示例

本文整理汇总了Python中twisted.web.xmlrpc.Proxy的典型用法代码示例。如果您正苦于以下问题:Python Proxy类的具体用法?Python Proxy怎么用?Python Proxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Proxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: modifyDB

    def modifyDB(self, ret, cmd, *params):
        abspath = os.path.join(self.shell._path(self.workingDirectory).path, params[0])
        abspath = re.sub(r'\\+', '/', abspath)
        logging.getLogger("twisted").debug(cmd + abspath)
        #print cmd, abspath.decode('utf-8').encode('gbk')
        def printValue(value):
            logging.getLogger("twisted").debug("return:"+value)
        def printErr(e):
            logging.getLogger("twisted").debug("Err:" + e)
        from twisted.web.xmlrpc import Proxy
        try:
            proxy = Proxy('http://localhost:9999/rpc/')
            if cmd == 'del':
                method = 'deleted'
            elif cmd == 'stor':
                method = 'uploaded'
            else:
                print "unexpected db operation"
                return ret
            logging.getLogger("twisted").debug("before remote "+ method)

            print method, abspath.decode('utf-8').encode('gbk')
            proxy.callRemote(method, self.portal.realm.username, abspath).addCallbacks(printValue, printErr)   
        except Exception, e:
            logging.getLogger("twisted").debug(e)
开发者ID:dalinhuang,项目名称:gybprojects,代码行数:25,代码来源:ftpserver.py

示例2: outputlevels

def outputlevels(levellist,twisted=0,clientid=_id):
    """present a list of dmx channel levels, each scaled from
    0..1. list can be any length- it will apply to the first len() dmx
    channels.

    if the server is not found, outputlevels will block for a
    second."""

    global _dmx, _id

    if _dmx is None:
        url = networking.dmxServer.url
        if not twisted:
            _dmx = xmlrpclib.Server(url)
        else:
            from twisted.web.xmlrpc import Proxy
            _dmx = Proxy(url)

    if not twisted:
        try:
            _dmx.outputlevels(clientid, levellist)
        except socket.error, e:
            print "dmx server error %s, waiting" % e
            time.sleep(1)
        except xmlrpclib.Fault,e:
            print "outputlevels had xml fault: %s" % e
            time.sleep(1)
开发者ID:shakaran,项目名称:light9,代码行数:27,代码来源:dmxclient.py

示例3: __init__

class AddDiary:

    def __init__(self, name, password):
        self.name = name
        self.password = password
        self.proxy = Proxy('http://advogato.org/XMLRPC')

    def __call__(self, filename):
        self.data = open(filename).read()
        d = self.proxy.callRemote('authenticate', self.name, self.password)
        d.addCallbacks(self.login, self.noLogin)

    def noLogin(self, reason):
        print("could not login")
        reactor.stop()

    def login(self, cookie):
        d = self.proxy.callRemote('diary.set', cookie, -1, self.data)
        d.addCallbacks(self.setDiary, self.errorSetDiary)

    def setDiary(self, response):
        reactor.stop()

    def errorSetDiary(self, error):
        print("could not set diary", error)
        reactor.stop()
开发者ID:wellbehavedsoftware,项目名称:wbs-graphite,代码行数:26,代码来源:advogato.py

示例4: uploadImage

    def uploadImage(self, name, data):
        exception = self.master.modules["commands"].exception

        user = yield self.config.get("user")
        passwd = yield self.config.get("pass")
        if user is None or passwd is None:
            raise exception(u"No blog username or password in config")

        blog = Proxy("http://commiesubs.com/xmlrpc.php")
        blog.queryFactory.noisy = False

        try:
            data = yield blog.callRemote("wp.uploadFile",
                0, # Blog ID
                user, # Username
                passwd, # Password
                { # Content
                    "name": name,
                    "type": "image/jpeg",
                    "bits": xmlrpclib.Binary(data),
                    "overwrite": True
                }
            )
        except:
            raise exception(u"Couldn't upload image")

        returnValue(data["url"])
开发者ID:Haidaraaaaa,项目名称:Servrhe,代码行数:27,代码来源:blog.py

示例5: _callRemote

 def _callRemote(self, method, *args, **kwds):
     proxy = Proxy("http://%s/XMLRPC" % self.host, user=self.username,
         password=self.password, allowNone=True)
     deferred = proxy.callRemote(method, *args, **kwds)
     deferred.addCallbacks(self.onResult, self.onError)
     deferred.addCallbacks(self._stopReactor, self._stopReactor)
     reactor.run()
     return 0
开发者ID:DSDev-NickHogle,项目名称:terane,代码行数:8,代码来源:commands.py

示例6: run

 def run(self):
     proxy = Proxy("http://%s/XMLRPC" % self.host, user=self.username,
         password=self.password, allowNone=True)
     deferred = proxy.callRemote('iterEvents', self.query, None, self.indices,
         self.limit, self.reverse, self.fields)
     deferred.addCallback(self.printResult)
     deferred.addErrback(self.printError)
     reactor.run()
     return 0
开发者ID:DSDev-NickHogle,项目名称:terane,代码行数:9,代码来源:searcher.py

示例7: reload

 def reload(self):
     if self._deferred != None:
         self._deferred.cancel()
     self._results.clear()
     proxy = Proxy(self._url, user=self._user, password=self._pass, allowNone=True)
     self._deferred = proxy.callRemote('iter', self._query)
     self._deferred.addCallback(self._getResult)
     self._deferred.addErrback(self._getError)
     logger.debug("searching with query '%s'" % self._query)
开发者ID:DSDev-NickHogle,项目名称:terane,代码行数:9,代码来源:search.py

示例8: retryWithOtherProvider

 def retryWithOtherProvider(self, error, nodeConfig, words, docId, filename):
     if self.providerSet:
         nextHost, nextPort = self.providerSet.pop()
         print "[webapp] trying to donwload %r from %s:%s" % (filename, nextHost, nextPort)
         proxy = Proxy(str('http://%s:%s' % (nextHost, nextPort)))
         d = proxy.callRemote('downloadFile', docId, words)
         d.addCallback(self.gotDataBack, nodeConfig, filename, words)
         d.addErrback(self.retryWithOtherProvider, nodeConfig, words, docId, filename)
         return d
     else:
         return self.onDownloadFileError('no provider available', filename)
开发者ID:BackupTheBerlios,项目名称:maay-svn,代码行数:11,代码来源:webapplication.py

示例9: _createPost

    def _createPost(self, show, episode, version, info_link, img_link, comment = None, hovertext = None, retries = 0, retryer = None):
        exception = self.master.modules["commands"].exception

        end = " END" if episode == show.episode.total else ""
        title = u"{} {:02d}{}{}".format(show.name.english, episode, version, end)

        img_type = 'video loop="loop" onmouseover="this.play()" onmouseout="this.pause()"' if img_link.endswith("webm") else 'img'
        img = '<{} src="{}" title="{}" style="width: 100%; border-radius: 5px;" />'.format(img_type, img_link, "" if hovertext is None else hovertext.replace('"', '&quot;'))
        comment = "<br><br>{}".format(comment.encode("utf8")) if comment is not None else ""

        user = yield self.config.get("user")
        passwd = yield self.config.get("pass")
        if user is None or passwd is None:
            raise exception(u"No blog username or password in config")

        blog = Proxy("http://commiesubs.com/xmlrpc.php")
        blog.queryFactory.noisy = False
        slug = re.search("([^/]+)/?$", show.blog).group(1)
        categories = ["Releases"] #, "DxS a shit"]
        result = yield blog.callRemote("wp.getTerms", 0, user, passwd, "category")
        for term in result:
            if term["slug"] == slug:
                categories.append(term["name"])

        try:
            post_id = yield blog.callRemote("wp.newPost",
                0, # Blog ID
                user, # Username
                passwd, # Password
                { # Content
                    "post_type": "post",
                    "post_status": "publish",
                    "comment_status": "open",
                    "post_title": title.encode("utf8"),
                    "post_content": "{}<br><br><a href=\"{}\">Torrent</a>{}".format(img, info_link, comment),
                    "terms_names": {"category": categories}
                }
            )
        except Exception as e:
            if retries:
                self.master.modules["irc"].msg(u"#commie-staff", u"Failed to make blog post ({}), retrying in a minute. This was attempt #{:,d}".format(title, retries))
            raise e

        try:
            data = yield blog.callRemote("wp.getPost", 0, user, passwd, int(post_id))
        except:
            link = "<unknown url>"
        else:
            link = data["link"]

        if retries:
            self.master.modules["irc"].msg(u"#commie-staff", u"Created blog post ({}): {}".format(title, link))
        returnValue(link)
开发者ID:Haidaraaaaa,项目名称:Servrhe,代码行数:53,代码来源:blog.py

示例10: test_inbound_request_and_reply

    def test_inbound_request_and_reply(self):
        address = self.transport.xmlrpc_server.getHost()
        url = 'http://' + address.host + ':' + str(address.port) + '/foo/'
        proxy = Proxy(url)
        x = proxy.callRemote('handleUSSD', {
            'TransactionId': '0001',
            'USSDServiceCode': '543',
            'USSDRequestString': '14321*1000#',
            'MSISDN': '275551234',
            'USSDEncoding': 'GSM0338',      # Optional
            'TransactionTime': '2013-07-05T22:58:47.565596'
            })
        [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        expected_inbound_payload = {
            'message_id': '',
            'content': None,
            'from_addr': '',    # msisdn
            'to_addr': '',      # service code
            'session_event': TransportUserMessage.SESSION_RESUME,
            'transport_name': self.tx_helper.transport_name,
            'transport_type': 'ussd',
            'transport_metadata': {
                'mtn_rwanda_ussd': {
                    'transaction_id': '0001',
                    'transaction_time': '2013-07-05T22:58:47.565596',
                },
            },
        }
        yield self.assert_inbound_message(
            expected_inbound_payload,
            msg,
            from_addr='275551234',
            to_addr='543',
            session_event=TransportUserMessage.SESSION_NEW)

        expected_reply = {'MSISDN': '275551234',
                          'TransactionId': '0001',
                          'TransactionTime': datetime.now().isoformat(),
                          'USSDEncoding': 'GSM0338',
                          'USSDResponseString': 'Test message',
                          'USSDServiceCode': '543',
                          'action': 'end'}

        self.tx_helper.make_dispatch_reply(
            msg, expected_reply['USSDResponseString'], continue_session=False)

        received_text = yield x
        for key in received_text.keys():
            if key == 'TransactionTime':
                self.assertEqual(len(received_text[key]),
                        len(expected_reply[key]))
            else:
                self.assertEqual(expected_reply[key], received_text[key])
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:53,代码来源:test_mtn_rwanda_ussd.py

示例11: start

 def start(self):
     proxy = Proxy("http://beatty.userland.com/RPC2")
     if TEST_ERRORS:
         i = self.i
         if i == 3:
             proxy = Proxy("http://illegal-host_name/")
         elif i == 6:
             proxy = Proxy("http://beatty.userland.com/")
         elif i == 8:
             proxy = Proxy("http://beatty.userland.com/testing_xmlrpc_error_case")
         
     return proxy.callRemote('examples.getStateName', self.i)
开发者ID:bhramoss,项目名称:code,代码行数:12,代码来源:recipe-203471.py

示例12: relayAnswer

 def relayAnswer(self, answer, local=False): # local still unused
     """record and forward answers to a query.
     If local is True, then the answers come from a local query,
     and thus must not be recorded in the database"""
     print "P2pQuerier relayAnswer : %s documents" % len(answer.documents)
     query = self._receivedQueries.get(answer.queryId)
     if query:
         print " ... relaying Answer to originator ..."
     else:
         query = self._sentQueries.get(answer.queryId)
         if query:
             print " ... originator : we got mail :) ... "
         else:
             print " ... bailing out (bug?) : we had no query for this answer"
             return
     
     toSend = []
     
     for document in answer.documents:
         if not isinstance(document, dict):
             document = document.__dict__
         # TODO: record answer in database if local is False
         # auc : to cache them ?
         if not query.isKnown(document):
             abstract = makeAbstract(document['text'], query.getWords())
             document['text'] = untagText(removeSpace(abstract))
             query.addMatch(document)
             #toSend.append(document.asDictionnary())
             # above was meant to be like .asKwargs() ?
             # anyway, this stuff is xmlrpc-serializable (auc)
             toSend.append(document)
     
     if query.sender != self.nodeId: 
         try:
             # getNodeUrl seems not to exist yet
             #senderUrl = self.querier.getNodeUrl(query.sender)
             host = query.host 
             port = query.port
             print " ... will send answer to %s:%s" % (host, port)
             senderUrl = 'http://%s:%s' % (host, port)
             proxy = Proxy(senderUrl)
             d = proxy.callRemote('distributedQueryAnswer',
                                  query.qid,
                                  self.nodeId,
                                  toSend)
             d.addCallback(self.querier.registerNodeActivity)
             d.addErrback(P2pErrbacks.answerQueryProblem)
             P2pErrbacks.setAnswerTarget(senderUrl)
         except ValueError:
             print "unknown node %s" % query.sender
     else: # local would be true ? don't waste the answers ...
         self._notifyAnswerCallbacks(answer.queryId, toSend)
开发者ID:BackupTheBerlios,项目名称:maay-svn,代码行数:52,代码来源:p2pquerier.py

示例13: locateChild

    def locateChild(self, request, segments):

        for filter in self.contentFilters:
            request.addResponseFilter(filter[0], atEnd=filter[1])

        # Examine cookies for wiki auth token; if there, ask the paired wiki
        # server for the corresponding record name.  If that maps to a
        # principal, assign that to authnuser.

        if not hasattr(request, "checkedWiki"):
            # Only do this once per request
            request.checkedWiki = True

            wikiConfig = config.Authentication.Wiki
            cookies = request.headers.getHeader("cookie")
            if wikiConfig["Enabled"] and cookies is not None:
                for cookie in cookies:
                    if cookie.name == wikiConfig["Cookie"]:
                        token = cookie.value
                        break
                else:
                    token = None

                if token is not None and token != "unauthenticated":
                    log.debug("Wiki sessionID cookie value: %s" % (token,))
                    proxy = Proxy(wikiConfig["URL"])
                    try:
                        username = (yield proxy.callRemote(wikiConfig["UserMethod"], token))
                    except Exception, e:
                        log.error("Failed to look up wiki token (%s)" % (e,))
                        username = None

                    if username is not None:
                        log.debug("Wiki lookup returned user: %s" % (username,))
                        principal = None
                        directory = request.site.resource.getDirectory()
                        record = directory.recordWithShortName("users", username)
                        log.debug("Wiki user record for user %s : %s" % (username, record))
                        if record:
                            # Note: record will be None if it's a /Local/Default user
                            for collection in self.principalCollections():
                                principal = collection.principalForRecord(record)
                                if principal is not None:
                                    break

                        if principal:
                            log.debug("Wiki-authenticated principal %s being assigned to authnUser" % (record.guid,))
                            request.authzUser = request.authnUser = davxml.Principal(
                                davxml.HRef.fromString("/principals/__uids__/%s/" % (record.guid,))
                            )
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:50,代码来源:root.py

示例14: render_GET

 def render_GET(self, request):
     key = request.args.get('key', [None])[0]
     if key is None or key != xml_key:
         return "fail"
     proxy = Proxy(xml_source)
     op = request.args.get('op', [None])[0]
     if op is not None:
         if op == 'store':
             proxy.callRemote(xml_method, xml_login, xml_password).addCallbacks(self.storeDocs, self.pr)
         elif op == 'compare' or op == 'update':
             proxy.callRemote(xml_method, xml_login, xml_password).addCallbacks(self.compareDocs, self.pr)
         elif op == 'descr':
             print "try to store"
             self.storeDescription(request)
     return "ok"
开发者ID:mysoftpro,项目名称:pc,代码行数:15,代码来源:catalog.py

示例15: cmd_search

def cmd_search(request, text):
    if len(text) > 2048:
        defer.returnValue(dict(ok=False, desc='Search query is too long.'))
    service = Proxy('http://127.0.0.1:%d/' % config.search_port)
    start = time.time()
    try:
        result = yield service.callRemote('search', text)
    except Exception:
        log.msg('SEARCH ERROR:\n\n' + traceback.format_exc())
        defer.returnValue(dict(ok=False, desc='Sorry, search not available.'))

    t = time.time() - start
    log.msg('Queried "%s" by %s. Found %s results in %.3fs.' % (
        text, request.user['name'], result[0], t))
    defer.returnValue(dict(ok=True, format='search', search_result=result))
开发者ID:Kagami,项目名称:bnw,代码行数:15,代码来源:command_search.py


注:本文中的twisted.web.xmlrpc.Proxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。