コード例 #1
0
ファイル: blog.py プロジェクト: rcombs/Servrhe
    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"])
コード例 #2
0
ファイル: blog.py プロジェクト: rcombs/Servrhe
    def updateMahoyo(self, progress):
        progress = BeautifulSoup(progress)
        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

        post = yield blog.callRemote("wp.getPost", 0, user, passwd, 8367)
        content = BeautifulSoup(post["post_content"])

        old = content.find(class_="progress")
        new = progress.find(class_="progress")
        old.replace_with(new)
        content = content.encode(formatter="html")

        try:
            yield blog.callRemote("wp.editPost", 0, user, passwd, 8367,
                                  {"post_content": content})
        except:
            raise exception(u"Couldn't update post")
コード例 #3
0
ファイル: dmxclient.py プロジェクト: shakaran/light9
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)
コード例 #4
0
ファイル: blog.py プロジェクト: Haidaraaaaa/Servrhe
    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"])
コード例 #5
0
ファイル: steerAPIproducer.py プロジェクト: loox-/p2ner
def stopProducingStream(streamId, p2nerIp='127.0.0.1', p2nerPort=PORT):
    print 'should stop producing ', STREAMID
    url = 'http://' + p2nerIp + ':' + str(p2nerPort)
    proxy = Proxy(url)
    d = proxy.callRemote('stopProducing', STREAMID)
    d.addCallback(stopSuccess)
    d.addErrback(stopFailure)
コード例 #6
0
ファイル: advogato.py プロジェクト: zerospam/twisted
class AddDiary:
    def __init__(self, name, password):
        self.name = name
        self.password = password
        self.proxy = Proxy(b"http://advogato.org/XMLRPC")

    def __call__(self, filename):
        with open(filename) as f:
            self.data = f.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()
コード例 #7
0
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()
コード例 #8
0
ファイル: test_xrpc.py プロジェクト: shuei/carchivetools
 def setUp(self):
     self.root = resource.buildResource('127.0.0.1:99999')
     self.site = Site(self.root)  # TODO: what is timeout?
     self.serv = reactor.listenTCP(0, self.site, interface='127.0.0.1')
     P = self.serv.getHost().port
     url = 'http://127.0.0.1:%d/cgi-bin/ArchiveDataServer.cgi' % P
     self.client = Proxy(url)
コード例 #9
0
ファイル: ftpserver.py プロジェクト: dalinhuang/gybprojects
    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)
コード例 #10
0
 def __init__(self, vip, vport, port=9000, testbed=False):
     xmlrpc.XMLRPC.__init__(self)
     print 'start listening xmlrpc'
     reactor.listenTCP(port, server.Site(self))
     url = "http://" + vip + ':' + str(vport) + "/XMLRPC"
     self.proxy = Proxy(url)
     self.register(port)
     self.testbed = testbed
コード例 #11
0
 def __init__(self, url):
     """
     Initialize the store. 
     """
     self.store = dict()
     self.url = url
     self.proxy = Proxy(self.url)
     self.error = False
コード例 #12
0
 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
コード例 #13
0
ファイル: tail.py プロジェクト: msfrank/terane
 def startService(self):
     Window.startService(self)
     logger.debug("started tail: using query '%s'" % self._query)
     self._proxy = Proxy(self._url,
                         user=self._user,
                         password=self._pass,
                         allowNone=True)
     self._tail()
コード例 #14
0
ファイル: serverxmlrpccontrol.py プロジェクト: loox-/p2ner
 def initInterface(self,*args,**kwargs):
     xmlrpc.XMLRPC.__init__(self)
     self.logger=DatabaseLog(_parent=self,server=True)
     print 'should register to ',kwargs['vizirIP'],kwargs['vizirPort']
     url="http://"+kwargs['vizirIP']+':'+str(kwargs['vizirPort'])+"/XMLRPC"
     self.vip=kwargs['vizirIP']
     self.vport=kwargs['vizirPort']
     self.proxy=Proxy(url)
コード例 #15
0
 def run(self):
     self._proxy = Proxy("http://%s/XMLRPC" % self.host,
                         user=self.username,
                         password=self.password,
                         allowNone=True)
     # make the XMLRPC call
     self.tail(None)
     reactor.run()
コード例 #16
0
ファイル: searcher.py プロジェクト: DSDev-NickHogle/terane
 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
