print -> print()
This commit is contained in:
parent
f67f063769
commit
e71188a6fa
27 changed files with 154 additions and 165 deletions
|
@ -159,7 +159,7 @@ class CommandWindow:
|
||||||
return self.stage_adhoc_commands_window_delete_event(self.window)
|
return self.stage_adhoc_commands_window_delete_event(self.window)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
print 'Object has been deleted.'
|
print('Object has been deleted.')
|
||||||
|
|
||||||
# stage 1: waiting for command list
|
# stage 1: waiting for command list
|
||||||
def stage1(self):
|
def stage1(self):
|
||||||
|
|
|
@ -36,7 +36,7 @@ from common import jingle_xtls
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
|
|
||||||
def create_log_db():
|
def create_log_db():
|
||||||
print _('creating logs database')
|
print(_('creating logs database'))
|
||||||
con = sqlite.connect(logger.LOG_DB_PATH)
|
con = sqlite.connect(logger.LOG_DB_PATH)
|
||||||
os.chmod(logger.LOG_DB_PATH, 0600) # rw only for us
|
os.chmod(logger.LOG_DB_PATH, 0600) # rw only for us
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
@ -84,7 +84,7 @@ def create_log_db():
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
def create_cache_db():
|
def create_cache_db():
|
||||||
print _('creating cache database')
|
print(_('creating cache database'))
|
||||||
con = sqlite.connect(logger.CACHE_DB_PATH)
|
con = sqlite.connect(logger.CACHE_DB_PATH)
|
||||||
os.chmod(logger.CACHE_DB_PATH, 0600) # rw only for us
|
os.chmod(logger.CACHE_DB_PATH, 0600) # rw only for us
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
@ -128,7 +128,7 @@ def create_cache_db():
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
def split_db():
|
def split_db():
|
||||||
print 'spliting database'
|
print('spliting database')
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
try:
|
try:
|
||||||
import configpaths
|
import configpaths
|
||||||
|
@ -162,8 +162,8 @@ def split_db():
|
||||||
cur.executescript('DROP TABLE %s;' % table)
|
cur.executescript('DROP TABLE %s;' % table)
|
||||||
con.commit()
|
con.commit()
|
||||||
except sqlite.OperationalError, e:
|
except sqlite.OperationalError, e:
|
||||||
print >> sys.stderr, 'error moving table %s to cache.db: %s' % \
|
print('error moving table %s to cache.db: %s' % (table, str(e)),
|
||||||
(table, str(e))
|
file=sys.stderr)
|
||||||
con.close()
|
con.close()
|
||||||
logger.CACHE_DB_PATH = tmp
|
logger.CACHE_DB_PATH = tmp
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ def check_and_possibly_move_config():
|
||||||
continue
|
continue
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
continue
|
continue
|
||||||
print 'moving %s to %s' % (src, dst)
|
print(_('moving %s to %s') % (src, dst))
|
||||||
shutil.move(src, dst)
|
shutil.move(src, dst)
|
||||||
gajim.logger.init_vars()
|
gajim.logger.init_vars()
|
||||||
gajim.logger.attach_cache_database()
|
gajim.logger.attach_cache_database()
|
||||||
|
@ -275,57 +275,57 @@ def check_and_possibly_create_paths():
|
||||||
if not os.path.exists(MY_DATA):
|
if not os.path.exists(MY_DATA):
|
||||||
create_path(MY_DATA)
|
create_path(MY_DATA)
|
||||||
elif os.path.isfile(MY_DATA):
|
elif os.path.isfile(MY_DATA):
|
||||||
print _('%s is a file but it should be a directory') % MY_DATA
|
print(_('%s is a file but it should be a directory') % MY_DATA)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(MY_CONFIG):
|
if not os.path.exists(MY_CONFIG):
|
||||||
create_path(MY_CONFIG)
|
create_path(MY_CONFIG)
|
||||||
elif os.path.isfile(MY_CONFIG):
|
elif os.path.isfile(MY_CONFIG):
|
||||||
print _('%s is a file but it should be a directory') % MY_CONFIG
|
print(_('%s is a file but it should be a directory') % MY_CONFIG)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(MY_CACHE):
|
if not os.path.exists(MY_CACHE):
|
||||||
create_path(MY_CACHE)
|
create_path(MY_CACHE)
|
||||||
elif os.path.isfile(MY_CACHE):
|
elif os.path.isfile(MY_CACHE):
|
||||||
print _('%s is a file but it should be a directory') % MY_CACHE
|
print(_('%s is a file but it should be a directory') % MY_CACHE)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(VCARD_PATH):
|
if not os.path.exists(VCARD_PATH):
|
||||||
create_path(VCARD_PATH)
|
create_path(VCARD_PATH)
|
||||||
elif os.path.isfile(VCARD_PATH):
|
elif os.path.isfile(VCARD_PATH):
|
||||||
print _('%s is a file but it should be a directory') % VCARD_PATH
|
print(_('%s is a file but it should be a directory') % VCARD_PATH)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(AVATAR_PATH):
|
if not os.path.exists(AVATAR_PATH):
|
||||||
create_path(AVATAR_PATH)
|
create_path(AVATAR_PATH)
|
||||||
elif os.path.isfile(AVATAR_PATH):
|
elif os.path.isfile(AVATAR_PATH):
|
||||||
print _('%s is a file but it should be a directory') % AVATAR_PATH
|
print(_('%s is a file but it should be a directory') % AVATAR_PATH)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(LOG_DB_FOLDER):
|
if not os.path.exists(LOG_DB_FOLDER):
|
||||||
create_path(LOG_DB_FOLDER)
|
create_path(LOG_DB_FOLDER)
|
||||||
elif os.path.isfile(LOG_DB_FOLDER):
|
elif os.path.isfile(LOG_DB_FOLDER):
|
||||||
print _('%s is a file but it should be a directory') % LOG_DB_FOLDER
|
print(_('%s is a file but it should be a directory') % LOG_DB_FOLDER)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(PLUGINS_CONFIG_PATH):
|
if not os.path.exists(PLUGINS_CONFIG_PATH):
|
||||||
create_path(PLUGINS_CONFIG_PATH)
|
create_path(PLUGINS_CONFIG_PATH)
|
||||||
elif os.path.isfile(PLUGINS_CONFIG_PATH):
|
elif os.path.isfile(PLUGINS_CONFIG_PATH):
|
||||||
print _('%s is a file but it should be a directory') % PLUGINS_CONFIG_PATH
|
print(_('%s is a file but it should be a directory') % PLUGINS_CONFIG_PATH)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(CACHE_DB_FOLDER):
|
if not os.path.exists(CACHE_DB_FOLDER):
|
||||||
create_path(CACHE_DB_FOLDER)
|
create_path(CACHE_DB_FOLDER)
|
||||||
elif os.path.isfile(CACHE_DB_FOLDER):
|
elif os.path.isfile(CACHE_DB_FOLDER):
|
||||||
print _('%s is a file but it should be a directory') % CACHE_DB_FOLDER
|
print(_('%s is a file but it should be a directory') % CACHE_DB_FOLDER)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
check_and_possibly_move_config()
|
check_and_possibly_move_config()
|
||||||
|
@ -334,16 +334,16 @@ def check_and_possibly_create_paths():
|
||||||
create_log_db()
|
create_log_db()
|
||||||
gajim.logger.init_vars()
|
gajim.logger.init_vars()
|
||||||
elif os.path.isdir(LOG_DB_PATH):
|
elif os.path.isdir(LOG_DB_PATH):
|
||||||
print _('%s is a directory but should be a file') % LOG_DB_PATH
|
print(_('%s is a directory but should be a file') % LOG_DB_PATH)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(CACHE_DB_PATH):
|
if not os.path.exists(CACHE_DB_PATH):
|
||||||
create_cache_db()
|
create_cache_db()
|
||||||
gajim.logger.attach_cache_database()
|
gajim.logger.attach_cache_database()
|
||||||
elif os.path.isdir(CACHE_DB_PATH):
|
elif os.path.isdir(CACHE_DB_PATH):
|
||||||
print _('%s is a directory but should be a file') % CACHE_DB_PATH
|
print(_('%s is a directory but should be a file') % CACHE_DB_PATH)
|
||||||
print _('Gajim will now exit')
|
print(_('Gajim will now exit'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(XTLS_CERTS):
|
if not os.path.exists(XTLS_CERTS):
|
||||||
|
@ -363,5 +363,5 @@ def create_path(directory):
|
||||||
create_path(head)
|
create_path(head)
|
||||||
if os.path.exists(directory):
|
if os.path.exists(directory):
|
||||||
return
|
return
|
||||||
print _('creating %s directory') % directory
|
print(('creating %s directory') % directory)
|
||||||
os.mkdir(directory, 0700)
|
os.mkdir(directory, 0700)
|
||||||
|
|
|
@ -162,8 +162,8 @@ class ConfigPaths:
|
||||||
try:
|
try:
|
||||||
self.add('TMP', None, fse(tempfile.gettempdir()))
|
self.add('TMP', None, fse(tempfile.gettempdir()))
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
print >> sys.stderr, 'Error opening tmp folder: %s\nUsing %s' % (
|
print('Error opening tmp folder: %s\nUsing %s' % (str(e),
|
||||||
str(e), os.path.expanduser('~'))
|
os.path.expanduser('~')), file=sys.stderr)
|
||||||
self.add('TMP', None, fse(os.path.expanduser('~')))
|
self.add('TMP', None, fse(os.path.expanduser('~')))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -593,7 +593,7 @@ class ConnectionVcard:
|
||||||
|
|
||||||
elif self.awaiting_answers[id_][0] == ARCHIVING_COLLECTIONS_ARRIVED:
|
elif self.awaiting_answers[id_][0] == ARCHIVING_COLLECTIONS_ARRIVED:
|
||||||
# TODO
|
# TODO
|
||||||
print 'ARCHIVING_COLLECTIONS_ARRIVED'
|
print('ARCHIVING_COLLECTIONS_ARRIVED')
|
||||||
|
|
||||||
elif self.awaiting_answers[id_][0] == ARCHIVING_COLLECTION_ARRIVED:
|
elif self.awaiting_answers[id_][0] == ARCHIVING_COLLECTION_ARRIVED:
|
||||||
def save_if_not_exists(with_, nick, direction, tim, payload):
|
def save_if_not_exists(with_, nick, direction, tim, payload):
|
||||||
|
@ -603,7 +603,7 @@ class ConnectionVcard:
|
||||||
gajim.logger.save_if_not_exists(with_, direction, tim,
|
gajim.logger.save_if_not_exists(with_, direction, tim,
|
||||||
msg=payload[0].getData(), nick=nick)
|
msg=payload[0].getData(), nick=nick)
|
||||||
elif payload[0].getName() == 'message':
|
elif payload[0].getName() == 'message':
|
||||||
print 'Not implemented'
|
print('Not implemented')
|
||||||
chat = iq_obj.getTag('chat')
|
chat = iq_obj.getTag('chat')
|
||||||
if chat:
|
if chat:
|
||||||
with_ = chat.getAttr('with')
|
with_ = chat.getAttr('with')
|
||||||
|
|
|
@ -366,10 +366,10 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
try:
|
try:
|
||||||
j = helpers.parse_jid(jid)
|
j = helpers.parse_jid(jid)
|
||||||
except Exception:
|
except Exception:
|
||||||
print >> sys.stderr, _('JID %s is not RFC compliant. It '
|
print(_('JID %s is not RFC compliant. It will not be added '
|
||||||
'will not be added to your roster. Use roster '
|
'to your roster. Use roster management tools such as '
|
||||||
'management tools such as '
|
'http://jru.jabberstudio.org/ to remove it') % jid,
|
||||||
'http://jru.jabberstudio.org/ to remove it') % jid
|
file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
infos = raw_roster[jid]
|
infos = raw_roster[jid]
|
||||||
if jid != our_jid and (not infos['subscription'] or \
|
if jid != our_jid and (not infos['subscription'] or \
|
||||||
|
|
|
@ -38,8 +38,8 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
supported = False
|
supported = False
|
||||||
if not os.name == 'nt': # only say that to non Windows users
|
if not os.name == 'nt': # only say that to non Windows users
|
||||||
print _('D-Bus python bindings are missing in this computer')
|
print(_('D-Bus python bindings are missing in this computer'))
|
||||||
print _('D-Bus capabilities of Gajim cannot be used')
|
print(_('D-Bus capabilities of Gajim cannot be used'))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
# test if dbus-x11 is installed
|
# test if dbus-x11 is installed
|
||||||
|
@ -49,14 +49,14 @@ else:
|
||||||
except dbus.DBusException:
|
except dbus.DBusException:
|
||||||
supported = False
|
supported = False
|
||||||
if not os.name == 'nt': # only say that to non Windows users
|
if not os.name == 'nt': # only say that to non Windows users
|
||||||
print _('D-Bus does not run correctly on this machine')
|
print(_('D-Bus does not run correctly on this machine'))
|
||||||
print _('D-Bus capabilities of Gajim cannot be used')
|
print(_('D-Bus capabilities of Gajim cannot be used'))
|
||||||
except exceptions.SystemBusNotPresent:
|
except exceptions.SystemBusNotPresent:
|
||||||
print _('D-Bus does not run correctly on this machine: system bus not '
|
print(_('D-Bus does not run correctly on this machine: system bus not '
|
||||||
'present')
|
'present'))
|
||||||
except exceptions.SessionBusNotPresent:
|
except exceptions.SessionBusNotPresent:
|
||||||
print _('D-Bus does not run correctly on this machine: session bus not '
|
print(_('D-Bus does not run correctly on this machine: session bus not '
|
||||||
'present')
|
'present'))
|
||||||
|
|
||||||
class SystemBus:
|
class SystemBus:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -94,6 +94,6 @@ def close():
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import time
|
import time
|
||||||
time.sleep(2.1)
|
time.sleep(2.1)
|
||||||
print getIdleSec()
|
print(getIdleSec())
|
||||||
close()
|
close()
|
||||||
print getIdleSec()
|
print(getIdleSec())
|
||||||
|
|
|
@ -401,7 +401,7 @@ class JingleTransportICEUDP(JingleTransport):
|
||||||
if 'type' in candidate and candidate['type'] in types:
|
if 'type' in candidate and candidate['type'] in types:
|
||||||
cand.type = types[candidate['type']]
|
cand.type = types[candidate['type']]
|
||||||
else:
|
else:
|
||||||
print 'Unknown type %s', candidate['type']
|
print('Unknown type %s' % candidate['type'])
|
||||||
candidates.append(cand)
|
candidates.append(cand)
|
||||||
self.remote_candidates.extend(candidates)
|
self.remote_candidates.extend(candidates)
|
||||||
return candidates
|
return candidates
|
||||||
|
|
|
@ -169,7 +169,7 @@ class Logger:
|
||||||
try:
|
try:
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
except sqlite.OperationalError, e:
|
except sqlite.OperationalError, e:
|
||||||
print >> sys.stderr, str(e)
|
print(str(e), file=sys.stderr)
|
||||||
self.commit_timout_id = None
|
self.commit_timout_id = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ class Logger:
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
message_id = self.cur.lastrowid
|
message_id = self.cur.lastrowid
|
||||||
except sqlite.OperationalError, e:
|
except sqlite.OperationalError, e:
|
||||||
print >> sys.stderr, str(e)
|
print(str(e), file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
self._timeout_commit()
|
self._timeout_commit()
|
||||||
if message_id:
|
if message_id:
|
||||||
|
|
|
@ -30,7 +30,7 @@ def parseLogLevel(arg):
|
||||||
elif arg.isupper() and hasattr(logging, arg):
|
elif arg.isupper() and hasattr(logging, arg):
|
||||||
return getattr(logging, arg)
|
return getattr(logging, arg)
|
||||||
else:
|
else:
|
||||||
print _('%s is not a valid loglevel') % repr(arg)
|
print(_('%s is not a valid loglevel') % repr(arg))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def parseLogTarget(arg):
|
def parseLogTarget(arg):
|
||||||
|
@ -72,7 +72,7 @@ def parseAndSetLogLevels(arg):
|
||||||
target = parseLogTarget(target.strip())
|
target = parseLogTarget(target.strip())
|
||||||
if target:
|
if target:
|
||||||
logging.getLogger(target).setLevel(level)
|
logging.getLogger(target).setLevel(level)
|
||||||
print "Logger %s level set to %d" % (target, level)
|
print("Logger %s level set to %d" % (target, level))
|
||||||
|
|
||||||
|
|
||||||
class colors:
|
class colors:
|
||||||
|
|
|
@ -50,7 +50,7 @@ class DeviceManager(object):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
except gst.ElementNotFoundError:
|
except gst.ElementNotFoundError:
|
||||||
print 'element \'%s\' not found' % name
|
print('element \'%s\' not found' % name)
|
||||||
|
|
||||||
|
|
||||||
class AudioInputManager(DeviceManager):
|
class AudioInputManager(DeviceManager):
|
||||||
|
|
|
@ -50,7 +50,8 @@ class OptionsParser:
|
||||||
except Exception:
|
except Exception:
|
||||||
if os.path.exists(self.__filename):
|
if os.path.exists(self.__filename):
|
||||||
#we talk about a file
|
#we talk about a file
|
||||||
print _('Error: cannot open %s for reading') % self.__filename
|
print(_('Error: cannot open %s for reading') % self.__filename,
|
||||||
|
file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
new_version = gajim.config.get('version')
|
new_version = gajim.config.get('version')
|
||||||
|
@ -381,7 +382,7 @@ class OptionsParser:
|
||||||
"""
|
"""
|
||||||
Apply indeces to the logs database
|
Apply indeces to the logs database
|
||||||
"""
|
"""
|
||||||
print _('migrating logs database to indices')
|
print(_('migrating logs database to indices'))
|
||||||
# FIXME see #2812
|
# FIXME see #2812
|
||||||
back = os.getcwd()
|
back = os.getcwd()
|
||||||
os.chdir(logger.LOG_DB_FOLDER)
|
os.chdir(logger.LOG_DB_FOLDER)
|
||||||
|
|
|
@ -329,7 +329,7 @@ if __name__ == '__main__':
|
||||||
global resolver
|
global resolver
|
||||||
host = text_view.get_text()
|
host = text_view.get_text()
|
||||||
def on_result(host, result_array):
|
def on_result(host, result_array):
|
||||||
print 'Result:\n' + repr(result_array)
|
print('Result:\n' + repr(result_array))
|
||||||
resolver.resolve(host, on_result)
|
resolver.resolve(host, on_result)
|
||||||
win = Gtk.Window()
|
win = Gtk.Window()
|
||||||
win.set_border_width(6)
|
win.set_border_width(6)
|
||||||
|
|
|
@ -28,7 +28,7 @@ try:
|
||||||
from docutils import nodes, utils
|
from docutils import nodes, utils
|
||||||
from docutils.parsers.rst.roles import set_classes
|
from docutils.parsers.rst.roles import set_classes
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Requires docutils 0.4 for set_classes to be available"
|
print("Requires docutils 0.4 for set_classes to be available")
|
||||||
def create_xhtml(text):
|
def create_xhtml(text):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
@ -147,7 +147,7 @@ else:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print "test 1\n", Generator.create_xhtml("""
|
print("test 1\n" + Generator.create_xhtml("""
|
||||||
test::
|
test::
|
||||||
|
|
||||||
>>> print 1
|
>>> print 1
|
||||||
|
@ -157,10 +157,10 @@ test::
|
||||||
|
|
||||||
this `` should trigger`` should trigger the problem.
|
this `` should trigger`` should trigger the problem.
|
||||||
|
|
||||||
""")
|
"""))
|
||||||
print "test 2\n", Generator.create_xhtml("""
|
print("test 2\n" + Generator.create_xhtml("""
|
||||||
*test1
|
*test1
|
||||||
|
|
||||||
test2_
|
test2_
|
||||||
""")
|
"""))
|
||||||
print "test 3\n", Generator.create_xhtml(""":ticket:`316` implements :xep:`71`""")
|
print("test 3\n" + Generator.create_xhtml(""":ticket:`316` implements :xep:`71`"""))
|
||||||
|
|
|
@ -32,7 +32,6 @@ class Roster:
|
||||||
self.setItem(val[zeroconf.C_NAME])
|
self.setItem(val[zeroconf.C_NAME])
|
||||||
|
|
||||||
def getRoster(self):
|
def getRoster(self):
|
||||||
#print 'roster_zeroconf.py: getRoster'
|
|
||||||
if self._data is None:
|
if self._data is None:
|
||||||
self._data = {}
|
self._data = {}
|
||||||
self.update_roster()
|
self.update_roster()
|
||||||
|
@ -50,11 +49,9 @@ class Roster:
|
||||||
if key in self._data:
|
if key in self._data:
|
||||||
if old_data[key] != self._data[key]:
|
if old_data[key] != self._data[key]:
|
||||||
diffs[key] = self._data[key]['status']
|
diffs[key] = self._data[key]['status']
|
||||||
#print 'roster_zeroconf.py: diffs:' + str(diffs)
|
|
||||||
return diffs
|
return diffs
|
||||||
|
|
||||||
def setItem(self, jid, name='', groups=''):
|
def setItem(self, jid, name='', groups=''):
|
||||||
#print 'roster_zeroconf.py: setItem %s' % jid
|
|
||||||
contact = self.zeroconf.get_contact(jid)
|
contact = self.zeroconf.get_contact(jid)
|
||||||
if not contact:
|
if not contact:
|
||||||
return
|
return
|
||||||
|
@ -96,34 +93,27 @@ class Roster:
|
||||||
self.setItem(jid=i['jid'], name=i['name'], groups=i['groups'])
|
self.setItem(jid=i['jid'], name=i['name'], groups=i['groups'])
|
||||||
|
|
||||||
def delItem(self, jid):
|
def delItem(self, jid):
|
||||||
#print 'roster_zeroconf.py: delItem %s' % jid
|
|
||||||
if jid in self._data:
|
if jid in self._data:
|
||||||
del self._data[jid]
|
del self._data[jid]
|
||||||
|
|
||||||
def getItem(self, jid):
|
def getItem(self, jid):
|
||||||
#print 'roster_zeroconf.py: getItem: %s' % jid
|
|
||||||
if jid in self._data:
|
if jid in self._data:
|
||||||
return self._data[jid]
|
return self._data[jid]
|
||||||
|
|
||||||
def __getitem__(self, jid):
|
def __getitem__(self, jid):
|
||||||
#print 'roster_zeroconf.py: __getitem__'
|
|
||||||
return self._data[jid]
|
return self._data[jid]
|
||||||
|
|
||||||
def getItems(self):
|
def getItems(self):
|
||||||
#print 'roster_zeroconf.py: getItems'
|
|
||||||
# Return list of all [bare] JIDs that the roster currently tracks.
|
# Return list of all [bare] JIDs that the roster currently tracks.
|
||||||
return self._data.keys()
|
return self._data.keys()
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
#print 'roster_zeroconf.py: keys'
|
|
||||||
return self._data.keys()
|
return self._data.keys()
|
||||||
|
|
||||||
def getRaw(self):
|
def getRaw(self):
|
||||||
#print 'roster_zeroconf.py: getRaw'
|
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
def getResources(self, jid):
|
def getResources(self, jid):
|
||||||
#print 'roster_zeroconf.py: getResources(%s)' % jid
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def getGroups(self, jid):
|
def getGroups(self, jid):
|
||||||
|
@ -142,14 +132,12 @@ class Roster:
|
||||||
return self._data[jid]['txt_dict']['msg']
|
return self._data[jid]['txt_dict']['msg']
|
||||||
|
|
||||||
def getShow(self, jid):
|
def getShow(self, jid):
|
||||||
#print 'roster_zeroconf.py: getShow'
|
|
||||||
return self.getStatus(jid)
|
return self.getStatus(jid)
|
||||||
|
|
||||||
def getPriority(self, jid):
|
def getPriority(self, jid):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
def getSubscription(self, jid):
|
def getSubscription(self, jid):
|
||||||
#print 'roster_zeroconf.py: getSubscription'
|
|
||||||
return 'both'
|
return 'both'
|
||||||
|
|
||||||
def Subscribe(self, jid):
|
def Subscribe(self, jid):
|
||||||
|
|
|
@ -75,7 +75,7 @@ class DataFormWidget(Gtk.Alignment, object):
|
||||||
selection.set_mode(Gtk.SelectionMode.MULTIPLE)
|
selection.set_mode(Gtk.SelectionMode.MULTIPLE)
|
||||||
|
|
||||||
def on_data_form_vbox_key_press_event(self, widget, event):
|
def on_data_form_vbox_key_press_event(self, widget, event):
|
||||||
print 'key pressed'
|
print('key pressed')
|
||||||
|
|
||||||
def set_data_form(self, dataform):
|
def set_data_form(self, dataform):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4812,7 +4812,6 @@ class AddSpecialNotificationDialog:
|
||||||
if active == 1: # user selected 'choose sound'
|
if active == 1: # user selected 'choose sound'
|
||||||
def on_ok(widget, path_to_snd_file):
|
def on_ok(widget, path_to_snd_file):
|
||||||
pass
|
pass
|
||||||
#print path_to_snd_file
|
|
||||||
|
|
||||||
def on_cancel(widget):
|
def on_cancel(widget):
|
||||||
widget.set_active(0) # go back to No Sound
|
widget.set_active(0) # go back to No Sound
|
||||||
|
|
|
@ -42,7 +42,7 @@ except Exception:
|
||||||
|
|
||||||
def send_error(error_message):
|
def send_error(error_message):
|
||||||
'''Writes error message to stderr and exits'''
|
'''Writes error message to stderr and exits'''
|
||||||
print >> sys.stderr, error_message.encode(PREFERRED_ENCODING)
|
print(error_message.encode(PREFERRED_ENCODING), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -52,7 +52,7 @@ try:
|
||||||
# test if dbus-x11 is installed
|
# test if dbus-x11 is installed
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
except Exception:
|
except Exception:
|
||||||
print _('D-Bus is not present on this machine or python module is missing')
|
print(_('D-Bus is not present on this machine or python module is missing'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
OBJ_PATH = '/org/gajim/dbus/RemoteObject'
|
OBJ_PATH = '/org/gajim/dbus/RemoteObject'
|
||||||
|
@ -310,14 +310,15 @@ class GajimRemote:
|
||||||
self.command = sys.argv[1]
|
self.command = sys.argv[1]
|
||||||
if self.command == 'help':
|
if self.command == 'help':
|
||||||
if self.argv_len == 3:
|
if self.argv_len == 3:
|
||||||
print self.help_on_command(sys.argv[2]).encode(PREFERRED_ENCODING)
|
print(self.help_on_command(sys.argv[2]).encode(
|
||||||
|
PREFERRED_ENCODING))
|
||||||
else:
|
else:
|
||||||
print self.compose_help().encode(PREFERRED_ENCODING)
|
print(self.compose_help().encode(PREFERRED_ENCODING))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if self.command == 'handle_uri':
|
if self.command == 'handle_uri':
|
||||||
self.handle_uri()
|
self.handle_uri()
|
||||||
if self.command == 'check_gajim_running':
|
if self.command == 'check_gajim_running':
|
||||||
print self.check_gajim_running()
|
print(self.check_gajim_running())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
self.init_connection()
|
self.init_connection()
|
||||||
self.check_arguments()
|
self.check_arguments()
|
||||||
|
@ -354,27 +355,27 @@ class GajimRemote:
|
||||||
if isinstance(res, list):
|
if isinstance(res, list):
|
||||||
for account in res:
|
for account in res:
|
||||||
if isinstance(account, unicode):
|
if isinstance(account, unicode):
|
||||||
print account.encode(PREFERRED_ENCODING)
|
print(account.encode(PREFERRED_ENCODING))
|
||||||
else:
|
else:
|
||||||
print account
|
print(account)
|
||||||
elif self.command == 'account_info':
|
elif self.command == 'account_info':
|
||||||
if res:
|
if res:
|
||||||
print self.print_info(0, res, True)
|
print(self.print_info(0, res, True))
|
||||||
elif self.command == 'list_contacts':
|
elif self.command == 'list_contacts':
|
||||||
for account_dict in res:
|
for account_dict in res:
|
||||||
print self.print_info(0, account_dict, True)
|
print(self.print_info(0, account_dict, True))
|
||||||
elif self.command == 'prefs_list':
|
elif self.command == 'prefs_list':
|
||||||
pref_keys = sorted(res.keys())
|
pref_keys = sorted(res.keys())
|
||||||
for pref_key in pref_keys:
|
for pref_key in pref_keys:
|
||||||
result = '%s = %s' % (pref_key, res[pref_key])
|
result = '%s = %s' % (pref_key, res[pref_key])
|
||||||
if isinstance(result, unicode):
|
if isinstance(result, unicode):
|
||||||
print result.encode(PREFERRED_ENCODING)
|
print(result.encode(PREFERRED_ENCODING))
|
||||||
else:
|
else:
|
||||||
print result
|
print(result)
|
||||||
elif self.command == 'contact_info':
|
elif self.command == 'contact_info':
|
||||||
print self.print_info(0, res, True)
|
print(self.print_info(0, res, True))
|
||||||
elif res:
|
elif res:
|
||||||
print unicode(res).encode(PREFERRED_ENCODING)
|
print(unicode(res).encode(PREFERRED_ENCODING))
|
||||||
|
|
||||||
def check_gajim_running(self):
|
def check_gajim_running(self):
|
||||||
if not self.sbus:
|
if not self.sbus:
|
||||||
|
|
28
src/gajim.py
28
src/gajim.py
|
@ -42,7 +42,7 @@ import warnings
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
log_path = os.path.join(os.environ['APPDATA'], 'Gajim')
|
log_path = os.path.join(os.environ['APPDATA'], 'Gajim')
|
||||||
if not os.path.exists(log_path):
|
if not os.path.exists(log_path):
|
||||||
os.mkdir(log_path, 0700)
|
os.mkdir(log_path, 0o700)
|
||||||
log_file = os.path.join(log_path, 'gajim.log')
|
log_file = os.path.join(log_path, 'gajim.log')
|
||||||
fout = open(log_file, 'a')
|
fout = open(log_file, 'a')
|
||||||
sys.stdout = fout
|
sys.stdout = fout
|
||||||
|
@ -65,7 +65,7 @@ if os.name == 'nt':
|
||||||
try:
|
try:
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print 'Gajim needs python-nbxmpp to run. Quiting...'
|
print('Gajim needs python-nbxmpp to run. Quiting...')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
#from common import demandimport
|
#from common import demandimport
|
||||||
|
@ -131,15 +131,15 @@ def parseOpts():
|
||||||
longargs += ' class= name= screen= gtk-module= sync g-fatal-warnings'
|
longargs += ' class= name= screen= gtk-module= sync g-fatal-warnings'
|
||||||
longargs += ' sm-client-id= sm-client-state-file= sm-disable'
|
longargs += ' sm-client-id= sm-client-state-file= sm-disable'
|
||||||
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
|
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
|
||||||
except getopt.error, msg1:
|
except getopt.error as msg1:
|
||||||
print msg1
|
print(msg1)
|
||||||
print 'for help use --help'
|
print('for help use --help')
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o in ('-h', '--help'):
|
if o in ('-h', '--help'):
|
||||||
print 'gajim [--help] [--quiet] [--verbose] ' + \
|
print('gajim [--help] [--quiet] [--verbose] ' + \
|
||||||
'[--loglevel subsystem=level[,subsystem=level[...]]] ' + \
|
'[--loglevel subsystem=level[,subsystem=level[...]]] ' + \
|
||||||
'[--profile name] [--config-path]'
|
'[--profile name] [--config-path]')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif o in ('-q', '--quiet'):
|
elif o in ('-q', '--quiet'):
|
||||||
logging_helpers.set_quiet()
|
logging_helpers.set_quiet()
|
||||||
|
@ -182,7 +182,7 @@ if os.name == 'nt':
|
||||||
if self._file is None and self._error is None:
|
if self._file is None and self._error is None:
|
||||||
try:
|
try:
|
||||||
self._file = open(fname, 'a')
|
self._file = open(fname, 'a')
|
||||||
except Exception, details:
|
except Exception as details:
|
||||||
self._error = details
|
self._error = details
|
||||||
if self._file is not None:
|
if self._file is not None:
|
||||||
self._file.write(text)
|
self._file.write(text)
|
||||||
|
@ -200,11 +200,11 @@ try:
|
||||||
GObject.set_prgname('gajim')
|
GObject.set_prgname('gajim')
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
except Warning, msg2:
|
except Warning as msg2:
|
||||||
if str(msg2) == 'could not open display':
|
if str(msg2) == 'could not open display':
|
||||||
print >> sys.stderr, _('Gajim needs X server to run. Quiting...')
|
print(_('Gajim needs X server to run. Quiting...'), file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
print >> sys.stderr, _('importing PyGTK failed: %s') % str(msg2)
|
print(_('importing PyGTK failed: %s') % str(msg2), file=sys.stderr)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
warnings.resetwarnings()
|
warnings.resetwarnings()
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ def pid_alive():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f1 = open('/proc/%d/cmdline'% pid)
|
f1 = open('/proc/%d/cmdline'% pid)
|
||||||
except IOError, e1:
|
except IOError as e1:
|
||||||
if e1.errno == errno.ENOENT:
|
if e1.errno == errno.ENOENT:
|
||||||
return False # file/pid does not exist
|
return False # file/pid does not exist
|
||||||
raise
|
raise
|
||||||
|
@ -419,7 +419,7 @@ try:
|
||||||
f2 = open(pid_filename, 'w')
|
f2 = open(pid_filename, 'w')
|
||||||
f2.write(str(os.getpid()))
|
f2.write(str(os.getpid()))
|
||||||
f2.close()
|
f2.close()
|
||||||
except IOError, e2:
|
except IOError as e2:
|
||||||
dlg = dialogs.ErrorDialog(_('Disk Write Error'), str(e2))
|
dlg = dialogs.ErrorDialog(_('Disk Write Error'), str(e2))
|
||||||
dlg.run()
|
dlg.run()
|
||||||
dlg.destroy()
|
dlg.destroy()
|
||||||
|
@ -464,4 +464,4 @@ if __name__ == '__main__':
|
||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
Gdk.threads_leave()
|
Gdk.threads_leave()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print >> sys.stderr, 'KeyboardInterrupt'
|
print('KeyboardInterrupt', file=sys.stderr)
|
||||||
|
|
|
@ -198,8 +198,8 @@ def get_default_font():
|
||||||
return line[start:line.find('"', start)].decode('utf-8')
|
return line[start:line.find('"', start)].decode('utf-8')
|
||||||
except Exception:
|
except Exception:
|
||||||
#we talk about file
|
#we talk about file
|
||||||
print >> sys.stderr, _('Error: cannot open %s for reading') % \
|
print(_('Error: cannot open %s for reading') % xfce_config_file,
|
||||||
xfce_config_file
|
file=sys.stderr)
|
||||||
|
|
||||||
elif os.path.exists(kde_config_file):
|
elif os.path.exists(kde_config_file):
|
||||||
try:
|
try:
|
||||||
|
@ -214,8 +214,8 @@ def get_default_font():
|
||||||
return font_string.decode('utf-8')
|
return font_string.decode('utf-8')
|
||||||
except Exception:
|
except Exception:
|
||||||
#we talk about file
|
#we talk about file
|
||||||
print >> sys.stderr, _('Error: cannot open %s for reading') % \
|
print(_('Error: cannot open %s for reading') % kde_config_file,
|
||||||
kde_config_file
|
file=sys.stderr)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -343,10 +343,10 @@ def parse_server_xml(path_to_file):
|
||||||
return handler.servers
|
return handler.servers
|
||||||
# handle exception if unable to open file
|
# handle exception if unable to open file
|
||||||
except IOError, message:
|
except IOError, message:
|
||||||
print >> sys.stderr, _('Error reading file:'), message
|
print(_('Error reading file:') + message, file=sys.stderr)
|
||||||
# handle exception parsing file
|
# handle exception parsing file
|
||||||
except xml.sax.SAXParseException, message:
|
except xml.sax.SAXParseException, message:
|
||||||
print >> sys.stderr, _('Error parsing file:'), message
|
print(_('Error parsing file:') + message, file=sys.stderr)
|
||||||
|
|
||||||
def set_unset_urgency_hint(window, unread_messages_no):
|
def set_unset_urgency_hint(window, unread_messages_no):
|
||||||
"""
|
"""
|
||||||
|
@ -389,7 +389,7 @@ def get_abspath_for_script(scriptname, want_type = False):
|
||||||
#we talk about a file here
|
#we talk about a file here
|
||||||
s = _('Could not write to %s. Session Management support will '
|
s = _('Could not write to %s. Session Management support will '
|
||||||
'not work') % path_to_script
|
'not work') % path_to_script
|
||||||
print >> sys.stderr, s
|
print(s, file=sys.stderr)
|
||||||
|
|
||||||
else: # normal user (not svn user)
|
else: # normal user (not svn user)
|
||||||
type_ = 'install'
|
type_ = 'install'
|
||||||
|
|
|
@ -2446,7 +2446,7 @@ class Interface:
|
||||||
def save_config(self):
|
def save_config(self):
|
||||||
err_str = parser.write()
|
err_str = parser.write()
|
||||||
if err_str is not None:
|
if err_str is not None:
|
||||||
print >> sys.stderr, err_str
|
print(err_str, file=sys.stderr)
|
||||||
# it is good to notify the user
|
# it is good to notify the user
|
||||||
# in case he or she cannot see the output of the console
|
# in case he or she cannot see the output of the console
|
||||||
dialogs.ErrorDialog(_('Could not save your settings and '
|
dialogs.ErrorDialog(_('Could not save your settings and '
|
||||||
|
@ -2608,7 +2608,7 @@ class Interface:
|
||||||
try:
|
try:
|
||||||
from ipython_view import IPythonView
|
from ipython_view import IPythonView
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print 'ipython_view not found'
|
print('ipython_view not found')
|
||||||
return
|
return
|
||||||
from gi.repository import Pango
|
from gi.repository import Pango
|
||||||
|
|
||||||
|
|
|
@ -309,11 +309,11 @@ class IterableIPShell:
|
||||||
@param header: Header to be printed before output
|
@param header: Header to be printed before output
|
||||||
@type header: string
|
@type header: string
|
||||||
"""
|
"""
|
||||||
if verbose or debug: print header+cmd
|
if verbose or debug: print(header+cmd)
|
||||||
# flush stdout so we don't mangle python's buffering
|
# flush stdout so we don't mangle python's buffering
|
||||||
if not debug:
|
if not debug:
|
||||||
input_, output = os.popen4(cmd)
|
input_, output = os.popen4(cmd)
|
||||||
print output.read()
|
print(output.read())
|
||||||
output.close()
|
output.close()
|
||||||
input_.close()
|
input_.close()
|
||||||
|
|
||||||
|
|
|
@ -290,14 +290,14 @@ class MusicTrackListener(GObject.GObject):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
def music_track_change_cb(listener, music_track_info):
|
def music_track_change_cb(listener, music_track_info):
|
||||||
if music_track_info is None:
|
if music_track_info is None:
|
||||||
print 'Stop!'
|
print('Stop!')
|
||||||
else:
|
else:
|
||||||
print music_track_info.title
|
print(music_track_info.title)
|
||||||
listener = MusicTrackListener.get()
|
listener = MusicTrackListener.get()
|
||||||
listener.connect('music-track-changed', music_track_change_cb)
|
listener.connect('music-track-changed', music_track_change_cb)
|
||||||
track = listener.get_playing_track()
|
track = listener.get_playing_track()
|
||||||
if track is None:
|
if track is None:
|
||||||
print 'Now not playing anything'
|
print('Now not playing anything')
|
||||||
else:
|
else:
|
||||||
print 'Now playing: "%s" by %s' % (track.title, track.artist)
|
print('Now playing: "%s" by %s' % (track.title, track.artist))
|
||||||
GObject.MainLoop().run()
|
GObject.MainLoop().run()
|
||||||
|
|
|
@ -46,7 +46,7 @@ class TestResolver(unittest.TestCase):
|
||||||
def testLibAsyncNSResolver(self):
|
def testLibAsyncNSResolver(self):
|
||||||
self._reset()
|
self._reset()
|
||||||
if not resolver.USE_LIBASYNCNS:
|
if not resolver.USE_LIBASYNCNS:
|
||||||
print 'testLibAsyncResolver: libasyncns-python not installed'
|
print('testLibAsyncResolver: libasyncns-python not installed')
|
||||||
return
|
return
|
||||||
self.resolver = resolver.LibAsyncNSResolver()
|
self.resolver = resolver.LibAsyncNSResolver()
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ class TestNonBlockingClient(unittest.TestCase):
|
||||||
self.assert_(self.connection.con)
|
self.assert_(self.connection.con)
|
||||||
features = self.client.Dispatcher.Stream.features
|
features = self.client.Dispatcher.Stream.features
|
||||||
if not features.getTag('auth'):
|
if not features.getTag('auth'):
|
||||||
print "Server doesn't support old authentication type, ignoring test"
|
print("Server doesn't support old authentication type, ignoring test")
|
||||||
else:
|
else:
|
||||||
self.assert_(self.connection.auth=='old_auth',
|
self.assert_(self.connection.auth=='old_auth',
|
||||||
msg='Unable to auth via old_auth')
|
msg='Unable to auth via old_auth')
|
||||||
|
|
|
@ -18,12 +18,12 @@ try:
|
||||||
longargs = 'help no-x verbose='
|
longargs = 'help no-x verbose='
|
||||||
opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split())
|
opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split())
|
||||||
except getopt.error, msg:
|
except getopt.error, msg:
|
||||||
print msg
|
print(msg)
|
||||||
print 'for help use --help'
|
print('for help use --help')
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o in ('-h', '--help'):
|
if o in ('-h', '--help'):
|
||||||
print 'runtests [--help] [--no-x] [--verbose level]'
|
print('runtests [--help] [--no-x] [--verbose level]')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif o in ('-n', '--no-x'):
|
elif o in ('-n', '--no-x'):
|
||||||
use_x = False
|
use_x = False
|
||||||
|
@ -31,7 +31,7 @@ for o, a in opts:
|
||||||
try:
|
try:
|
||||||
verbose = int(a)
|
verbose = int(a)
|
||||||
except Exception:
|
except Exception:
|
||||||
print 'verbose must be a number >= 0'
|
print('verbose must be a number >= 0')
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# new test modules need to be added manually
|
# new test modules need to be added manually
|
||||||
|
|
|
@ -16,10 +16,10 @@ from common import jingle_xtls
|
||||||
class fake_sock(Mock):
|
class fake_sock(Mock):
|
||||||
def __init__(self, sockobj):
|
def __init__(self, sockobj):
|
||||||
Mock.__init__(self)
|
Mock.__init__(self)
|
||||||
|
|
||||||
self.sockobj = sockobj
|
self.sockobj = sockobj
|
||||||
|
|
||||||
|
|
||||||
def setup_stream(self):
|
def setup_stream(self):
|
||||||
sha1 = self.sockobj._get_sha1_auth()
|
sha1 = self.sockobj._get_sha1_auth()
|
||||||
|
|
||||||
|
@ -36,29 +36,29 @@ class fake_sock(Mock):
|
||||||
def switch_stream(self):
|
def switch_stream(self):
|
||||||
# Roles are reversed, client will be expecting server stream
|
# Roles are reversed, client will be expecting server stream
|
||||||
# and server will be expecting client stream
|
# and server will be expecting client stream
|
||||||
|
|
||||||
temp = self.incoming
|
temp = self.incoming
|
||||||
self.incoming = self.outgoing
|
self.incoming = self.outgoing
|
||||||
self.outgoing = temp
|
self.outgoing = temp
|
||||||
|
|
||||||
def _recv(self, foo):
|
def _recv(self, foo):
|
||||||
return self.incoming.pop(0)
|
return self.incoming.pop(0)
|
||||||
|
|
||||||
def _send(self, data):
|
def _send(self, data):
|
||||||
# This method is surrounded by a try block,
|
# This method is surrounded by a try block,
|
||||||
# we can't use assert here
|
# we can't use assert here
|
||||||
|
|
||||||
if data != self.outgoing[0]:
|
if data != self.outgoing[0]:
|
||||||
print 'FAILED SENDING TEST'
|
print('FAILED SENDING TEST')
|
||||||
self.outgoing.pop(0)
|
self.outgoing.pop(0)
|
||||||
|
|
||||||
class fake_idlequeue(Mock):
|
class fake_idlequeue(Mock):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Mock.__init__(self)
|
Mock.__init__(self)
|
||||||
|
|
||||||
def plug_idle(self, obj, writable=True, readable=True):
|
def plug_idle(self, obj, writable=True, readable=True):
|
||||||
|
|
||||||
if readable:
|
if readable:
|
||||||
obj.pollin()
|
obj.pollin()
|
||||||
if writable:
|
if writable:
|
||||||
|
@ -77,7 +77,7 @@ class TestSocks5(unittest.TestCase):
|
||||||
queue.file_props = {}
|
queue.file_props = {}
|
||||||
#self.sockobj = Socks5Receiver(fake_idlequeue(), streamhost, None)
|
#self.sockobj = Socks5Receiver(fake_idlequeue(), streamhost, None)
|
||||||
self.sockobj = Socks5Sender(fake_idlequeue(), None, 'server', Mock() ,
|
self.sockobj = Socks5Sender(fake_idlequeue(), None, 'server', Mock() ,
|
||||||
None, None, True, file_props={})
|
None, None, True, file_props={})
|
||||||
sock = fake_sock(self.sockobj)
|
sock = fake_sock(self.sockobj)
|
||||||
self.sockobj._sock = sock
|
self.sockobj._sock = sock
|
||||||
self.sockobj._recv = sock._recv
|
self.sockobj._recv = sock._recv
|
||||||
|
@ -85,70 +85,70 @@ class TestSocks5(unittest.TestCase):
|
||||||
self.sockobj.state = 1
|
self.sockobj.state = 1
|
||||||
self.sockobj.connected = True
|
self.sockobj.connected = True
|
||||||
self.sockobj.pollend = self._pollend
|
self.sockobj.pollend = self._pollend
|
||||||
|
|
||||||
# Something that the receiver needs
|
# Something that the receiver needs
|
||||||
#self.sockobj.file_props['type'] = 'r'
|
#self.sockobj.file_props['type'] = 'r'
|
||||||
|
|
||||||
# Something that the sender needs
|
# Something that the sender needs
|
||||||
self.sockobj.file_props = {}
|
self.sockobj.file_props = {}
|
||||||
self.sockobj.file_props['type'] = 'r'
|
self.sockobj.file_props['type'] = 'r'
|
||||||
self.sockobj.file_props['paused'] = ''
|
self.sockobj.file_props['paused'] = ''
|
||||||
self.sockobj.queue = Mock()
|
self.sockobj.queue = Mock()
|
||||||
self.sockobj.queue.process_result = self._pollend
|
self.sockobj.queue.process_result = self._pollend
|
||||||
|
|
||||||
def _pollend(self, foo = None, duu = None):
|
def _pollend(self, foo = None, duu = None):
|
||||||
# This is a disconnect function
|
# This is a disconnect function
|
||||||
sys.exit("end of the road")
|
sys.exit("end of the road")
|
||||||
|
|
||||||
def _check_inout(self):
|
def _check_inout(self):
|
||||||
# Check if there isn't anything else to receive or send
|
# Check if there isn't anything else to receive or send
|
||||||
sock = self.sockobj._sock
|
sock = self.sockobj._sock
|
||||||
assert(sock.incoming == [])
|
assert(sock.incoming == [])
|
||||||
assert(sock.outgoing == [])
|
assert(sock.outgoing == [])
|
||||||
|
|
||||||
def test_connection_server(self):
|
def test_connection_server(self):
|
||||||
return
|
return
|
||||||
mocksock = self.sockobj._sock
|
mocksock = self.sockobj._sock
|
||||||
mocksock.setup_stream()
|
mocksock.setup_stream()
|
||||||
#self.sockobj._sock.switch_stream()
|
#self.sockobj._sock.switch_stream()
|
||||||
s = socket.socket(2, 1, 6)
|
s = socket.socket(2, 1, 6)
|
||||||
server = ('127.0.0.1', 28000)
|
server = ('127.0.0.1', 28000)
|
||||||
|
|
||||||
s.connect(server)
|
s.connect(server)
|
||||||
|
|
||||||
s.send(mocksock.outgoing.pop(0))
|
|
||||||
self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
|
||||||
|
|
||||||
s.send(mocksock.outgoing.pop(0))
|
s.send(mocksock.outgoing.pop(0))
|
||||||
self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
||||||
|
|
||||||
|
s.send(mocksock.outgoing.pop(0))
|
||||||
|
self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
||||||
|
|
||||||
def test_connection_client(self):
|
def test_connection_client(self):
|
||||||
|
|
||||||
|
|
||||||
mocksock = self.sockobj._sock
|
mocksock = self.sockobj._sock
|
||||||
mocksock.setup_stream()
|
mocksock.setup_stream()
|
||||||
mocksock.switch_stream()
|
mocksock.switch_stream()
|
||||||
s = socket.socket(10, 1, 6)
|
s = socket.socket(10, 1, 6)
|
||||||
|
|
||||||
|
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||||
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||||
|
|
||||||
netadd = ('::', 28000, 0, 0)
|
netadd = ('::', 28000, 0, 0)
|
||||||
s.bind(netadd)
|
s.bind(netadd)
|
||||||
s.listen(socket.SOMAXCONN)
|
s.listen(socket.SOMAXCONN)
|
||||||
(s, address) = s.accept()
|
(s, address) = s.accept()
|
||||||
|
|
||||||
|
|
||||||
self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
||||||
s.send(mocksock.outgoing.pop(0))
|
s.send(mocksock.outgoing.pop(0))
|
||||||
|
|
||||||
buff = s.recv(64)
|
buff = s.recv(64)
|
||||||
inco = mocksock.incoming.pop(0)
|
inco = mocksock.incoming.pop(0)
|
||||||
#self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
#self.assertEquals(s.recv(64), mocksock.incoming.pop(0))
|
||||||
s.send(mocksock.outgoing.pop(0))
|
s.send(mocksock.outgoing.pop(0))
|
||||||
|
|
||||||
def test_client_negoc(self):
|
def test_client_negoc(self):
|
||||||
return
|
return
|
||||||
self.sockobj._sock.setup_stream()
|
self.sockobj._sock.setup_stream()
|
||||||
|
@ -156,22 +156,22 @@ class TestSocks5(unittest.TestCase):
|
||||||
self.sockobj.pollout()
|
self.sockobj.pollout()
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._check_inout()
|
self._check_inout()
|
||||||
|
|
||||||
def test_server_negoc(self):
|
def test_server_negoc(self):
|
||||||
return
|
return
|
||||||
self.sockobj._sock.setup_stream()
|
self.sockobj._sock.setup_stream()
|
||||||
self.sockobj._sock.switch_stream()
|
self.sockobj._sock.switch_stream()
|
||||||
try:
|
try:
|
||||||
self.sockobj.idlequeue.plug_idle(self.sockobj, False, True)
|
self.sockobj.idlequeue.plug_idle(self.sockobj, False, True)
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
self._check_inout()
|
self._check_inout()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue