def __init__(self, repopath, port=50000): self.server = jsonrpc.Server( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(timeout=60.0, addr=("0.0.0.0", port))) repo = repository.Repo(repopath) fr = front.Front(repo) self.server.register_instance(fr, "front")
def __init__ (self, device=None, did=None,invitecode=None,\ pins=[None,None,None,None],pinsstate=["output",None,None,None],memdump=False): self.device = device if not self.device is None: lockdev(self.device) self.transport = jsonrpc.TransportSERIAL( port=device, baudrate=115200, logfunc=jsonrpc.log_file("myrpc.log")) self._mgr = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(radio=False, notification=False), self.transport) self.ana = dict.fromkeys( ("onenet", "nid", "did", "invitecode", "region", "channel", "version", "invitecode", "status", "nsmkey", "smkey"), None) self.clients = [] self.events = Asyncevent() self.ana["did"] = did self.ana["invitecode"] = invitecode self.pins = pins self.pinsstate = pinsstate self._pinsstandingunit = None self._pinsstandingonoff = None self._mem = dict.fromkeys( ("master_param", "base_param", "client_list", "peer"), None) if device is None: return
def __init__(self, service_name, host, port): self.service_name = service_name self.host = host self.addr = socket.gethostbyname(host) self.port = port self.server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(host, port))) self.hg_port = self.server.get_hg_port() self.bt_port = self.server.get_bt_port() self.free_space = self.server.get_free_space()
def tag_sentence(sentence): server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8080))) result = loads(server.parse(sentence)) tagged_sentence = [] for word in result[u'sentences'][0][u'words']: tagged_sentence.append([word[0], word[1][u'PartOfSpeech'].lower()]) #print tagged_sentence return tagged_sentence
def connect(url): m = re.match("boar://(.*?)(:[0-9]+)?/", url) assert m, "Not a valid boar url" address = m.group(1) port = 50000 if m.group(2): port = int(m.group(2)[1:]) #print "Connecting to '%s' on port %s" % (address, port) server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(address, port), timeout=60.0, limit=2**16)) return server.front
def __init__(self, parent=None): QtGui.QGraphicsView.__init__(self, parent) self.parent = parent # topologyInterface exchanges json messages with monitoring server #self.topologyInterface = TopologyInterface(self) self.topologyInterface = self.parent.parent.communication #self.topologyInterface.start() self.mininet = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(self.parent.parent.mininet_address, 31415))) self.setStyleSheet("background: black") self.topoScene = QtGui.QGraphicsScene(self) self.topoScene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) self.topoScene.setSceneRect(-300, -300, 600, 600) self.setScene(self.topoScene) self.setCacheMode(QtGui.QGraphicsView.CacheBackground) self.setRenderHint(QtGui.QPainter.Antialiasing) self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter) self.drawAccess = 'Default' #(utilization/te/et/etc) self.scale(0.9, 0.9) self.setMinimumSize(400, 400) # Pan self.setDragMode(self.ScrollHandDrag) self.setCursor(QtCore.Qt.ArrowCursor) # Connect signals to slots self.topologyInterface.topology_received_signal[object].connect \ (self.got_topo_msg) self.updateAllSignal.connect(self.updateAll) # Dictionaries holding node and link QGraphicsItems self.nodes = {} self.links = {} self.helloMessenger() self.get_nodes()
def run(self): import sys from corenlp import StanfordCoreNLP import jsonrpc sys.__stdin__ = sys.__stdout__ server = jsonrpc.Server( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("0.0.0.0", int(self.port)))) nlp = StanfordCoreNLP() server.register_function(nlp.parse) server.register_function(nlp.parse_file) print "registering parse_file" server.register_function(lambda *a, **k: 'pong', 'ping') try: server.serve() except KeyboardInterrupt: print("%d exiting" % self.port)
def __register(self): #return server = jsonrpc.Server( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=('', self.rpc_port)) ) #, logfunc=jsonrpc.log_file("myrpc.%i.log"%self.rpc_port) server.register_function(self.get_hg_port) server.register_function(self.get_bt_port) server.register_function(self.you_should_pull_from) server.register_function(self.please_mirror) server.register_function(self.get_active_info_hashes) server.register_function(self.get_free_space) server.register_function(self.please_stop_mirroring) t = threading.Thread(target=server.serve) t.daemon = True t.start() t = threading.Thread(target=self.repo.hg_serve, args=(self.hg_port, )) t.daemon = True t.start() print 'http://localhost:%i/' % self.hg_port print 'registering bonjour listener...' self.bj_name = self.name + '__' + uuid.uuid4().hex bjservice = pybonjour.DNSServiceRegister( name=self.bj_name, regtype="_delugefs._tcp", port=self.rpc_port, callBack=self.__bonjour_register_callback) try: while True: ready = select.select([bjservice], [], []) if bjservice in ready[0]: pybonjour.DNSServiceProcessResult(bjservice) except KeyboardInterrupt: pass
def parse(self, text): """ This function takes a text string, sends it to the Stanford parser, reads in the result, parses the results and returns a list with one dictionary entry for each parsed sentence, in JSON format. """ response = self._parse(text) logger.debug("Response: '%s'" % (response)) return json.dumps(response) if __name__ == '__main__': """ The code below starts an JSONRPC server """ parser = optparse.OptionParser(usage="%prog [OPTIONS]") parser.add_option('-p', '--port', default='8080', help='Port to serve on (default: 8080)') parser.add_option('-H', '--host', default='127.0.0.1', help='Host to serve on (default: 127.0.0.1. Use 0.0.0.0 to make public)') options, args = parser.parse_args() server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(options.host, int(options.port))), "corenlp-server.log") nlp = StanfordCoreNLP() server.register_function(nlp.parse) logger.info('Serving on http://%s:%s' % (options.host, options.port)) server.serve()
# create JSON-RPC client import jsonrpc import time import checklines_pi server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415))) # call a remote-procedure (with positional parameters) import os host = 'LOCALHOST' port = 8080 time.sleep(1) try: while 1: testVar = raw_input("Enter Command: ") if testVar=="report": result=server.getreport() elif testVar=="1": result = server.sendcommand("opengrab#A") elif testVar=="2": result = server.sendcommand("closegrabA") elif testVar=="3": result = server.sendcommand("turnslow#0500A") elif testVar=="4": result = server.sendcommand("turnslow#2500A")
def get_server(self, hostname='localhost', port=3456, timeout=300.0): version = jsonrpc.JsonRpc20() transport = jsonrpc.TransportTcpIp(addr=(hostname, port), timeout=timeout) server = jsonrpc.ServerProxy(version, transport) return server
def __init__(self): self.server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("128.10.4.66", 4056)))
# create a JSON-RPC-server import jsonrpc import time import threading import serial ser = serial.Serial('/dev/ttyS0', 9600, timeout=10) ser.close() ser.open() time.sleep(1) server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415), logfunc=jsonrpc.log_file("myrpc.log"))) voltC="nix" voltM="nix" globalanswer="standard" gotanswer=0 A3=0 B3=0 gripA=0 busy="0" connected=False def handle_data(data): global voltC global voltM global B3 global A3
response = self._parse(text) logger.debug("Response: '%s'" % (response)) return json.dumps(response) if __name__ == '__main__': """ The code below starts an JSONRPC server """ parser = optparse.OptionParser(usage="%prog [OPTIONS]") parser.add_option('-p', '--port', default='8080', help='Port to serve on (default: 8080)') parser.add_option( '-H', '--host', default='127.0.0.1', help='Host to serve on (default: 127.0.0.1. Use 0.0.0.0 to make public)' ) options, args = parser.parse_args() server = jsonrpc.Server( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(options.host, int(options.port)))) nlp = StanfordCoreNLP() server.register_function(nlp.parse) logger.info('Serving on http://%s:%s' % (options.host, options.port)) server.serve()
from scipy.spatial.distance import cosine import networkx as nx import en import sys from operator import itemgetter import csv reload(sys) sys.setdefaultencoding('utf-8') # Normalization and cleaning engine cucco = Cucco() # Connect to core nLP server coref_server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8080))) dep_server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.2", 8080))) normalizations = [ 'remove_accent_marks', ('replace_urls', { 'replacement': '' }), ('replace_emails', { 'replacement': '' }), 'remove_extra_whitespaces', ] rep = {
def __init__(self,transport): self._timing=0 # default for USB self.proxy=jsonrpc.ServerProxy( jsonrpc.JsonRpc20(),transport)
def coref_resolution(text): server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8080))) result = loads(server.parse(text)) return result
#!/usr/bin/python import jsonrpc import socket import random import json import sys print "dumping subscribed forums... please wait!" #rpc = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportSocket(addr="/tmp/testservice", sock_type=socket.AF_UNIX)) rpc = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportSocket(addr=("127.0.0.1", 11111))) print "loading forums..." forums = rpc.bridge.getForums() print "loading keyring..." gpgIdList = rpc.bridge.getGPGAllList() print "gen name hash..." gpgIds = {} for i in gpgIdList: n = rpc.bridge.getPeerName(i) #print n gpgIds[i] = n print "writing forums list..." with open('../jout/forums.json', 'w') as ffile: ffile.write(json.dumps(forums)) def dumpMsg(forumID, msgID): #print msgID msg = rpc.bridge.getForumMessage(forumID, msgID)
def __init__(self, host="127.0.0.1", port=8080): self.server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(host, port)))