コード例 #17
0
ファイル: daemon.py プロジェクト: pombredanne/launchpad-3
def make_portal():
    """Create and return a `Portal` for the SSH service.

    This portal accepts SSH credentials and returns our customized SSH
    avatars (see `CodehostingAvatar`).
    """
    authentication_proxy = Proxy(config.codehosting.authentication_endpoint)
    codehosting_proxy = Proxy(config.codehosting.codehosting_endpoint)
    return get_portal(authentication_proxy, codehosting_proxy)
コード例 #18
0
 def on_connectButton_clicked(self,widget):
     ip=self.builder.get_object('ipEntry').get_text()
     port=self.builder.get_object('portEntry').get_text()
     self.url="http://"+ip+':'+port+"/XMLRPC"
     print self.url
     proxy = Proxy(self.url)
     d =proxy.callRemote('connect')
     d.addCallback(self.succesfulConnection)
     d.addErrback(self.failedConnection)
コード例 #19
0
ファイル: search.py プロジェクト: DSDev-NickHogle/terane
 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)
コード例 #20
0
ファイル: blog.py プロジェクト: rcombs/Servrhe
    def createPost(self,
                   show,
                   episode,
                   version,
                   info_link,
                   img_link,
                   comment=None,
                   hovertext=None):
        end = " END" if episode == show.episode.total else ""
        exception = self.master.modules["commands"].exception
        img = '<img src="{}" title="{}" style="width: 100%; border-radius: 5px;" />'.format(
            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 = ["The Bread Lines"]  #, "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:
            yield blog.callRemote(
                "wp.newPost",
                0,  # Blog ID
                user,  # Username
                passwd,  # Password
                {  # Content
                    "post_type":
                    "post",
                    "post_status":
                    "publish",
                    "comment_status":
                    "open",
                    "post_title":
                    "{} {:02d}{}{}".format(show.name.english, episode, version,
                                           end),
                    "post_content":
                    "{}<br><br><a href=\"{}\">Torrent</a>{}".format(
                        img, info_link, comment),
                    "terms_names": {
                        "category": categories
                    }
                })
        except:
            raise exception(u"Couldn't publish blog post")
コード例 #21
0
 def xmlrpc_proxyCommand(self, *args):
     #cmd=args.pop(0)
     args = list(args)
     peer = args.pop(-1)
     if self.testbed:
         peer[0] = LTOGIP[peer[0]]
     url = "http://" + peer[0] + ':' + str(peer[1]) + "/XMLRPC"
     proxy = Proxy(url)
     d = proxy.callRemote(*args)
     return d
コード例 #22
0
def main():
    """
    script main function
    """
    url = 'http://%s:%s' % (CFG['client']['server'], CFG['client']['port'])
    proxy = Proxy(url)
    proxy.callRemote('request', 1,
                     'http://127.0.0.1/dolphin/callback').addCallbacks(
                         success_callback, error_callback)

    reactor.run()
コード例 #23
0
 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)
コード例 #24
0
 def __init__(self, xmlrpc_port=33610, xmlrpc_use_ssl=True, api_key=None):
     Resource.__init__(self)
     url = '%(protocol)s://127.0.0.1:%(port)d/CloudMailing' % {
         'protocol': xmlrpc_use_ssl and 'https' or 'http',
         'port': xmlrpc_port
     }
     self.proxy = Proxy(url,
                        user='******',
                        password=api_key,
                        allowNone=True,
                        useDateTime=True,
                        connectTimeout=30.0)
コード例 #25
0
ファイル: recipe-203471.py プロジェクト: bhramoss/code
 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)
コード例 #26
0
ファイル: search.py プロジェクト: msfrank/terane
 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('iterEvents', self._query)
     self._deferred.addCallback(self._getResult)
     self._deferred.addErrback(self._getError)
     logger.debug("searching with query '%s'" % self._query)
コード例 #27
0
ファイル: blog.py プロジェクト: Haidaraaaaa/Servrhe
    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)
コード例 #28
0
    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])
コード例 #29
0
 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
