Remove sys.version_info checks for python2 and clean some imports.

This commit is contained in:
Emmanuel Gil Peyrot
2014-08-16 22:37:25 +02:00
committed by Florent Le Coz
parent b92dac72f3
commit 0e95015410
13 changed files with 23 additions and 114 deletions
+1 -5
View File
@@ -19,10 +19,6 @@ import logging
import threading
if sys.version_info >= (3, 0):
unicode = str
log = logging.getLogger(__name__)
@@ -89,7 +85,7 @@ def load_plugin(name, module=None):
module = 'slixmpp.features.%s' % name
__import__(module)
mod = sys.modules[module]
elif isinstance(module, (str, unicode)):
elif isinstance(module, str):
__import__(module)
mod = sys.modules[module]
else:
+2 -6
View File
@@ -10,10 +10,6 @@ from slixmpp.xmlstream import ET
import base64
import logging
import time
import sys
if sys.version_info > (3, 0):
unicode = str
log = logging.getLogger(__name__)
@@ -58,7 +54,7 @@ def _py2xml(*args):
boolean = ET.Element("{%s}boolean" % _namespace)
boolean.text = str(int(x))
val.append(boolean)
elif type(x) in (str, unicode):
elif type(x) is str:
string = ET.Element("{%s}string" % _namespace)
string.text = x
val.append(string)
@@ -156,7 +152,7 @@ class rpctime(object):
def __init__(self,data=None):
#assume string data is in iso format YYYYMMDDTHH:MM:SS
if type(data) in (str, unicode):
if type(data) is str:
self.timestamp = time.strptime(data,"%Y%m%dT%H:%M:%S")
elif type(data) is time.struct_time:
self.timestamp = data
+2 -8
View File
@@ -9,8 +9,6 @@
import uuid
import logging
import hashlib
import random
import sys
from slixmpp.jid import JID
from slixmpp.exceptions import IqError, IqTimeout
@@ -105,12 +103,8 @@ class XEP_0078(BasePlugin):
if 'digest' in resp['auth']['fields']:
log.debug('Authenticating via jabber:iq:auth Digest')
if sys.version_info < (3, 0):
stream_id = bytes(self.xmpp.stream_id)
password = bytes(self.xmpp.password)
else:
stream_id = bytes(self.xmpp.stream_id, encoding='utf-8')
password = bytes(self.xmpp.password, encoding='utf-8')
stream_id = bytes(self.xmpp.stream_id, encoding='utf-8')
password = bytes(self.xmpp.password, encoding='utf-8')
digest = hashlib.sha1(b'%s%s' % (stream_id, password)).hexdigest()
iq['auth']['digest'] = digest