|
|
82b6ca |
diff --git jabberpy-0.5-0/jabber/__init__.py jabberpy-0.5-0/jabber/__init__.py
|
|
|
82b6ca |
index ba26086..8d134bd 100644
|
|
|
82b6ca |
--- jabberpy-0.5-0/jabber/__init__.py
|
|
|
82b6ca |
+++ jabberpy-0.5-0/jabber/__init__.py
|
|
|
82b6ca |
@@ -1,6 +1,10 @@
|
|
|
82b6ca |
-__all__ = []
|
|
|
82b6ca |
+import sys
|
|
|
82b6ca |
+if sys.version_info[0] == 3:
|
|
|
82b6ca |
+ from . import jabber
|
|
|
82b6ca |
+else:
|
|
|
82b6ca |
+ import jabber
|
|
|
82b6ca |
|
|
|
82b6ca |
-import jabber
|
|
|
82b6ca |
+__all__ = []
|
|
|
82b6ca |
|
|
|
82b6ca |
for __s in dir(jabber):
|
|
|
82b6ca |
__val = getattr(jabber, __s)
|
|
|
82b6ca |
diff --git jabberpy-0.5-0/jabber/debug.py jabberpy-0.5-0/jabber/debug.py
|
|
|
82b6ca |
index 4615697..b9ee00d 100644
|
|
|
82b6ca |
--- jabberpy-0.5-0/jabber/debug.py
|
|
|
82b6ca |
+++ jabberpy-0.5-0/jabber/debug.py
|
|
|
82b6ca |
@@ -41,9 +41,13 @@ in this code
|
|
|
82b6ca |
|
|
|
82b6ca |
import sys
|
|
|
82b6ca |
import time
|
|
|
82b6ca |
-from string import join
|
|
|
82b6ca |
|
|
|
82b6ca |
-import types
|
|
|
82b6ca |
+if sys.version_info[0] == 3:
|
|
|
82b6ca |
+ StringType = (str, bytes)
|
|
|
82b6ca |
+ UnicodeType = str
|
|
|
82b6ca |
+else:
|
|
|
82b6ca |
+ StringType = basestring
|
|
|
82b6ca |
+ UnicodeType = unicode
|
|
|
82b6ca |
|
|
|
82b6ca |
|
|
|
82b6ca |
debug_flags = []
|
|
|
82b6ca |
@@ -164,10 +168,10 @@ class Debug:
|
|
|
82b6ca |
):
|
|
|
82b6ca |
|
|
|
82b6ca |
if type(active_flags) not in [type([]), type(())]:
|
|
|
82b6ca |
- print '***'
|
|
|
82b6ca |
- print '*** Invalid or oldformat debug param given: %s' % active_flags
|
|
|
82b6ca |
- print '*** please correct your param, should be of [] type!'
|
|
|
82b6ca |
- print '*** Due to this, full debuging is enabled'
|
|
|
82b6ca |
+ print('***')
|
|
|
82b6ca |
+ print('*** Invalid or oldformat debug param given: %s' % active_flags)
|
|
|
82b6ca |
+ print('*** please correct your param, should be of [] type!')
|
|
|
82b6ca |
+ print('*** Due to this, full debuging is enabled')
|
|
|
82b6ca |
active_flags=[DBG_ALWAYS]
|
|
|
82b6ca |
|
|
|
82b6ca |
if welcome == -1:
|
|
|
82b6ca |
@@ -182,7 +186,7 @@ class Debug:
|
|
|
82b6ca |
try:
|
|
|
82b6ca |
self._fh = open(log_file,'w')
|
|
|
82b6ca |
except:
|
|
|
82b6ca |
- print 'ERROR: can open %s for writing'
|
|
|
82b6ca |
+ print('ERROR: can open %s for writing')
|
|
|
82b6ca |
sys.exit(0)
|
|
|
82b6ca |
else: ## assume its a stream type object
|
|
|
82b6ca |
self._fh = log_file
|
|
|
82b6ca |
@@ -190,8 +194,7 @@ class Debug:
|
|
|
82b6ca |
self._fh = sys.stdout
|
|
|
82b6ca |
|
|
|
82b6ca |
if time_stamp not in (0,1,2):
|
|
|
82b6ca |
- msg2 = '%s' % time_stamp
|
|
|
82b6ca |
- raise 'Invalid time_stamp param', msg2
|
|
|
82b6ca |
+ raise Exception('Invalid time_stamp param: %s' % time_stamp)
|
|
|
82b6ca |
self.prefix = prefix
|
|
|
82b6ca |
self.sufix = sufix
|
|
|
82b6ca |
self.time_stamp = time_stamp
|
|
|
82b6ca |
@@ -214,8 +217,7 @@ class Debug:
|
|
|
82b6ca |
if type(flag_show) in (type(''), type(None)):
|
|
|
82b6ca |
self.flag_show = flag_show
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
- msg2 = '%s' % type(flag_show )
|
|
|
82b6ca |
- raise 'Invalid type for flag_show!', msg2
|
|
|
82b6ca |
+ raise Exception('Invalid type for flag_show: %s' % type(flag_show))
|
|
|
82b6ca |
|
|
|
82b6ca |
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -271,7 +273,7 @@ class Debug:
|
|
|
82b6ca |
# dont print "None", just show the separator
|
|
|
82b6ca |
output = '%s %s' % ( output, self.flag_show )
|
|
|
82b6ca |
|
|
|
82b6ca |
- if type(msg)==type(u'') and self.encoding:
|
|
|
82b6ca |
+ if isinstance(msg, UnicodeType) and self.encoding:
|
|
|
82b6ca |
msg=msg.encode(self.encoding, 'replace')
|
|
|
82b6ca |
|
|
|
82b6ca |
output = '%s%s%s' % ( output, msg, suf )
|
|
|
82b6ca |
@@ -321,11 +323,11 @@ class Debug:
|
|
|
82b6ca |
if not active_flags:
|
|
|
82b6ca |
#no debuging at all
|
|
|
82b6ca |
self.active = []
|
|
|
82b6ca |
- elif type( active_flags ) in ( types.TupleType, types.ListType ):
|
|
|
82b6ca |
+ elif isinstance(active_flags, (tuple, list)):
|
|
|
82b6ca |
flags = self._as_one_list( active_flags )
|
|
|
82b6ca |
for t in flags:
|
|
|
82b6ca |
if t not in debug_flags:
|
|
|
82b6ca |
- print 'Invalid debugflag given', t
|
|
|
82b6ca |
+ print('Invalid debugflag given', t)
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
ok_flags.append( t )
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -360,7 +362,7 @@ class Debug:
|
|
|
82b6ca |
|
|
|
82b6ca |
This code organises lst and remves dupes
|
|
|
82b6ca |
"""
|
|
|
82b6ca |
- if type( items ) <> type( [] ) and type( items ) <> type( () ):
|
|
|
82b6ca |
+ if not isinstance(items, (tuple, list)):
|
|
|
82b6ca |
return [ items ]
|
|
|
82b6ca |
r = []
|
|
|
82b6ca |
for l in items:
|
|
|
82b6ca |
@@ -377,9 +379,8 @@ class Debug:
|
|
|
82b6ca |
|
|
|
82b6ca |
def _append_unique_str( self, lst, item ):
|
|
|
82b6ca |
"""filter out any dupes."""
|
|
|
82b6ca |
- if type(item) <> type(''):
|
|
|
82b6ca |
- msg2 = '%s' % item
|
|
|
82b6ca |
- raise 'Invalid item type (should be string)',msg2
|
|
|
82b6ca |
+ if not isinstance(item, StringType):
|
|
|
82b6ca |
+ raise Exception('Invalid item type (should be string): %s' % type(item))
|
|
|
82b6ca |
if item not in lst:
|
|
|
82b6ca |
lst.append( item )
|
|
|
82b6ca |
return lst
|
|
|
82b6ca |
@@ -389,9 +390,8 @@ class Debug:
|
|
|
82b6ca |
'verify that flag is defined.'
|
|
|
82b6ca |
if flags:
|
|
|
82b6ca |
for f in self._as_one_list( flags ):
|
|
|
82b6ca |
- if not f in debug_flags:
|
|
|
82b6ca |
- msg2 = '%s' % f
|
|
|
82b6ca |
- raise 'Invalid debugflag given', msg2
|
|
|
82b6ca |
+ if f not in debug_flags:
|
|
|
82b6ca |
+ raise Exception('Invalid debugflag given: %s' % f)
|
|
|
82b6ca |
|
|
|
82b6ca |
def _remove_dupe_flags( self ):
|
|
|
82b6ca |
"""
|
|
|
82b6ca |
diff --git jabberpy-0.5-0/jabber/jabber.py jabberpy-0.5-0/jabber/jabber.py
|
|
|
82b6ca |
index ab9d9b3..c6c97c7 100644
|
|
|
82b6ca |
--- jabberpy-0.5-0/jabber/jabber.py
|
|
|
82b6ca |
+++ jabberpy-0.5-0/jabber/jabber.py
|
|
|
82b6ca |
@@ -64,17 +64,23 @@ An example of usage for a simple client would be ( only psuedo code !)
|
|
|
82b6ca |
|
|
|
82b6ca |
# $Id: jabber.py,v 1.58 2004/01/18 05:27:10 snakeru Exp $
|
|
|
82b6ca |
|
|
|
82b6ca |
-import xmlstream
|
|
|
82b6ca |
import time
|
|
|
82b6ca |
import hashlib
|
|
|
82b6ca |
+import sys
|
|
|
82b6ca |
+
|
|
|
82b6ca |
+if sys.version_info[0] == 3:
|
|
|
82b6ca |
+ from . import xmlstream
|
|
|
82b6ca |
+ StringType = (str, bytes)
|
|
|
82b6ca |
+ UnicodeType = str
|
|
|
82b6ca |
+else:
|
|
|
82b6ca |
+ import xmlstream
|
|
|
82b6ca |
+ StringType = basestring
|
|
|
82b6ca |
+ UnicodeType = unicode
|
|
|
82b6ca |
|
|
|
82b6ca |
debug=xmlstream.debug
|
|
|
82b6ca |
|
|
|
82b6ca |
VERSION = xmlstream.VERSION
|
|
|
82b6ca |
|
|
|
82b6ca |
-False = 0;
|
|
|
82b6ca |
-True = 1;
|
|
|
82b6ca |
-
|
|
|
82b6ca |
timeout = 300
|
|
|
82b6ca |
|
|
|
82b6ca |
DBG_INIT, DBG_ALWAYS = debug.DBG_INIT, debug.DBG_ALWAYS
|
|
|
82b6ca |
@@ -179,14 +185,14 @@ RS_EXT_PENDING = 0
|
|
|
82b6ca |
def ustr(what):
|
|
|
82b6ca |
"""If sending object is already a unicode str, just
|
|
|
82b6ca |
return it, otherwise convert it using xmlstream.ENCODING"""
|
|
|
82b6ca |
- if type(what) == type(u''):
|
|
|
82b6ca |
+ if isinstance(what, UnicodeType):
|
|
|
82b6ca |
r = what
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
try: r = what.__str__()
|
|
|
82b6ca |
except AttributeError: r = str(what)
|
|
|
82b6ca |
# make sure __str__() didnt return a unicode
|
|
|
82b6ca |
- if type(r) <> type(u''):
|
|
|
82b6ca |
- r = unicode(r,xmlstream.ENCODING,'replace')
|
|
|
82b6ca |
+ if not isinstance(r, UnicodeType):
|
|
|
82b6ca |
+ r = UnicodeType(r,xmlstream.ENCODING,'replace')
|
|
|
82b6ca |
return r
|
|
|
82b6ca |
xmlstream.ustr = ustr
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -218,17 +224,17 @@ class Connection(xmlstream.Client):
|
|
|
82b6ca |
|
|
|
82b6ca |
def setMessageHandler(self, func, type='', chainOutput=False):
|
|
|
82b6ca |
"""Back compartibility method"""
|
|
|
82b6ca |
- print "WARNING! setMessageHandler(...) method is obsolette, use registerHandler('message',...) instead."
|
|
|
82b6ca |
+ print("WARNING! setMessageHandler(...) method is obsolette, use registerHandler('message',...) instead.")
|
|
|
82b6ca |
return self.registerHandler('message', func, type, chained=chainOutput)
|
|
|
82b6ca |
|
|
|
82b6ca |
def setPresenceHandler(self, func, type='', chainOutput=False):
|
|
|
82b6ca |
"""Back compartibility method"""
|
|
|
82b6ca |
- print "WARNING! setPresenceHandler(...) method is obsolette, use registerHandler('presence',...) instead."
|
|
|
82b6ca |
+ print("WARNING! setPresenceHandler(...) method is obsolette, use registerHandler('presence',...) instead.")
|
|
|
82b6ca |
return self.registerHandler('presence', func, type, chained=chainOutput)
|
|
|
82b6ca |
|
|
|
82b6ca |
def setIqHandler(self, func, type='', ns=''):
|
|
|
82b6ca |
"""Back compartibility method"""
|
|
|
82b6ca |
- print "WARNING! setIqHandler(...) method is obsolette, use registerHandler('iq',...) instead."
|
|
|
82b6ca |
+ print("WARNING! setIqHandler(...) method is obsolette, use registerHandler('iq',...) instead.")
|
|
|
82b6ca |
return self.registerHandler('iq', func, type, ns)
|
|
|
82b6ca |
|
|
|
82b6ca |
def header(self):
|
|
|
82b6ca |
@@ -248,7 +254,7 @@ class Connection(xmlstream.Client):
|
|
|
82b6ca |
|
|
|
82b6ca |
def _expectedIqHandler(self, conn, iq_obj):
|
|
|
82b6ca |
if iq_obj.getAttr('id') and \
|
|
|
82b6ca |
- self._expected.has_key(iq_obj.getAttr('id')):
|
|
|
82b6ca |
+ iq_obj.getAttr('id') in self._expected:
|
|
|
82b6ca |
self._expected[iq_obj.getAttr('id')] = iq_obj
|
|
|
82b6ca |
raise NodeProcessed('No need for further Iq processing.')
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -257,7 +263,7 @@ class Connection(xmlstream.Client):
|
|
|
82b6ca |
Builds the relevant jabber.py object and dispatches it
|
|
|
82b6ca |
to a relevant function or callback."""
|
|
|
82b6ca |
name=stanza.getName()
|
|
|
82b6ca |
- if not self.handlers.has_key(name):
|
|
|
82b6ca |
+ if name not in self.handlers:
|
|
|
82b6ca |
self.DEBUG("whats a tag -> " + name,DBG_NODE_UNKNOWN)
|
|
|
82b6ca |
name='unknown'
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
@@ -274,9 +280,9 @@ class Connection(xmlstream.Client):
|
|
|
82b6ca |
self.DEBUG("dispatch called for: name->%s ns->%s"%(name,ns),DBG_DISPATCH)
|
|
|
82b6ca |
|
|
|
82b6ca |
typns=typ+ns
|
|
|
82b6ca |
- if not self.handlers[name].has_key(ns): ns=''
|
|
|
82b6ca |
- if not self.handlers[name].has_key(typ): typ=''
|
|
|
82b6ca |
- if not self.handlers[name].has_key(typns): typns=''
|
|
|
82b6ca |
+ if ns not in self.handlers[name]: ns=''
|
|
|
82b6ca |
+ if typ not in self.handlers[name]: typ=''
|
|
|
82b6ca |
+ if typns not in self.handlers[name]: typns=''
|
|
|
82b6ca |
|
|
|
82b6ca |
chain=[]
|
|
|
82b6ca |
for key in ['default',typ,ns,typns]: # we will use all handlers: from very common to very particular
|
|
|
82b6ca |
@@ -337,7 +343,7 @@ class Connection(xmlstream.Client):
|
|
|
82b6ca |
have lower priority that common handlers.
|
|
|
82b6ca |
"""
|
|
|
82b6ca |
if not type and not ns: type='default'
|
|
|
82b6ca |
- if not self.handlers[name].has_key(type+ns): self.handlers[name][type+ns]=[]
|
|
|
82b6ca |
+ if type+ns not in self.handlers[name]: self.handlers[name][type+ns]=[]
|
|
|
82b6ca |
if makefirst: self.handlers[name][type+ns].insert({'chain':chained,'func':handler,'system':system})
|
|
|
82b6ca |
else: self.handlers[name][type+ns].append({'chain':chained,'func':handler,'system':system})
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -525,16 +531,23 @@ class Client(Connection):
|
|
|
82b6ca |
token = auth_ret_query.getTag('token').getData()
|
|
|
82b6ca |
seq = auth_ret_query.getTag('sequence').getData()
|
|
|
82b6ca |
self.DEBUG("zero-k authentication supported",(DBG_INIT,DBG_NODE_IQ))
|
|
|
82b6ca |
- hash = hashlib.new('sha1', hashlib.new('sha1', passwd).hexdigest()+token).hexdigest()
|
|
|
82b6ca |
- for foo in xrange(int(seq)): hash = hashlib.new('sha1', hash).hexdigest()
|
|
|
82b6ca |
+ # Unicode-objects must be encoded before hashing
|
|
|
82b6ca |
+ if isinstance(passwd, UnicodeType):
|
|
|
82b6ca |
+ pass_enc = passwd.encode('utf-8')
|
|
|
82b6ca |
+ else:
|
|
|
82b6ca |
+ pass_enc = passwd
|
|
|
82b6ca |
+ hash = hashlib.new('sha1', hashlib.new('sha1', pass_enc).hexdigest()+token).hexdigest()
|
|
|
82b6ca |
+ for foo in range(int(seq)): hash = hashlib.new('sha1', hash).hexdigest()
|
|
|
82b6ca |
q.insertTag('hash').insertData(hash)
|
|
|
82b6ca |
|
|
|
82b6ca |
elif auth_ret_query.getTag('digest'):
|
|
|
82b6ca |
|
|
|
82b6ca |
self.DEBUG("digest authentication supported",(DBG_INIT,DBG_NODE_IQ))
|
|
|
82b6ca |
digest = q.insertTag('digest')
|
|
|
82b6ca |
- digest.insertData(hashlib.new('sha1',
|
|
|
82b6ca |
- self.getIncomingID() + passwd).hexdigest() )
|
|
|
82b6ca |
+ idp = self.getIncomingID() + passwd
|
|
|
82b6ca |
+ if isinstance(idp, UnicodeType):
|
|
|
82b6ca |
+ idp = idp.encode('uft-8')
|
|
|
82b6ca |
+ digest.insertData(hashlib.new('sha1', idp).hexdigest() )
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
self.DEBUG("plain text authentication supported",(DBG_INIT,DBG_NODE_IQ))
|
|
|
82b6ca |
q.insertTag('password').insertData(passwd)
|
|
|
82b6ca |
@@ -729,7 +742,7 @@ class Protocol(xmlstream.Node):
|
|
|
82b6ca |
|
|
|
82b6ca |
def asNode(self):
|
|
|
82b6ca |
"""Back compartibility method"""
|
|
|
82b6ca |
- print 'WARNING! "asNode()" method is obsolette, use Protocol object as Node object instead.'
|
|
|
82b6ca |
+ print('WARNING! "asNode()" method is obsolette, use Protocol object as Node object instead.')
|
|
|
82b6ca |
return self
|
|
|
82b6ca |
|
|
|
82b6ca |
def getError(self):
|
|
|
82b6ca |
@@ -822,7 +835,7 @@ class Protocol(xmlstream.Node):
|
|
|
82b6ca |
XML document"""
|
|
|
82b6ca |
x = self.setX(namespace)
|
|
|
82b6ca |
|
|
|
82b6ca |
- if type(payload) == type('') or type(payload) == type(u''):
|
|
|
82b6ca |
+ if isinstance(payload, StringType):
|
|
|
82b6ca |
payload = xmlstream.NodeBuilder(payload).getDom()
|
|
|
82b6ca |
|
|
|
82b6ca |
x.kids = [] # should be a method for this realy
|
|
|
82b6ca |
@@ -961,7 +974,7 @@ class Message(Protocol):
|
|
|
82b6ca |
return m
|
|
|
82b6ca |
|
|
|
82b6ca |
def build_reply(self, reply_txt=''):
|
|
|
82b6ca |
- print "WARNING: build_reply method is obsolette. Use buildReply instead."
|
|
|
82b6ca |
+ print("WARNING: build_reply method is obsolette. Use buildReply instead.")
|
|
|
82b6ca |
return self.buildReply(reply_txt)
|
|
|
82b6ca |
|
|
|
82b6ca |
#############################################################################
|
|
|
82b6ca |
@@ -1059,7 +1072,7 @@ class Iq(Protocol):
|
|
|
82b6ca |
if q is None:
|
|
|
82b6ca |
q = self.insertTag('query')
|
|
|
82b6ca |
|
|
|
82b6ca |
- if type(payload) == type('') or type(payload) == type(u''):
|
|
|
82b6ca |
+ if isinstance(payload, StringType):
|
|
|
82b6ca |
payload = xmlstream.NodeBuilder(payload).getDom()
|
|
|
82b6ca |
|
|
|
82b6ca |
if not add: q.kids = []
|
|
|
82b6ca |
@@ -1138,7 +1151,7 @@ class Roster:
|
|
|
82b6ca |
def getStatus(self, jid): ## extended
|
|
|
82b6ca |
"""Returns the 'status' value for a Roster item with the given jid."""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['status']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1146,7 +1159,7 @@ class Roster:
|
|
|
82b6ca |
def getShow(self, jid): ## extended
|
|
|
82b6ca |
"""Returns the 'show' value for a Roster item with the given jid."""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['show']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1155,7 +1168,7 @@ class Roster:
|
|
|
82b6ca |
"""Returns the 'online' status for a Roster item with the given jid.
|
|
|
82b6ca |
"""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['online']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1164,7 +1177,7 @@ class Roster:
|
|
|
82b6ca |
"""Returns the 'subscription' status for a Roster item with the given
|
|
|
82b6ca |
jid."""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['sub']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1172,7 +1185,7 @@ class Roster:
|
|
|
82b6ca |
def getName(self,jid):
|
|
|
82b6ca |
"""Returns the 'name' for a Roster item with the given jid."""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['name']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1181,7 +1194,7 @@ class Roster:
|
|
|
82b6ca |
""" Returns the lsit of groups associated with the given roster item.
|
|
|
82b6ca |
"""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['groups']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1189,7 +1202,7 @@ class Roster:
|
|
|
82b6ca |
def getAsk(self,jid):
|
|
|
82b6ca |
"""Returns the 'ask' status for a Roster item with the given jid."""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
return self._data[jid]['ask']
|
|
|
82b6ca |
return None
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -1233,7 +1246,7 @@ class Roster:
|
|
|
82b6ca |
jid = ustr(jid) # just in case
|
|
|
82b6ca |
online = 'offline'
|
|
|
82b6ca |
if ask: online = 'pending'
|
|
|
82b6ca |
- if self._data.has_key(jid): # update it
|
|
|
82b6ca |
+ if jid in self._data: # update it
|
|
|
82b6ca |
self._data[jid]['name'] = name
|
|
|
82b6ca |
self._data[jid]['groups'] = groups
|
|
|
82b6ca |
self._data[jid]['ask'] = ask
|
|
|
82b6ca |
@@ -1255,13 +1268,13 @@ class Roster:
|
|
|
82b6ca |
def _setOnline(self,jid,val):
|
|
|
82b6ca |
"""Used internally - private"""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
self._data[jid]['online'] = val
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("update", jid, {'online' : val})
|
|
|
82b6ca |
else: ## fall back
|
|
|
82b6ca |
jid_basic = JID(jid).getStripped()
|
|
|
82b6ca |
- if self._data.has_key(jid_basic):
|
|
|
82b6ca |
+ if jid_basic in self._data:
|
|
|
82b6ca |
self._data[jid_basic]['online'] = val
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("update", jid_basic, {'online' : val})
|
|
|
82b6ca |
@@ -1270,13 +1283,13 @@ class Roster:
|
|
|
82b6ca |
def _setShow(self,jid,val):
|
|
|
82b6ca |
"""Used internally - private"""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
self._data[jid]['show'] = val
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("update", jid, {'show' : val})
|
|
|
82b6ca |
else: ## fall back
|
|
|
82b6ca |
jid_basic = JID(jid).getStripped()
|
|
|
82b6ca |
- if self._data.has_key(jid_basic):
|
|
|
82b6ca |
+ if jid_basic in self._data:
|
|
|
82b6ca |
self._data[jid_basic]['show'] = val
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("update", jid_basic, {'show' : val})
|
|
|
82b6ca |
@@ -1285,13 +1298,13 @@ class Roster:
|
|
|
82b6ca |
def _setStatus(self,jid,val):
|
|
|
82b6ca |
"""Used internally - private"""
|
|
|
82b6ca |
jid = ustr(jid)
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
self._data[jid]['status'] = val
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("update", jid, {'status' : val})
|
|
|
82b6ca |
else: ## fall back
|
|
|
82b6ca |
jid_basic = JID(jid).getStripped()
|
|
|
82b6ca |
- if self._data.has_key(jid_basic):
|
|
|
82b6ca |
+ if jid_basic in self._data:
|
|
|
82b6ca |
self._data[jid_basic]['status'] = val
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("update", jid_basic, {'status' : val})
|
|
|
82b6ca |
@@ -1299,7 +1312,7 @@ class Roster:
|
|
|
82b6ca |
|
|
|
82b6ca |
def _remove(self,jid):
|
|
|
82b6ca |
"""Used internally - private"""
|
|
|
82b6ca |
- if self._data.has_key(jid):
|
|
|
82b6ca |
+ if jid in self._data:
|
|
|
82b6ca |
del self._data[jid]
|
|
|
82b6ca |
if self._listener != None:
|
|
|
82b6ca |
self._listener("remove", jid, {})
|
|
|
82b6ca |
@@ -1397,8 +1410,11 @@ class Component(Connection):
|
|
|
82b6ca |
|
|
|
82b6ca |
def auth(self,secret):
|
|
|
82b6ca |
"""will disconnect on failure"""
|
|
|
82b6ca |
+ idp = self.getIncomingID() + secret
|
|
|
82b6ca |
+ if isinstance(idp, UnicodeType):
|
|
|
82b6ca |
+ idp = idp.encode('uft-8')
|
|
|
82b6ca |
self.send( u"<handshake id='1'>%s</handshake>"
|
|
|
82b6ca |
- % hashlib.new('sha1', self.getIncomingID() + secret ).hexdigest()
|
|
|
82b6ca |
+ % hashlib.new('sha1', idp).hexdigest()
|
|
|
82b6ca |
)
|
|
|
82b6ca |
while not self._auth_OK:
|
|
|
82b6ca |
self.DEBUG("waiting on handshake")
|
|
|
82b6ca |
diff --git jabberpy-0.5-0/jabber/xmlstream.py jabberpy-0.5-0/jabber/xmlstream.py
|
|
|
82b6ca |
index e8fdcab..7e72708 100644
|
|
|
82b6ca |
--- jabberpy-0.5-0/jabber/xmlstream.py
|
|
|
82b6ca |
+++ jabberpy-0.5-0/jabber/xmlstream.py
|
|
|
82b6ca |
@@ -34,14 +34,21 @@ import time, sys, re, socket
|
|
|
82b6ca |
from select import select
|
|
|
82b6ca |
from base64 import encodestring
|
|
|
82b6ca |
import xml.parsers.expat
|
|
|
82b6ca |
-import debug
|
|
|
82b6ca |
+
|
|
|
82b6ca |
+if sys.version_info[0] == 3:
|
|
|
82b6ca |
+ from . import debug
|
|
|
82b6ca |
+ UnicodeType = str
|
|
|
82b6ca |
+ BytesType = bytes
|
|
|
82b6ca |
+else:
|
|
|
82b6ca |
+ BytesType = str
|
|
|
82b6ca |
+ UnicodeType = unicode
|
|
|
82b6ca |
+ import debug
|
|
|
82b6ca |
+
|
|
|
82b6ca |
+
|
|
|
82b6ca |
_debug=debug
|
|
|
82b6ca |
|
|
|
82b6ca |
VERSION = "0.5"
|
|
|
82b6ca |
|
|
|
82b6ca |
-False = 0
|
|
|
82b6ca |
-True = 1
|
|
|
82b6ca |
-
|
|
|
82b6ca |
TCP = 1
|
|
|
82b6ca |
STDIO = 0
|
|
|
82b6ca |
TCP_SSL = 2
|
|
|
82b6ca |
@@ -83,7 +90,7 @@ class Node:
|
|
|
82b6ca |
"""A simple XML DOM like class"""
|
|
|
82b6ca |
def __init__(self, tag=None, parent=None, attrs={}, payload=[], node=None):
|
|
|
82b6ca |
if node:
|
|
|
82b6ca |
- if type(node)<>type(self): node=NodeBuilder(node).getDom()
|
|
|
82b6ca |
+ if type(node) != type(self): node=NodeBuilder(node).getDom()
|
|
|
82b6ca |
self.name,self.namespace,self.attrs,self.data,self.kids,self.parent = \
|
|
|
82b6ca |
node.name,node.namespace,node.attrs,node.data,node.kids,node.parent
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
@@ -244,7 +251,8 @@ class NodeBuilder:
|
|
|
82b6ca |
self.__depth = 0
|
|
|
82b6ca |
self._dispatch_depth = 1
|
|
|
82b6ca |
|
|
|
82b6ca |
- if data: self._parser.Parse(data,1)
|
|
|
82b6ca |
+ if data:
|
|
|
82b6ca |
+ self._parser.Parse(data.__str__(), 1)
|
|
|
82b6ca |
|
|
|
82b6ca |
def unknown_starttag(self, tag, attrs):
|
|
|
82b6ca |
"""XML Parser callback"""
|
|
|
82b6ca |
@@ -258,7 +266,7 @@ class NodeBuilder:
|
|
|
82b6ca |
self._ptr.kids.append(Node(tag=tag,parent=self._ptr,attrs=attrs))
|
|
|
82b6ca |
self._ptr = self._ptr.kids[-1]
|
|
|
82b6ca |
else: ## it the stream tag:
|
|
|
82b6ca |
- if attrs.has_key('id'):
|
|
|
82b6ca |
+ if 'id' in attrs:
|
|
|
82b6ca |
self._incomingID = attrs['id']
|
|
|
82b6ca |
self.last_is_data = False
|
|
|
82b6ca |
|
|
|
82b6ca |
@@ -322,7 +330,7 @@ class Stream(NodeBuilder):
|
|
|
82b6ca |
try:
|
|
|
82b6ca |
self._logFH = open(log,'w')
|
|
|
82b6ca |
except:
|
|
|
82b6ca |
- print "ERROR: can open %s for writing" % log
|
|
|
82b6ca |
+ print("ERROR: can open %s for writing" % log)
|
|
|
82b6ca |
sys.exit(0)
|
|
|
82b6ca |
else: ## assume its a stream type object
|
|
|
82b6ca |
self._logFH = log
|
|
|
82b6ca |
@@ -361,9 +369,9 @@ class Stream(NodeBuilder):
|
|
|
82b6ca |
If supplied data is not unicode string, ENCODING
|
|
|
82b6ca |
is used for convertion. Avoid this!
|
|
|
82b6ca |
Always send your data as a unicode string."""
|
|
|
82b6ca |
- if type(raw_data) == type(''):
|
|
|
82b6ca |
+ if isinstance(raw_data, BytesType):
|
|
|
82b6ca |
self.DEBUG('Non-utf-8 string "%s" passed to Stream.write! Treating it as %s encoded.'%(raw_data,ENCODING))
|
|
|
82b6ca |
- raw_data = unicode(raw_data,ENCODING)
|
|
|
82b6ca |
+ raw_data = UnicodeType(raw_data,ENCODING)
|
|
|
82b6ca |
data_out = raw_data.encode('utf-8')
|
|
|
82b6ca |
try:
|
|
|
82b6ca |
self._write(data_out)
|
|
|
82b6ca |
@@ -469,7 +477,7 @@ class Client(Stream):
|
|
|
82b6ca |
af, socktype, proto, canonname, sa = r
|
|
|
82b6ca |
try:
|
|
|
82b6ca |
self._sock = socket.socket(af, socktype, proto)
|
|
|
82b6ca |
- except socket.error, msg:
|
|
|
82b6ca |
+ except socket.error:
|
|
|
82b6ca |
self._sock = None
|
|
|
82b6ca |
continue
|
|
|
82b6ca |
try:
|
|
|
82b6ca |
@@ -477,7 +485,8 @@ class Client(Stream):
|
|
|
82b6ca |
self._sock.connect((self._proxy['host'], self._proxy['port']))
|
|
|
82b6ca |
else:
|
|
|
82b6ca |
self._sock.connect((self._hostIP, self._port))
|
|
|
82b6ca |
- except socket.error, e:
|
|
|
82b6ca |
+ except socket.error:
|
|
|
82b6ca |
+ e = sys.exc_info()[1]
|
|
|
82b6ca |
self._sock.close()
|
|
|
82b6ca |
self._sock = None
|
|
|
82b6ca |
self.DEBUG("socket error: "+str(e),DBG_CONN_ERROR)
|
|
|
82b6ca |
@@ -501,7 +510,7 @@ class Client(Stream):
|
|
|
82b6ca |
|
|
|
82b6ca |
if self._proxy:
|
|
|
82b6ca |
self.DEBUG("Proxy connected",DBG_INIT)
|
|
|
82b6ca |
- if self._proxy.has_key('type'): type = self._proxy['type'].upper()
|
|
|
82b6ca |
+ if 'type' in self._proxy: type = self._proxy['type'].upper()
|
|
|
82b6ca |
else: type = 'CONNECT'
|
|
|
82b6ca |
connector = []
|
|
|
82b6ca |
if type == 'CONNECT':
|
|
|
82b6ca |
@@ -515,7 +524,7 @@ class Client(Stream):
|
|
|
82b6ca |
connector.append('Pragma: no-cache')
|
|
|
82b6ca |
connector.append('Host: %s:%s'%(self._hostIP,self._port))
|
|
|
82b6ca |
connector.append('User-Agent: Jabberpy/'+VERSION)
|
|
|
82b6ca |
- if self._proxy.has_key('user') and self._proxy.has_key('password'):
|
|
|
82b6ca |
+ if 'user' in self._proxy and 'password' in self._proxy:
|
|
|
82b6ca |
credentials = '%s:%s'%(self._proxy['user'],self._proxy['password'])
|
|
|
82b6ca |
credentials = encodestring(credentials).strip()
|
|
|
82b6ca |
connector.append('Proxy-Authorization: Basic '+credentials)
|
|
|
82b6ca |
@@ -526,7 +535,7 @@ class Client(Stream):
|
|
|
82b6ca |
self._read , self._write = bak
|
|
|
82b6ca |
try: proto,code,desc=reply.split('\n')[0].split(' ',2)
|
|
|
82b6ca |
except: raise error('Invalid proxy reply')
|
|
|
82b6ca |
- if code<>'200': raise error('Invalid proxy reply: %s %s %s'%(proto,code,desc))
|
|
|
82b6ca |
+ if code != '200': raise error('Invalid proxy reply: %s %s %s'%(proto,code,desc))
|
|
|
82b6ca |
while reply.find('\n\n') == -1: reply += self.read().replace('\r','')
|
|
|
82b6ca |
|
|
|
82b6ca |
self.DEBUG("Jabber server connected",DBG_INIT)
|
|
|
82b6ca |
@@ -574,16 +583,16 @@ class Server:
|
|
|
82b6ca |
|
|
|
82b6ca |
def serve(self):
|
|
|
82b6ca |
|
|
|
82b6ca |
- print 'select-server loop starting'
|
|
|
82b6ca |
+ print('select-server loop starting')
|
|
|
82b6ca |
|
|
|
82b6ca |
while 1:
|
|
|
82b6ca |
- print "LOOPING"
|
|
|
82b6ca |
+ print("LOOPING")
|
|
|
82b6ca |
readables, writeables, exceptions = select(self.readsocks,
|
|
|
82b6ca |
self.writesocks, [])
|
|
|
82b6ca |
for sockobj in readables:
|
|
|
82b6ca |
if sockobj in self. mainsocks: # for ready input sockets
|
|
|
82b6ca |
newsock, address = sockobj.accept() # accept not block
|
|
|
82b6ca |
- print 'Connect:', address, id(newsock)
|
|
|
82b6ca |
+ print('Connect:', address, id(newsock))
|
|
|
82b6ca |
self.readsocks.append(newsock)
|
|
|
82b6ca |
self._makeNewStream(newsock)
|
|
|
82b6ca |
# add to select list, wait
|
|
|
82b6ca |
@@ -591,7 +600,7 @@ class Server:
|
|
|
82b6ca |
# client socket: read next line
|
|
|
82b6ca |
data = sockobj.recv(1024)
|
|
|
82b6ca |
# recv should not block
|
|
|
82b6ca |
- print '\tgot', data, 'on', id(sockobj)
|
|
|
82b6ca |
+ print('\tgot', data, 'on', id(sockobj))
|
|
|
82b6ca |
if not data: # if closed by the clients
|
|
|
82b6ca |
sockobj.close() # close here and remv from
|
|
|
82b6ca |
self.readsocks.remove(sockobj)
|
|
|
82b6ca |
diff --git jabberpy-0.5-0/setup.py jabberpy-0.5-0/setup.py
|
|
|
82b6ca |
index 11f6f81..84c5369 100644
|
|
|
82b6ca |
--- jabberpy-0.5-0/setup.py
|
|
|
82b6ca |
+++ jabberpy-0.5-0/setup.py
|
|
|
82b6ca |
@@ -5,14 +5,14 @@ try:
|
|
|
82b6ca |
from distutils.core import setup
|
|
|
82b6ca |
except:
|
|
|
82b6ca |
if sys.version[0] < 2:
|
|
|
82b6ca |
- print "jabber.py requires at least python 2.0"
|
|
|
82b6ca |
- print "Setup cannot continue."
|
|
|
82b6ca |
+ print("jabber.py requires at least python 2.0")
|
|
|
82b6ca |
+ print("Setup cannot continue.")
|
|
|
82b6ca |
sys.exit(1)
|
|
|
82b6ca |
- print "You appear not to have the Python distutils modules"
|
|
|
82b6ca |
- print "installed. Setup cannot continue."
|
|
|
82b6ca |
- print "You can manually install jabberpy by coping the jabber"
|
|
|
82b6ca |
- print "directory to your /python-libdir/site-packages"
|
|
|
82b6ca |
- print "directory."
|
|
|
82b6ca |
+ print("You appear not to have the Python distutils modules")
|
|
|
82b6ca |
+ print("installed. Setup cannot continue.")
|
|
|
82b6ca |
+ print("You can manually install jabberpy by coping the jabber")
|
|
|
82b6ca |
+ print("directory to your /python-libdir/site-packages")
|
|
|
82b6ca |
+ print("directory.")
|
|
|
82b6ca |
sys.exit(1)
|
|
|
82b6ca |
|
|
|
82b6ca |
setup(name="jabber.py",
|