コード例 #30
0
ファイル: connectgui.py プロジェクト: loox-/p2ner
 def on_connectButton_clicked(self, widget):
     self.ip = self.builder.get_object('ipEntry').get_text()
     port = self.builder.get_object('portEntry').get_text()
     self.url = "http://" + self.ip + ':' + port + "/XMLRPC"
     proxy = Proxy(self.url)
     password = self.builder.get_object('passwordEntry').get_text()
     m = md5()
     m.update(password)
     password = m.hexdigest()
     d = proxy.callRemote('connect', password)
     d.addCallback(self.succesfulConnection)
     d.addErrback(self.failedConnection)
コード例 #31
0
 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)
コード例 #32
0
    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)
コード例 #33
0
ファイル: root.py プロジェクト: svn2github/calendarserver-raw
    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,))
                            )
コード例 #34
0
ファイル: connection.py プロジェクト: Ubun1/txkoji
 def __init__(self, profile):
     self.profile = profile
     self.url = self.lookup(profile, 'server')
     self.weburl = self.lookup(profile, 'weburl')
     if not self.url:
         msg = 'no server configured at %s for %s' % (PROFILES, profile)
         raise ValueError(msg)
     self.proxy = Proxy(self.url.encode(), allowNone=True)
     self.proxy.queryFactory = KojiQueryFactory
     self.cache = Cache(self)
     # We populate these on login:
     self.session_id = None
     self.session_key = None
     self.callnum = None
コード例 #35
0
ファイル: xmlrpccontrol.py プロジェクト: loox-/p2ner
 def initInterface(self, *args, **kwargs):
     xmlrpc.XMLRPC.__init__(self)
     self.dContactServers = {}
     self.dSubStream = {}
     self.dStopProducing = {}
     self.dUnregisterStream = {}
     self.dRegisterStream = {}
     if 'vizir' in kwargs.keys() and kwargs['vizir']:
         print 'should register to ', kwargs['vizirIP'], kwargs['vizirPort']
         url = "http://" + kwargs['vizirIP'] + ':' + str(
             kwargs['vizirPort']) + "/XMLRPC"
         self.proxy = Proxy(url)
     else:
         self.proxy = None
コード例 #36
0
class RestApiHome(ApiResource):
    permission_classes = (AllowAny, )

    def __init__(self, xmlrpc_port=33610, xmlrpc_use_ssl=True, api_key=None):
        Resource.__init__(self)
        url = '%(protocol)s://127.0.0.1:%(port)d/CloudMailing' % {
            'protocol': xmlrpc_use_ssl and 'https' or 'http',
            'port': xmlrpc_port
        }
        self.proxy = Proxy(url,
                           user='******',
                           password=api_key,
                           allowNone=True,
                           useDateTime=True,
                           connectTimeout=30.0)

    def render_GET(self, request):
        self.log_call(request)
        data = {
            'product_name': "CloudMailing",
            'product_version': __version__,
            'api_version': API_VERSION,
        }
        self.write_headers(request)
        return json.dumps(data)

    def _api_callback(self, data, request):
        request.setResponseCode(http_status.HTTP_200_OK)
        self.write_headers(request)
        # print data
        request.write(
            json.dumps({
                'status': 'ok',
                'result': data
            }, default=json_default))
        request.finish()

    def render_POST(self, request):
        if not self.check_permissions([IsAdminUser()]):
            return self.access_forbidden(request)

        self.log_call(request)
        data = json.loads(request.content.read(), object_hook=datetime_parser)
        function = data['function']
        args = data.get('args', [])
        log.debug("Calling '%s(%s)'", function, repr(args))
        self.proxy.callRemote(str(function), *args)\
            .addCallback(self._api_callback, request)\
            .addErrback(self._on_error, request)
        return server.NOT_DONE_YET
コード例 #37
0
ファイル: steerAPIproducer.py プロジェクト: loox-/p2ner
def registerStream(title,
                   author,
                   desc,
                   port,
                   trackerIP,
                   trackerPort,
                   p2nerIp='127.0.0.1',
                   p2nerPort=PORT):
    url = 'http://' + p2nerIp + ':' + str(p2nerPort)
    proxy = Proxy(url)
    d = proxy.callRemote('registerSteerStream', title, author, desc, port,
                         trackerIP, trackerPort)
    d.addCallback(registationSuccess)
    d.addErrback(registrationFailed)
