本文整理汇总了Python中twisted.internet.protocol.ClientCreator类的典型用法代码示例。如果您正苦于以下问题:Python ClientCreator类的具体用法?Python ClientCreator怎么用?Python ClientCreator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClientCreator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
text = str(self.cmd.text())
if text:
self.output.clear()
c = ClientCreator(reactor, NovacomRun, self)
d = c.connectTCP('localhost', self.port)
d.addCallback(cmd_run, True, text)
示例2: writeMetric
def writeMetric(metric_path, value, timestamp, host, port, username, password,
vhost, exchange, spec=None, channel_number=1, ssl=False):
if not spec:
spec = txamqp.spec.load(os.path.normpath(
os.path.join(os.path.dirname(__file__), 'amqp0-8.xml')))
delegate = TwistedDelegate()
connector = ClientCreator(reactor, AMQClient, delegate=delegate,
vhost=vhost, spec=spec)
if ssl:
from twisted.internet.ssl import ClientContextFactory
conn = yield connector.connectSSL(host, port, ClientContextFactory())
else:
conn = yield connector.connectTCP(host, port)
yield conn.authenticate(username, password)
channel = yield conn.channel(channel_number)
yield channel.channel_open()
yield channel.exchange_declare(exchange=exchange, type="topic",
durable=True, auto_delete=False)
message = Content( "%f %d" % (value, timestamp) )
message["delivery mode"] = 2
channel.basic_publish(exchange=exchange, content=message, routing_key=metric_path)
yield channel.channel_close()
示例3: getList
def getList():
# For the sample client, below:
from twisted.internet import reactor
from twisted.internet.protocol import ClientCreator
creator = ClientCreator(reactor, amp.AMP)
host = '127.0.0.1'
import sys
if len(sys.argv) > 1:
host = sys.argv[1]
d = creator.connectTCP(host, 62308)
def connected(ampProto):
return ampProto.callRemote(GatewayAMPCommand, command=command)
d.addCallback(connected)
def resulted(result):
return result['result']
d.addCallback(resulted)
def done(result):
print('Done: %s' % (result,))
reactor.stop()
d.addCallback(done)
reactor.run()
示例4: callCommand
def callCommand(signaler, host, port, user, password, command):
print "at callCommand"
print "Running", command, "at", host, port
d = ClientCreator(reactor, ClientCommandTransport, signaler,
user, password, command).connectTCP(host, int(port))
d.addErrback(signaler.errback)
示例5: connect
def connect(self, server):
self.disconnect()
self.server = server
if not server:
return
username = server.getUsername()
if not username:
username = 'anonymous'
password = '[email protected]'
else:
password = server.getPassword()
host = server.getAddress()
passive = server.getPassive()
port = server.getPort()
timeout = 30 # TODO: make configurable
# XXX: we might want to add a guard so we don't try to connect to another host while a previous attempt is not timed out
if server.getConnectionType():
try:
ftps = ftplib.FTP_TLS()
ftps.connect(host,port)
ftps.login(username, password)
ftps.prot_p()
self.controlConnectionMade(ftps)
except ftplib.all_errors as e:
self.connectionFailed(e)
else:
creator = ClientCreator(reactor, FTPClient, username, password, passive = passive)
creator.connectTCP(host, port, timeout).addCallback(self.controlConnectionMade).addErrback(self.connectionFailed)
示例6: run
def run(self):
delegate = TwistedDelegate()
cc = ClientCreator(reactor, AMQClient, delegate=delegate,
vhost=self.vhost, spec=self.specfile)
connection = yield cc.connectTCP(self.host, self.port)
yield connection.authenticate(self.user, self.password)
channel = yield connection.channel(1)
yield channel.channel_open()
channel.queue_declare(queue="process_queue", durable=True)
# yield channel.queue_bind(
# queue="process_queue", exchange="worker",
# routing_key="test_routing_key")
yield channel.basic_consume(queue="process_queue", consumer_tag="test_consumer_tag", no_ack=True)
queue = yield connection.queue("test_consumer_tag")
while True:
pkg = yield queue.get()
msg = pickle.loads(pkg.content.body)
print msg
self.reply(channel, msg)
示例7: run
def run():
# Create the client
FTPClient.debug = 1
creator = ClientCreator(reactor, FTPClient, "admin", '1', passive=1)
creator.connectSSL("localhost", 2121,
ssl.ClientContextFactory()).addCallback(connectionMade).addErrback(connectionFailed)
reactor.run(installSignalHandlers=0)
示例8: connect
def connect(self, user, targetserver):
if targetserver not in self.ircd.servconfig["serverlinks"]:
if user:
user.sendMessage(irc.ERR_NOSUCHSERVER, targetserver, ":No link block exists")
return
def sendServerHandshake(protocol, password):
protocol.callRemote(
IntroduceServer,
name=self.ircd.name,
password=password,
description=self.ircd.servconfig["server_description"],
version=protocol_version,
commonmodules=self.ircd.common_modules,
)
protocol.sentDataBurst = False
servinfo = self.ircd.servconfig["serverlinks"][targetserver]
if "ip" not in servinfo or "port" not in servinfo:
return
if "bindaddress" in servinfo and "bindport" in servinfo:
bind = (servinfo["bindaddress"], servinfo["bindport"])
else:
bind = None
creator = ClientCreator(reactor, ServerProtocol, self.ircd)
if "ssl" in servinfo and servinfo["ssl"]:
d = creator.connectSSL(servinfo["ip"], servinfo["port"], self.ircd.ssl_cert, bindAddress=bind)
else:
d = creator.connectTCP(servinfo["ip"], servinfo["port"], bindAddress=bind)
d.addCallback(sendServerHandshake, servinfo["outgoing_password"])
示例9: __init__
def __init__(self, host, port, path, fileOrName, username = 'anonymous', \
password = '[email protected]', writeProgress = None, passive = True, \
supportPartial = False, *args, **kwargs):
timeout = 30
# We need this later
self.path = path
self.resume = supportPartial
# Initialize
self.currentlength = 0
self.totallength = None
if writeProgress and type(writeProgress) is not list:
writeProgress = [ writeProgress ]
self.writeProgress = writeProgress
# Output
if isinstance(fileOrName, str):
self.filename = fileOrName
self.file = None
else:
self.file = fileOrName
creator = ClientCreator(reactor, FTPClient, username, password, passive = passive)
creator.connectTCP(host, port, timeout).addCallback(self.controlConnectionMade).addErrback(self.connectionFailed)
self.deferred = defer.Deferred()
示例10: connect_to_rez
def connect_to_rez(rez_info):
dyno_id = rez_info.get('dyno_id')
cc = ClientCreator(reactor, ProcLiteProtocol)
(cc.connectSSL(rez_info.get('host'),
self.settings['dynohost_rendezvous_port'],
ssl.ClientContextFactory()).
addCallback(buildProtoCallback(dyno_id)))
示例11: initialise
def initialise(self):
self.perle = None
c = ClientCreator(reactor, PerleProtocol, self, self.user, self.password, self.relay)
deferred = c.connectTCP(self.ip, self.port)
deferred.addCallbacks(self.connected, self.error)
示例12: get_vbucket_data
def get_vbucket_data(host, port, vbucket, credentials):
cli = ClientCreator(reactor, DcpProtocol, vbucket, credentials)
conn = cli.connectTCP(host, port)
conn.addCallback(lambda x: x.authenticate()) \
.addCallback(lambda x: x.connect()) \
.addCallback(lambda x: x.failover_request())
reactor.run()
示例13: execute
def execute(host, port, df):
d = ClientCreator(reactor, ClientCommandTransport, df,
'root', '192168061', 'server',
'/etc/init.d/ossec restart',
).connectTCP(host, port)
d.addErrback(df.errback, **{'how': False})
示例14: installPreware
def installPreware(self):
port = self.getActivePort()
if port:
print 'Install preware'
c = ClientCreator(reactor, NovacomInstallIPKG, self, port)
d = c.connectTCP('localhost', port)
d.addCallback(cmd_installIPKG_URL, PREWARE)
示例15: do_connect
def do_connect():
"""Connect and authenticate."""
client_creator = ClientCreator(reactor, MemCacheProtocol)
client = yield client_creator.connectTCP(host=host, port=port,
timeout=timeout)
version = yield client.version()