summaryrefslogtreecommitdiff
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
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
-rw-r--r--sleekxmpp/__init__.py27
-rw-r--r--sleekxmpp/plugins/gmail_notify.py2
-rw-r--r--sleekxmpp/plugins/xep_0078.py2
-rw-r--r--sleekxmpp/plugins/xep_0092.py2
-rw-r--r--sleekxmpp/plugins/xep_0199.py4
-rwxr-xr-xsleekxmpp/tests/testpubsub.py2
6 files changed, 13 insertions, 26 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")
diff --git a/sleekxmpp/plugins/gmail_notify.py b/sleekxmpp/plugins/gmail_notify.py
index e49815c6..b839311e 100644
--- a/sleekxmpp/plugins/gmail_notify.py
+++ b/sleekxmpp/plugins/gmail_notify.py
@@ -33,7 +33,7 @@ class gmail_notify(base.base_plugin):
def handler_gmailcheck(self, payload):
#TODO XEP 30 should cache results and have getFeature
- result = self.xmpp['xep_0030'].getInfo(self.xmpp.server)
+ result = self.xmpp['xep_0030'].getInfo(self.xmpp.domain)
features = []
for feature in result.findall('{http://jabber.org/protocol/disco#info}query/{http://jabber.org/protocol/disco#info}feature'):
features.append(feature.get('var'))
diff --git a/sleekxmpp/plugins/xep_0078.py b/sleekxmpp/plugins/xep_0078.py
index f8732905..e1e31e46 100644
--- a/sleekxmpp/plugins/xep_0078.py
+++ b/sleekxmpp/plugins/xep_0078.py
@@ -45,7 +45,7 @@ class xep_0078(base.base_plugin):
logging.debug("Starting jabber:iq:auth Authentication")
auth_request = self.xmpp.makeIqGet()
auth_request_query = ET.Element('{jabber:iq:auth}query')
- auth_request.attrib['to'] = self.xmpp.server
+ auth_request.attrib['to'] = self.xmpp.domain
username = ET.Element('username')
username.text = self.xmpp.username
auth_request_query.append(username)
diff --git a/sleekxmpp/plugins/xep_0092.py b/sleekxmpp/plugins/xep_0092.py
index aeebbe0c..22ae919d 100644
--- a/sleekxmpp/plugins/xep_0092.py
+++ b/sleekxmpp/plugins/xep_0092.py
@@ -38,7 +38,7 @@ class xep_0092(base.base_plugin):
def report_version(self, xml):
iq = self.xmpp.makeIqResult(xml.get('id', 'unknown'))
- iq.attrib['to'] = xml.get('from', self.xmpp.server)
+ iq.attrib['to'] = xml.get('from', self.xmpp.domain)
query = ET.Element('{jabber:iq:version}query')
name = ET.Element('name')
name.text = self.name
diff --git a/sleekxmpp/plugins/xep_0199.py b/sleekxmpp/plugins/xep_0199.py
index 1bd8d9f9..9ad89374 100644
--- a/sleekxmpp/plugins/xep_0199.py
+++ b/sleekxmpp/plugins/xep_0199.py
@@ -41,14 +41,14 @@ class xep_0199(base.base_plugin):
def handler_pingserver(self, xml):
if not self.running:
time.sleep(self.config.get('frequency', 300))
- while self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is not False:
+ while self.sendPing(self.xmpp.domain, self.config.get('timeout', 30)) is not False:
time.sleep(self.config.get('frequency', 300))
logging.debug("Did not recieve ping back in time. Requesting Reconnect.")
self.xmpp.disconnect(reconnect=True)
def handler_ping(self, xml):
iq = self.xmpp.makeIqResult(xml.get('id', 'unknown'))
- iq.attrib['to'] = xml.get('from', self.xmpp.server)
+ iq.attrib['to'] = xml.get('from', self.xmpp.domain)
self.xmpp.send(iq)
def sendPing(self, jid, timeout = 30):
diff --git a/sleekxmpp/tests/testpubsub.py b/sleekxmpp/tests/testpubsub.py
index ed9dd5c2..5c9bf770 100755
--- a/sleekxmpp/tests/testpubsub.py
+++ b/sleekxmpp/tests/testpubsub.py
@@ -43,7 +43,7 @@ class testps(sleekxmpp.ClientXMPP):
self.node = "pstestnode_%s"
self.pshost = pshost
if pshost is None:
- self.pshost = self.server
+ self.pshost = self.domain
self.nodenum = int(nodenum)
self.leafnode = self.nodenum + 1
self.collectnode = self.nodenum + 2