コード例 #38
0
ファイル: serverxmlrpccontrol.py プロジェクト: loox-/p2ner
class xmlrpcControl(Interface,xmlrpc.XMLRPC):

    def initInterface(self,*args,**kwargs):
        xmlrpc.XMLRPC.__init__(self)
        self.logger=DatabaseLog(_parent=self,server=True)
        print 'should register to ',kwargs['vizirIP'],kwargs['vizirPort']
        url="http://"+kwargs['vizirIP']+':'+str(kwargs['vizirPort'])+"/XMLRPC"
        self.vip=kwargs['vizirIP']
        self.vport=kwargs['vizirPort']
        self.proxy=Proxy(url)


    def start(self):
        print 'start listening xmlrpc'
        p=findNextTCPPort(9090)
        print p
        reactor.listenTCP(p, server.Site(self))
        self.register(getIP(self.vip,self.vport)[0], p)


    def register(self,ip,port):
        try:
            p=self.root.controlPipe.callSimple('getPort')
        except:
            reactor.callLater(0.5,self.register,ip,port)
            return

        self.proxy.callRemote('register',ip,port,p,0,True)

    def xmlrpc_restartServer(self):
        print 'restarting server'
        self.root.restartServer()
        return 1

    def logRecord(self,record):
         self.logger.addRecord(record)

    def xmlrpc_getRecords(self):
        d=self.logger.getRecords()
        d.addCallback(self.dumpRecords)
        return d

    def dumpRecords(self,ret):
        if ret:
            ret=[dict(r) for r in ret]
            ret= [dumps(r) for r in ret]
        else:
            ret=[]
        return ret
コード例 #39
0
ファイル: catalog.py プロジェクト: mysoftpro/pc
 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"
コード例 #40
0
 def route_email(self, ee):
     proxy = Proxy('http://localhost:8001/')
     if ee.html:
         print 'preview html in browser'
         d = proxy.callRemote('preview', ee.html,
                              fixed.digest(ee.broadcast_dict['file_dest']))
         d.addCallback(lambda local_file: s3.save_s3(
             s3.bucket_straight('www.scewpt.com'),
             str(ee.broadcast_dict['file_dest'] + "_preview.png"), None,
             local_file, "image/png", 'public-read'))
         d.addErrback(self.browser_error)
         return d
     else:
         print 'not previewed'
         return defer.SUCCESS
コード例 #41
0
ファイル: command_search.py プロジェクト: Kagami/bnw
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))
コード例 #42
0
ファイル: flickr_storage.py プロジェクト: unintended/Cohen
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        self.next_id = 10000
        self.name = kwargs.get('name', 'Flickr')
        self.proxy = kwargs.get('proxy', 'false')
        self.refresh = int(kwargs.get('refresh', 60)) * 60

        self.limit = int(kwargs.get('limit', 100))

        self.flickr_userid = kwargs.get('userid', None)
        self.flickr_password = kwargs.get('password', None)
        self.flickr_permissions = kwargs.get('permissions', None)

        if self.proxy in [1, 'Yes', 'yes', 'True', 'true']:
            self.proxy = True
        else:
            self.proxy = False

        ignore_patterns = kwargs.get('ignore_patterns', [])
        ignore_file_pattern = re.compile('|'.join(['^\..*'] + list(ignore_patterns)))

        self.wmc_mapping = {'16': 0}

        self.update_id = 0
        self.flickr = Proxy('http://api.flickr.com/services/xmlrpc/')
        self.flickr_api_key = '837718c8a622c699edab0ea55fcec224'
        self.flickr_api_secret = '30a684822c341c3c'
        self.store = {}
        self.uploads = {}

        self.refresh_store_loop = task.LoopingCall(self.refresh_store)
        self.refresh_store_loop.start(self.refresh, now=False)
        #self.server.coherence.store_plugin_config(self.server.uuid, {'test':'äöüß'})

        self.flickr_userid = kwargs.get('userid', None)
        self.flickr_password = kwargs.get('password', None)
        self.flickr_permissions = kwargs.get('permissions', 'read')

        self.flickr_authtoken = kwargs.get('authtoken', None)

        if(self.flickr_authtoken == None and
           self.server.coherence.writeable_config() == True):
            if not None in (self.flickr_userid, self.flickr_password):
                d = self.flickr_authenticate_app()
                d.addBoth(lambda x: self.init_completed())
                return

        self.init_completed()
