本文整理汇总了Python中twisted.names.srvconnect.SRVConnector类的典型用法代码示例。如果您正苦于以下问题:Python SRVConnector类的具体用法?Python SRVConnector怎么用?Python SRVConnector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SRVConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getConnection
def _getConnection(self):
if self.host:
return reactor.connectTCP(self.host, self.port, self.factory)
else:
c = SRVConnector(reactor, 'xmpp-client', self.domain, self.factory)
c.connect()
return c
示例2: start
def start(self):
myJid = jid.JID(self.username)
factory = client.XMPPClientFactory(myJid, self.password)
factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)
connector = SRVConnector(reactor, 'xmpp-client', self.jabberserver, factory)
reactor.callLater(5, self.stop)
connector.connect()
示例3: connectSRV
def connectSRV(self, service, domain, *args, **kwargs):
SRVConnector = kwargs.pop('ConnectorClass', None)
if SRVConnector is None:
from twisted.names.srvconnect import SRVConnector
gtransport, factory = self._make_transport_and_factory()
c = SRVConnector(self.reactor, service, domain, factory, *args, **kwargs)
c.connect()
gtransport._init_transport()
return gtransport
示例4: connect
def connect(self):
if callable(self.override):
self.override(self.factory)
elif not self._isQueryNeeded():
self.factory.doStart()
self.factory.startedConnecting(self)
self._reallyConnect()
else:
SRVConnector.connect(self)
示例5: __init__
def __init__(self, client_jid, secret):
f = client.XMPPClientFactory(client_jid, secret)
f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected)
f.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected)
f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated)
f.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed)
connector = SRVConnector(reactor, 'xmpp-client', client_jid.host, f,
defaultPort=5222)
connector.connect()
示例6: __init__
def __init__(self, client_reactor, domain, factory):
""" Init """
SRVConnector.__init__(self, client_reactor, 'xmpp-client', domain, factory)
if isinstance(domain, unicode):
warnings.warn(
"Domain argument to XMPPClientConnector should be bytes, "
"not unicode",
stacklevel=2)
domain = domain.encode('ascii')
self.timeout = [1,3]
示例7: __init__
def __init__(self, reactor, jid, secret):
self.reactor = reactor
f = client.XMPPClientFactory(jid, secret)
f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected)
f.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected)
f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated)
f.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed)
connector = SRVConnector(reactor, "xmpp-client", jid.host, f, defaultPort=5222)
connector.connect()
self.finished = Deferred()
示例8: __init__
def __init__(self, service):
jid = JID('127.0.0.1')
f = client.XMPPClientFactory(jid, '')
f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected)
f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated)
connector = SRVConnector(
reactor, 'xmpp-client', jid.host, f, defaultPort=6523)
connector.connect()
self.finished = Deferred()
self.files = {}
self.service = service
示例9: __init__
def __init__(self, reactor, dn, factory,
overrides=None, bindAddress=None):
if not isinstance(dn, distinguishedname.DistinguishedName):
dn = distinguishedname.DistinguishedName(stringValue=dn)
if overrides is None:
overrides = {}
self.override = self._findOverRide(dn, overrides)
domain = dn.getDomainName() or ''
SRVConnector.__init__(self, reactor,
'ldap', domain, factory,
connectFuncKwArgs={'bindAddress': bindAddress})
示例10: connect
def connect(self, protocolFactory):
def _canceller(deferred):
connector.stopConnecting()
deferred.errback(
error.ConnectingCancelledError(connector.getDestination()))
try:
wf = _WrappingFactory(protocolFactory, _canceller)
connector = SRVConnector(self._reactor, self._service,
self._domain, wf, protocol=self._protocol)
connector.connect()
return wf._onConnection
except:
return defer.fail()
示例11: pickServer
def pickServer(self):
if self.override is None:
overriddenHost, overriddenPort = None, None
else:
overriddenHost, overriddenPort = self.override
if (overriddenHost is not None
and (overriddenPort is not None
or self.domain is None)):
host = overriddenHost
port = overriddenPort
else:
host, port = SRVConnector.pickServer(self)
if overriddenHost is not None:
host = overriddenHost
if overriddenPort is not None:
port = overriddenPort
try:
port = int(port)
except ValueError:
pass
assert host is not None
if port is None:
port = 389
return host, port
示例12: connect
def connect(self, server_address, service=None, protocol='tcp'):
"""
Connect to the given server_address.
Without the 'service' keyword, the server_address can be formatted
as HOST[:PORT] (if no port given, 8800 will be assumed).
If 'service' is used, it must be the name of a service to look up
using a DNS SRV record at the server_address (in this case, no port is
expected in the server_address). The 'protocol' is also sent used in
the DNS SRV lookup.
The 'protocol' keyword is ignored if 'service' is not used.
Examples:
c = Client()
# connect to example.com at port 8800
c.connect('example.com')
# connect to example.com at port 45
c.connect('example.com:45')
# look up the host and port using SRV, passing 'SIP' as the
## service name to the DNS SRV host at example.com
c.connect('example.com', service='SIP')
TODO: Twisted uses it's own lookup cache that appears to be
cleared when the process terminates. I am unsure whether that
cache respects SRV TTL; if not, long-living reconnecting
clients *might* not get a new lookup. Further testing is needed
to determine this.
"""
self.ip = server_address
if service:
connector = SRVConnector(reactor, service, server_address,
self.factory, protocol=protocol)
connector.connect()
else:
self.host, self.port = utils.parse_host_port(server_address, 8800)
try:
reactor.connectTCP(self.host, self.port, self.factory)
except error.ConnectionRefusedError, e:
logger.error(e)
# wraps the error in a slightly more generic ClientError
## and reraises
raise ClientError(str(e))
示例13: pickServer
def pickServer(self):
host, port = SRVConnector.pickServer(self)
if not self.servers and not self.orderedServers:
# no SRV record, fall back..
port = int(config()['xmpp']['port'])
return host, port
示例14: pickServer
def pickServer(self):
host, port = SRVConnector.pickServer(self)
if not self.servers and not self.orderedServers:
# no SRV record, fall back..
port = 5222
return host, port
示例15: pickServer
def pickServer(self):
assert self.servers is not None
assert self.orderedServers is not None
if not self.servers and not self.orderedServers:
# no SRV record, fall back..
return self.domain, 2855
return SRVConnector.pickServer(self)