Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cylon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ def message_handler(self, conn, mess):
logging.info(cmd)
cmd_parameters = cmd.split()
plugin_name = cmd_parameters[0]
if modules.has_key(plugin_name) or aliases.has_key(plugin_name):
if aliases.has_key(plugin_name):
func = aliases[plugin_name].keys()[0]
if plugin_name in modules or plugin_name in aliases:
if plugin_name in aliases:
func = list(aliases[plugin_name].keys())[0]
inst = aliases[plugin_name][func]
cmd_parameters.pop(0)
try:
msg = self.__call_plugin(mess, inst, func, cmd_parameters)
except AttributeError, e:
except AttributeError as e:
msg = "Function %s not implemented." % func
logging.error("%s plugin exec: %s" % (class_, str(e)))
else:
Expand All @@ -145,7 +145,7 @@ def message_handler(self, conn, mess):
# Way to test if class exists.If exception, error msg.
method = getattr(inst, func)
msg = self.__call_plugin(mess, inst, func, cmd_parameters)
except AttributeError, e:
except AttributeError as e:
msg = "Function %s not implemented." % func
logging.error("%s plugin exec: %s" % (class_, str(e)))
else:
Expand All @@ -161,7 +161,7 @@ def __call_plugin(self, xmpp_mess, class_, func, param):
msg = class_.wrapper(func, xmpp_mess.getBody(),
xmpp_mess.getFrom(), xmpp_mess.getType(),
param)
except Exception, e:
except Exception as e:
msg = "Error during %s function execution." % func
logging.error("%s plugin exec: %s" % (class_, str(e)))

Expand Down Expand Up @@ -236,7 +236,7 @@ def __connect(self):
logging.error("Unable to connect to server %s." %
self._jid.getDomain())
exit()
if res<>'tls':
if res!='tls':
logging.warning("Unable to establish TLS connection.")

res = conn.auth(self._jid.getNode(),
Expand All @@ -245,7 +245,7 @@ def __connect(self):
if not res:
logging.error("Unable to authenticate this connection.")
exit()
if res<>'sasl':
if res!='sasl':
logging.warning("Unable to get SASL creditential for: %s." %
self.jid.getDomain())
conn.RegisterHandler('message', self.message_handler)
Expand All @@ -261,7 +261,7 @@ def __connect(self):
def __join_muc(self):
for room_config in self._settings.groupchat:
if isinstance(room_config, dict):
for k, v in room_config.iteritems():
for k, v in room_config.items():
presence = xmpp.Presence(to="%s/%s" % (k, self._settings.chat_name))
presence.setTag('x', namespace='http://jabber.org/protocol/muc').setTagData('password',v)
else:
Expand Down
2 changes: 1 addition & 1 deletion cylon/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def help(self, body, from_user, chat_type, args):

def list(self, body, from_user, chat_type, args):
msg = "\n"
for type_ in list(self.modules.viewkeys()):
for type_ in list(self.modules.keys()):
msg = msg + type_ + ":\n"
for plugin_name in self.modules[type_]:
msg = msg + " - %s\n" % plugin_name
Expand Down
6 changes: 3 additions & 3 deletions cylon/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def cmd_to_class(command):
def compute_aliases(alias_info, class_inst, plugin_name):
logging.debug("Loading aliases...")
alias_hash = {}
for method_name, alias_name in alias_info.iteritems():
for method_name, alias_name in alias_info.items():
alias_hash.update({alias_name : { method_name : class_inst }})
logging.debug("Final alias list:")
logging.debug(alias_hash)
Expand Down Expand Up @@ -98,11 +98,11 @@ def get_needed_class(filenames, plugin_list, alias_list):
class_inst = class_()
if class_inst.is_public():
plugins['publics'].update({name : class_inst})
if name in alias_list.keys():
if name in list(alias_list.keys()):
aliases['publics'].update(compute_aliases(alias_list[name], class_inst, name))
else:
plugins['privates'].update({name : class_inst})
if alias_list.has_key(name):
if name in alias_list:
aliases['privates'].update(compute_aliases(alias_list[name], class_inst, name))
except TypeError:
logging.error("You need to define help method for %s plugin class" % wanted_class)
Expand Down
10 changes: 5 additions & 5 deletions cylon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, conf_file):
logging.debug("Starting configuration parsing")
try:
stream = file(conf_file, 'r')
except Exception, e:
except Exception as e:
logging.error("%s read: %s" % (conf_file, str(e)))
exit()
logging.info("Loading %s" % conf_file)
Expand All @@ -39,7 +39,7 @@ def __build_alias_settings(self, alias_list):
logging.debug("Get alias list settings:")
alias_hash = {}
for alias in alias_list:
str_ = alias.keys()[0]
str_ = list(alias.keys())[0]
data = str_.split('.')
if str_ == data[0]:
logging.info("Alias %s not loaded." % data[0])
Expand All @@ -51,19 +51,19 @@ def __build_alias_settings(self, alias_list):
logging.info("Alias %s not loaded." % data[0])
continue
plugin_method = data[1]
if alias_hash.has_key(plugin_name):
if plugin_name in alias_hash:
alias_hash[plugin_name].update({ plugin_method : alias_name})
else:
alias_hash.update({ plugin_name : { plugin_method : alias_name }})
del alias
print alias_hash
print(alias_hash)
return alias_hash

def __check(self):
logging.debug("Configuration check")
for attr_type in self.ATTRS:
for attr in attr_type:
if self._conf_file_values.has_key(attr):
if attr in self._conf_file_values:
if not isinstance(self._conf_file_values[attr], attr_type[attr]):
if not attr.startswith("loaded_"):
logging.error("Type error in configuration file: %s has to be a %s." %
Expand Down
5 changes: 2 additions & 3 deletions cylon/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import logging
from abc import ABCMeta, abstractmethod

class Hook:
class Hook(metaclass=ABCMeta):


__metaclass__ = ABCMeta
hooks = {}
settings = {}
connection = None
Expand All @@ -19,5 +18,5 @@ def __init__(self):


def build_regex(self):
for r in self.ACTIONS.keys():
for r in list(self.ACTIONS.keys()):
self.regex.append((re.compile(r), self.ACTIONS[r]))
11 changes: 3 additions & 8 deletions cylon/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import logging
from abc import ABCMeta, abstractmethod

class Plugin:
class Plugin(metaclass=ABCMeta):

__metaclass__ = ABCMeta
plugins = {}
settings = {}
connection = None
Expand All @@ -24,9 +23,7 @@ def default(self, *args):
def help(self):
pass

class Public(Plugin):

__metaclass__ = ABCMeta
class Public(Plugin, metaclass=ABCMeta):

def is_public(self):
return True
Expand All @@ -38,9 +35,7 @@ def is_private(self):
def help(self):
pass

class Private(Plugin):

__metaclass__ = ABCMeta
class Private(Plugin, metaclass=ABCMeta):

def is_public(self):
return False
Expand Down