Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def startService(self):
# if we're not started yet
if not self.cold_start:
self.start()
if not self.dispatcher_url:
self.dispatcher_url = self.config['dispatcher-url']
if self.config.has_key('listen') and not self.port:
self.host, self.port = self.config['listen'].split(':')
self.tub = Tub()
self.tub.listenOn('tcp:%d' % int(self.port))
self.tub.setLocation('%s:%d' % (self.host, int(self.port)))
self.tub.registerReference(self, self.name)
self.tub.startService()
self._createConnector()
def gotReference(remote):
print "got a RemoteReference"
print "asking it to add 1+2"
d = remote.callRemote("add", a=1, b=2)
d.addCallbacks(gotAnswer, gotError2)
def gotAnswer(answer):
print "the answer is", answer
reactor.stop()
if len(sys.argv) < 2:
print "Usage: pb2client.py URL"
sys.exit(1)
url = sys.argv[1]
tub = Tub()
tub.startService()
d = tub.getReference(url)
d.addCallbacks(gotReference, gotError1)
reactor.run()
def nodeid(pem):
# XXX < warner> we're moving to non-foolscap ed25519 pubkey
return Tub(certData=pem).tubID.lower()
print "got an error:", err
def gotRemote(remote):
o = Observer()
d = remote.callRemote("addObserver", observer=o)
d.addCallback(lambda res: remote.callRemote("push", num=2))
d.addCallback(lambda res: remote.callRemote("push", num=3))
d.addCallback(lambda res: remote.callRemote("add"))
d.addCallback(lambda res: remote.callRemote("pop"))
d.addCallback(printResult)
d.addCallback(lambda res: remote.callRemote("removeObserver", observer=o))
d.addErrback(gotError)
d.addCallback(lambda res: reactor.stop())
return d
url = sys.argv[1]
tub = Tub()
tub.startService()
d = tub.getReference(url)
d.addCallback(gotRemote)
reactor.run()
def run_service():
tub = Tub()
s = AgentService('simple_service', tub)
application = ts.Application('nodeset-service')
s.tub.setServiceParent(application)
return run(application)
def run_command(config):
c = dispatch_table[config.subCommand]()
tub = Tub()
try:
from twisted.internet import reactor
from twisted.internet.endpoints import clientFromString
from foolscap.connections import tor
CONTROL = os.environ.get("FOOLSCAP_TOR_CONTROL_PORT", "")
SOCKS = os.environ.get("FOOLSCAP_TOR_SOCKS_PORT", "")
if CONTROL:
h = tor.control_endpoint(clientFromString(reactor, CONTROL))
tub.addConnectionHintHandler("tor", h)
elif SOCKS:
h = tor.socks_endpoint(clientFromString(reactor, SOCKS))
tub.addConnectionHintHandler("tor", h)
#else:
# h = tor.default_socks()
# tub.addConnectionHintHandler("tor", h)
except ImportError:
def make_swissnum():
return generateSwissnumber(Tub.NAMEBITS)
# don't tell anyone our shoe size
return d
class Database(Referenceable):
def __init__(self):
self.users = {}
def addUser(self, name, age, shoe_size):
self.users[name] = UserRecord(name, age, shoe_size)
def remote_getuser(self, name):
return self.users[name]
db = Database()
db.addUser("alice", 34, 8)
db.addUser("bob", 25, 9)
tub = Tub()
tub.listenOn("tcp:12345")
tub.setLocation("localhost:12345")
url = tub.registerReference(db, "database")
print "the database is at:", url
tub.startService()
reactor.run()
def create_tub(ignored):
return Tub()