コード例 #43
0
 def test_inbound_faulty_request(self):
     address = self.transport.xmlrpc_server.getHost()
     url = 'http://' + address.host + ':' + str(address.port) + '/foo/'
     proxy = Proxy(url)
     try:
         yield proxy.callRemote('handleUSSD', {
             'TransactionId': '0001',
             'USSDServiceCode': '543',
             'USSDRequestString': '14321*1000#',
             'MSISDN': '275551234',
             'USSDEncoding': 'GSM0338',
         })
         [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     except xmlrpclib.Fault, e:
         self.assertEqual(e.faultCode, 8002)
         self.assertEqual(e.faultString, 'error')
コード例 #44
0
ファイル: test_xrpc.py プロジェクト: aderbenev/carchivetools
 def setUp(self):
     self.root = resource.buildResource('127.0.0.1:99999')
     self.site = Site(self.root) # TODO: what is timeout?
     self.serv = reactor.listenTCP(0, self.site, interface='127.0.0.1')
     P = self.serv.getHost().port
     url = 'http://127.0.0.1:%d/cgi-bin/ArchiveDataServer.cgi'%P
     self.client = Proxy(url)
コード例 #45
0
ファイル: run.py プロジェクト: gabadie/GHome
def playMusic():
    if request.method == 'POST':
        form=request.form
        tag =  [form.get(val) for val in ['tag']]
        print tag

        api=API8tracks(config.api_8tracks)

        mixset = api.mixset(tags=tag, sort='popular')
        print mixset
        url= "http://streamTaMaman.wav" # [stream.data['track_file_stream_url'] for stream in mixset.mixes[0].tracks_cache]
        proxy = Proxy('http://'+str(config.main_server.ip)+':'+str(config.main_server.rpc_port))
        proxy.callRemote('raspi.find_music_url',0,url).addCallbacks(return_value)
        reactor.run()
        # TODO : this is blocking, warning!!
    return json.dumps("haha")
コード例 #46
0
    def __init__(self, server, **kwargs):
        self.next_id = 1000
        self.name = kwargs.get('name','Flickr')
        self.proxy = kwargs.get('proxy','false')
        self.refresh = int(kwargs.get('refresh',60))*60
        if self.proxy in [1,'Yes','yes','True','true']:
            self.proxy = True
        else:
            self.proxy = False

        self.urlbase = kwargs.get('urlbase','')
        if( len(self.urlbase)>0 and
            self.urlbase[len(self.urlbase)-1] != '/'):
            self.urlbase += '/'

        ignore_patterns = kwargs.get('ignore_patterns',[])
        ignore_file_pattern = re.compile('|'.join(['^\..*'] + list(ignore_patterns)))

        self.server = server
        self.update_id = 0
        self.flickr = Proxy('http://api.flickr.com/services/xmlrpc/')
        self.flickr_api_key = '837718c8a622c699edab0ea55fcec224'
        self.store = {}

        self.refresh_store_loop = task.LoopingCall(self.refresh_store)
        self.refresh_store_loop.start(self.refresh, now=False)

        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
コード例 #47
0
ファイル: store.py プロジェクト: DamnWidget/goliat
 def __init__(self, url):
     """
     Initialize the store. 
     """
     self.store=dict()
     self.url=url
     self.proxy=Proxy(self.url)
     self.error=False
コード例 #48
0
 def test_timeout(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',
         'TransactionTime': '2013-07-05T22:58:47.565596'
         })
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.clock.advance(30)
     try:
         yield x
     except xmlrpclib.Fault, e:
         self.assertEqual(e.faultCode, 8002)
         self.assertEqual(e.faultString, 'error')
コード例 #49
0
ファイル: agent.py プロジェクト: mikefort/mandelbrot
def agent_version_callback(ns):
    section = ns.get_section('client')
    url = 'http://localhost:9844/XMLRPC'
    if section.get_bool("debug", False):
        startLogging(StdoutHandler(), DEBUG)
    else:
        startLogging(None)
    logger.debug("connecting to %s", url)
    proxy = Proxy(url)
    defer = proxy.callRemote('getVersion')
    def onfailure(failure):
        print "query failed: " + failure.getErrorMessage()
        reactor.stop()
    def onresponse(version):
        print "mandelbrot-agent version " + version
        reactor.stop()
    defer.addCallbacks(onresponse, onfailure)
    reactor.run()
