本文整理汇总了Python中twisted.internet.reactor.connectUNIX函数的典型用法代码示例。如果您正苦于以下问题:Python connectUNIX函数的具体用法?Python connectUNIX怎么用?Python connectUNIX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connectUNIX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = OptionParser()
parser.add_option(
"--socket",
help="UNIX socket where melissi client listens",
default=os.path.expanduser("~/.config/melisi/melisi.sock"),
)
(options, args) = parser.parse_args()
commands = {
"auth": auth,
"disconnect": disconnect,
"connect": connect,
"register": register,
"checkbusy": checkbusy,
"sethost": sethost,
"deleteuser": deleteuser,
"addshare": addshare,
"removeshare": removeshare,
}
if len(args) < 1:
usage(commands)
sys.exit(0)
try:
commands[args[0]](args[1:])
except KeyError:
usage(commands)
sys.exit(1)
melisi_commander = MelisiCommander(command_list)
reactor.connectUNIX(options.socket, melisi_commander)
reactor.callLater(2, _timeout)
reactor.run()
示例2: testDumber
def testDumber(self):
filename = tempfile.mktemp()
l = reactor.listenUNIX(filename, Factory())
reactor.connectUNIX(filename, TestClientFactory())
for i in xrange(100):
reactor.iterate()
l.stopListening()
示例3: test_dumber
def test_dumber(self):
"""
L{IReactorUNIX.connectUNIX} can be used to connect a client to a server
started with L{IReactorUNIX.listenUNIX}.
"""
filename = self.mktemp()
serverFactory = MyServerFactory()
serverConnMade = defer.Deferred()
serverFactory.protocolConnectionMade = serverConnMade
unixPort = reactor.listenUNIX(filename, serverFactory)
self.addCleanup(unixPort.stopListening)
clientFactory = MyClientFactory()
clientConnMade = defer.Deferred()
clientFactory.protocolConnectionMade = clientConnMade
reactor.connectUNIX(filename, clientFactory)
d = defer.gatherResults([serverConnMade, clientConnMade])
def allConnected(args):
serverProtocol, clientProtocol = args
# Incidental assertion which may or may not be redundant with some
# other test. This probably deserves its own test method.
self.assertEqual(clientFactory.peerAddresses,
[address.UNIXAddress(filename)])
clientProtocol.transport.loseConnection()
serverProtocol.transport.loseConnection()
d.addCallback(allConnected)
return d
示例4: connectUNIX
def connectUNIX(self, sock_path):
if not self.factory:
self.factory = pb.PBClientFactory()
self.factory.clientConnectionFailed = self._onConnectionFailed
self.factory.clientConnectionLost = self._onConnectionLost
reactor.connectUNIX(sock_path)
self.factory.getRootObject().addCallbacks(self.connected, self.onError)
示例5: startFactory
def startFactory(self):
"""Tell the other end that we are done starting up.
"""
# Import reactor here to avoid installing default at startup
from twisted.internet import reactor
reactor.connectUNIX("zomne_startup_complete.socket", NotificationFactory())
示例6: listen
def listen(self, reactor):
if self.simulate:
reactor.connectUNIX(self.get_simsocket(self.uri), PeerFactory(peer), timeout = 2)
self.debug("Listening at", self.get_simsocket(self.uri))
else:
reactor.listenTCP(self.port, ServerFactory(self, self.serversession), interface = self.host)
self.debug("Listening at", self.uri)
示例7: render
def render(self, request):
"""Render this request, from my server.
This will always be asynchronous, and therefore return NOT_DONE_YET.
It spins off a request to the pb client, and either adds it to the list
of pending issues or requests it immediately, depending on if the
client is already connected.
"""
if not self.publisher:
self.pending.append(request)
if not self.waiting:
self.waiting = 1
bf = pb.PBClientFactory()
timeout = 10
if self.host == "unix":
reactor.connectUNIX(self.port, bf, timeout)
else:
reactor.connectTCP(self.host, self.port, bf, timeout)
d = bf.getRootObject()
d.addCallbacks(self.connected, self.notConnected)
else:
i = Issue(request)
self.publisher.callRemote('request', request).addCallbacks(i.finished, i.failed)
return server.NOT_DONE_YET
示例8: connect
def connect(host, port, options, verifyHostKey, userAuthObject):
if options['nocache']:
return defer.fail(ConchError('not using connection caching'))
d = defer.Deferred()
filename = os.path.expanduser("~/.conch-%s-%s-%i" % (userAuthObject.user, host, port))
factory = SSHUnixClientFactory(d, options, userAuthObject)
reactor.connectUNIX(filename, factory, timeout=2, checkPID=1)
return d
示例9: setUp
def setUp(self):
sock = self.mktemp()
serverfactory = DummyCacheServer()
self.server = reactor.listenUNIX(sock, serverfactory)
deferred = defer.Deferred()
self.client = protocol.RRDCacheClient(deferred, True)
reactor.connectUNIX(sock, self.client)
return deferred
示例10: do_connect
def do_connect(listener, reconnect = False):
if not hasattr(socket, 'AF_UNIX') or common.config.getboolean('Client', 'force_tcp'):
logging.info('Open tcp port')
reactor.connectTCP('localhost', common.config.getint('Server', 'port'), ConnectionFactory(listener, reconnect))
else:
logging.info('Open file socket')
reactor.connectUNIX(common.config.get('Server', 'file'), ConnectionFactory(listener, reconnect))
logging.info("Client started")
示例11: testMode
def testMode(self):
filename = tempfile.mktemp()
l = reactor.listenUNIX(filename, Factory(), mode = 0600)
self.assertEquals(stat.S_IMODE(os.stat(filename)[0]), 0600)
reactor.connectUNIX(filename, TestClientFactory())
for i in xrange(100):
reactor.iterate()
l.stopListening()
示例12: connect
def connect(self):
if self._node["type"] == "tcp":
reactor.connectTCP(self._node["host"], self._node["port"], self)
elif self._node["type"] == "unix":
reactor.connectUNIX(self._node["addr"], self)
else:
log.err("Unknown connect type")
self.getRootObject().addCallback(self._proxy.insert, self._node["name"])
示例13: makeUnixConnection
def makeUnixConnection(path, poolsize, reconnect, isLazy):
factory = TarantoolFactory(poolsize, isLazy, UnixConnectionHandler)
factory.continueTrying = reconnect
for x in xrange(poolsize):
reactor.connectUNIX(path, factory)
if isLazy:
return factory.handler
else:
return factory.deferred
示例14: _run
def _run(config, args):
factory = pb.PBClientFactory()
reactor.connectUNIX(config.socket, factory)
try:
perspective = yield factory.login(UsernamePassword("guest", "guest"))
yield perspective.callRemote('add_dns', args[0], args[1], int(args[2]))
print "Record added"
except Exception as e:
print "Error: ", str(e)
reactor.stop()
示例15: testStoppingServer
def testStoppingServer(self):
factory = protocol.ServerFactory()
factory.protocol = wire.Echo
t = internet.UNIXServer('echo.skt', factory)
t.startService()
t.stopService()
self.failIf(t.running)
factory = protocol.ClientFactory()
d = defer.Deferred()
factory.clientConnectionFailed = lambda *args: d.callback(None)
reactor.connectUNIX('echo.skt', factory)
return d