summaryrefslogtreecommitdiff
path: root/sleekxmpp/__init__.py
diff options
context:
space:
mode:
authorTom Nichols <tmnichols@gmail.com>2010-07-09 17:25:11 -0400
committerTom Nichols <tmnichols@gmail.com>2010-07-09 17:25:11 -0400
commit9c5285987dd5cc6052d04f113cae97806101e5d0 (patch)
tree43f1c62e79b741688a06e24f2758e445db8cc21b /sleekxmpp/__init__.py
parentd09cbef9a73b30b7da56ccbd6ee2558991d2f9cb (diff)
downloadslixmpp-9c5285987dd5cc6052d04f113cae97806101e5d0.tar.gz
slixmpp-9c5285987dd5cc6052d04f113cae97806101e5d0.tar.bz2
slixmpp-9c5285987dd5cc6052d04f113cae97806101e5d0.tar.xz
slixmpp-9c5285987dd5cc6052d04f113cae97806101e5d0.zip
removed ClientXMPP.server in favor of ClientXMPP.domain
Diffstat (limited to 'sleekxmpp/__init__.py')
-rw-r--r--sleekxmpp/__init__.py27
1 files changed, 7 insertions, 20 deletions
diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py
index dc847f30..a996999a 100644
--- a/sleekxmpp/__init__.py
+++ b/sleekxmpp/__init__.py
@@ -41,25 +41,16 @@ except ImportError:
srvsupport = False
-
-#class PresenceStanzaType(object):
-#
-# def fromXML(self, xml):
-# self.ptype = xml.get('type')
-
-
class ClientXMPP(basexmpp, XMLStream):
"""SleekXMPP's client class. Use only for good, not evil."""
def __init__(self, jid, password, ssl=False, plugin_config = {}, plugin_whitelist=[], escape_quotes=True):
- global srvsupport
XMLStream.__init__(self)
self.default_ns = 'jabber:client'
basexmpp.__init__(self)
self.plugin_config = plugin_config
self.escape_quotes = escape_quotes
self.set_jid(jid)
- self.server = None
self.port = 5222 # not used if DNS SRV is used
self.plugin_whitelist = plugin_whitelist
self.auto_reconnect = True
@@ -105,25 +96,25 @@ class ClientXMPP(basexmpp, XMLStream):
def connect(self, host=None, port=None):
"""Connect to the Jabber Server. Attempts SRV lookup, and if it fails, uses
- the JID server."""
+ the JID server. You can optionally specify a host/port if you're not using
+ DNS and want to connect to a server address that is different from the XMPP domain."""
if self.state['connected']: return True
- if host:
- self.server = host
+ if host: # if a host was specified, don't attempt a DNS lookup.
if port is None: port = self.port
else:
if not self.srvsupport:
- logging.debug("Did not supply (address, port) to connect to and no SRV support is installed (http://www.dnspython.org). Continuing to attempt connection, using domain from JID.")
+ logging.warn("Did not supply (address, port) to connect to and no SRV support is installed (http://www.dnspython.org). Continuing to attempt connection, using domain from JID.")
else:
logging.debug("Since no address is supplied, attempting SRV lookup.")
try:
- answers = dns.resolver.query("_xmpp-client._tcp.%s" % self.server, dns.rdatatype.SRV)
+ answers = dns.resolver.query("_xmpp-client._tcp.%s" % self.domain, dns.rdatatype.SRV)
except dns.resolver.NXDOMAIN:
- logging.debug("No appropriate SRV record found. Using JID server name.")
+ logging.info("No appropriate SRV record found for %s. Using domain as server address.", self.domain)
except dns.exception.DNSException:
# this could be a timeout or other DNS error. Worth retrying?
- logging.exception("DNS error during SRV query for %s. Using JID server name.", self.server)
+ logging.exception("DNS error during SRV query for %s. Using domain as server address.", self.domain)
else:
# pick a random answer, weighted by priority
# there are less verbose ways of doing this (random.choice() with answer * priority), but I chose this way anyway
@@ -140,16 +131,12 @@ class ClientXMPP(basexmpp, XMLStream):
if picked <= priority:
(host,port) = addresses[priority]
break
- # if SRV lookup was successful, we aren't using a particular server.
- self.server = None
if not host:
# if all else fails take server from JID.
(host,port) = (self.domain, self.port)
- self.server = None
logging.debug('Attempting connection to %s:%d', host, port )
- #TODO option to not use TLS?
result = XMLStream.connect(self, host, port)
if result:
self.event("connected")