コード例 #50
0
 def child_distantfile(self, context):
     """download distant file and put it in a public indexable directory"""
     host = context.arg('host')
     port = context.arg('port')
     qid = context.arg('qid')
     words = context.arg('words').split()
     filename = context.arg('filename')
     docid = context.arg('docid')
     if not host or not port or not docid:
         return Maay404()
     nodeConfig = INodeConfiguration(context)
     proxy = Proxy(str('http://%s:%s' % (host, port)))
     print "[webapp] trying to donwload %r from %s:%s" % (filename, host, port)
     d = proxy.callRemote('downloadFile', docid, words)
     d.addCallback(self.gotDataBack, nodeConfig, filename, words)
     d.addErrback(self.tryOtherProviders, nodeConfig, filename, words, host,
                  port, docid, qid)
     return d
コード例 #51
0
 def sendQuery(self, query):
     """
     :type query: `maay.p2pquerier.P2pQuery`
     """        
     print "P2pQuerier sendQuery %s : %s" % (query.qid, query)
     if self._sentQueries.has_key(query.qid):
         print " ... my bad, we were going to send query %s to ourselves ..." \
               % query.qid
         return
     #FIXME: avoid to send query to the originator
     for neighbor in self._selectTargetNeighbors(query):
         target = str(neighbor.getRpcUrl())
         proxy = Proxy(target) 
         d = proxy.callRemote('distributedQuery', query.asKwargs())
         d.addCallback(self.querier.registerNodeActivity)
         d.addErrback(P2pErrbacks.sendQueryProblem)
         P2pErrbacks.setQueryTarget(target)
         self._sentQueries[query.qid] = query
         print " ... sent to %s" % neighbor
コード例 #52
0
ファイル: ftpserver.py プロジェクト: dalinhuang/gybprojects
 def modifyDB(self, ret, cmd, *params):
     abspath = os.path.join(self.shell._path(self.workingDirectory).path, params[0])
     import re
     abspath = re.sub(r'\\+', '/', abspath)
     def printValue(value):
         pass
     from twisted.web.xmlrpc import Proxy
     try:
         proxy = Proxy('http://localhost:80/rpc/')
         if cmd == 'del':
             method = 'deleted'
         elif cmd == 'stor':
             method = 'uploaded'
         else:
             print "unexpected db operation"
             return ret
         proxy.callRemote(method, self.portal.realm.username, abspath).addCallback(printValue)   
     except Exception, e:
         print e
コード例 #53
0
    def relayAnswer(self, answer): 
        """record and forward answers to a query."""
        print "P2pQuerier relayAnswer : %s document(s) from %s:%s" \
              % (len(answer.documents), answer.provider[2],
                 answer.provider[3])
        query = self._receivedQueries.get(answer.qid)
        if not query :
            query = self._sentQueries.get(answer.qid)
            if not query:
                print " ... bug or dos : we had no query for this answer"
                return
                
        toSend = []
        for document in answer.documents:
            if not isinstance(document, dict):
                document = document.__dict__
            # only node-local docs will exhibit their full pathname
            if 'url' in document:
                doc_url = base64.decodestring(document['url'])
                document['url'] = base64.encodestring(os.path.basename(doc_url))
            # TODO: record answer in database if local is False
            # auc : to have them in Document with state == KNOWN
            abstract = makeAbstract(document['text'], query.getWords())
            document['text'] = untagText(removeSpace(abstract))
            query.addMatch(document)
            toSend.append(document)

        if query.sender != NODE_CONFIG.get_node_id():
            self.querier.registerNodeActivity(answer.provider[1])
            (host, port) = (query.client_host, query.client_port)
            print " ... relaying Answer to %s:%s ..." % (host, port)
            senderUrl = 'http://%s:%s' % (host, port)
            proxy = Proxy(senderUrl)
            d = proxy.callRemote('distributedQueryAnswer',
                                 query.qid,
                                 NODE_CONFIG.get_node_id(),
                                 answer.provider,
                                 toSend) 
            d.addErrback(answerQueryErrback(query))
        else:
            print " ... originator : we got an answer !"
            self._notifyAnswerCallbacks(answer.qid, answer.provider, toSend)
コード例 #54
0
ファイル: tail.py プロジェクト: msfrank/terane
class Tailer(Window):
    def __init__(self, args):
        title = "Tail '%s'" % args
        self._query = args
        self._lastId = None
        self._results = ResultsListbox()
        self.interval = 2
        self._url = "http://%s/XMLRPC" % console.host
        self._user = console.username
        self._pass = console.password
        self._delayed = None
        self._deferred = None
        logger.debug("using proxy url %s" % self._url)
        Window.__init__(self, title, self._results)

    def startService(self):
        Window.startService(self)
        logger.debug("started tail: using query '%s'" % self._query)
        self._proxy = Proxy(self._url, user=self._user, password=self._pass, allowNone=True)
        self._tail()

    def stopService(self):
        if self._delayed != None:
            self._delayed.cancel()
        self._delayed = None
        if self._deferred != None:
            self._deferred.cancel()
        self._deferred = None
        logger.debug("stopped tail")
        Window.stopService(self)

    def _tail(self):
        self._deferred = self._proxy.callRemote('tailEvents', self._query, self._lastId)
        self._deferred.addCallback(self._getResult)
        self._deferred.addErrback(self._getError)

    @useMainThread
    def _getResult(self, results):
        """
        Append each search result into the ResultsListbox.
        """
        try:
            meta = results.pop(0)
            self._lastId = meta['lastId']
            logger.debug("tail returned %i results, last id is %s" % (len(results), self._lastId))
            if len(results) > 0:
                for evid,defaultfield,defaultvalue,fields in results:
                    evid = EVID(evid[0], evid[1])
                    self._results.append(evid, defaultfield, defaultvalue, fields)
                console.redraw()
            from twisted.internet import reactor
            self._delayed = reactor.callLater(self.interval, self._tail)
        except Exception, e:
            logger.exception(e)
コード例 #55
0
    def sendQuery(self, query):
        """
        :type query: `maay.p2pquerier.P2pQuery`
        """        
        print "P2pQuerier sendQuery %s : %s" % (query.qid, query)
        if self._sentQueries.has_key(query.qid):
            return
        print " ... query from %s:%s" % (query.client_host,
                                         query.client_port)
        for neighbor in self._selectTargetNeighbors(query):
            if (neighbor.ip, neighbor.port) == \
                   (query.client_host, query.client_port):
                continue
            proxy = Proxy(str(neighbor.getRpcUrl()))
            d = proxy.callRemote('distributedQuery', query.asKwargs())
	    d.addErrback(sendQueryErrback(neighbor, self.querier))
            self._sentQueries[query.qid] = query
            print "     ... sent to %s:%s %s" % (neighbor.ip,
                                                 neighbor.port,
                                                 neighbor.node_id)
コード例 #56
0
ファイル: command_search.py プロジェクト: nskriv/bnw
def cmd_search(request, query='', page='0'):
    if not query:
        defer.returnValue(dict(ok=False, desc='So where is your query?'))
    if len(query) > 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', query, int(page))
    except Exception:
        log.msg('SEARCH ERROR:\n\n' + traceback.format_exc())
        defer.returnValue(dict(ok=False, desc='Search internal error.'))
    else:
        if result is None:
            defer.returnValue(dict(ok=False, desc='Bad request.'))

    t = time.time() - start
    log.msg('Queried "%s" by %s. Found %s results in %.3fs.' % (
        query, request.user['name'] if request.user else '*', result['estimated'], t))
    defer.returnValue(dict(ok=True, format='search', **result))
コード例 #57
0
ファイル: test_xrpc.py プロジェクト: aderbenev/carchivetools
class TestServer(unittest.TestCase):
    timeout = 1.0
    def setUp(self):
        self.root = resource.buildResource('127.0.0.1:99999')
        self.site = Site(self.root) # TODO: what is timeout?
        self.serv = reactor.listenTCP(0, self.site, interface='127.0.0.1')
        P = self.serv.getHost().port
        url = 'http://127.0.0.1:%d/cgi-bin/ArchiveDataServer.cgi'%P
        self.client = Proxy(url)

    def tearDown(self):
        self.serv.stopListening()

    @defer.inlineCallbacks
    def test_info(self):
        R = yield self.client.callRemote('archiver.info')
        self.assertEqual(R ,resource._info)

    @defer.inlineCallbacks
    def test_archives(self):
        R = yield self.client.callRemote('archiver.archives')
        self.assertEqual(R ,resource._archives)