mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 17:56:32 +01:00
Move to python3 style except.
This commit is contained in:
parent
0493dc0b4e
commit
0384fcc63d
24 changed files with 47 additions and 47 deletions
|
|
@ -565,7 +565,7 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
|||
# catch it here and don't pass it on.
|
||||
pass
|
||||
|
||||
except ExecSystemCommand, exc:
|
||||
except ExecSystemCommand as exc:
|
||||
# Not a normal command: run a system command, if available,
|
||||
# or fall back to a return string.
|
||||
syscmd = exc.syscmd
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
cmdsetclass = cmdsetclass(cmdsetobj)
|
||||
errstring = ""
|
||||
return cmdsetclass
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
logger.log_trace()
|
||||
errstring += _("\nError loading cmdset {path}: \"{error}\"")
|
||||
errstring = errstring.format(path=python_path, error=e)
|
||||
|
|
@ -169,12 +169,12 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
errstring += _("\nError in loading cmdset: No cmdset class '{classname}' in {path}.")
|
||||
errstring = errstring.format(classname=classname, path=python_path)
|
||||
break
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
logger.log_trace()
|
||||
errstring += _("\nSyntaxError encountered when loading cmdset '{path}': \"{error}\".")
|
||||
errstring = errstring.format(path=python_path, error=e)
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.log_trace()
|
||||
errstring += _("\nCompile/Run error when loading cmdset '{path}': \"{error}\".")
|
||||
errstring = errstring.format(path=python_path, error=e)
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ class CmdBatchCommands(MuxCommand):
|
|||
|
||||
try:
|
||||
commands = BATCHCMD.parse_file(python_path)
|
||||
except UnicodeDecodeError, err:
|
||||
except UnicodeDecodeError as err:
|
||||
caller.msg(_UTF8_ERROR % (python_path, err))
|
||||
return
|
||||
except IOError as err:
|
||||
|
|
@ -346,7 +346,7 @@ class CmdBatchCode(MuxCommand):
|
|||
#parse indata file
|
||||
try:
|
||||
codes = BATCHCODE.parse_file(python_path, debug=debug)
|
||||
except UnicodeDecodeError, err:
|
||||
except UnicodeDecodeError as err:
|
||||
caller.msg(_UTF8_ERROR % (python_path, err))
|
||||
return
|
||||
except IOError:
|
||||
|
|
|
|||
|
|
@ -1774,7 +1774,7 @@ class CmdLock(ObjManipCommand):
|
|||
lockdef = re.sub(r"\'|\"", "", lockdef)
|
||||
try:
|
||||
ok = obj.locks.add(lockdef)
|
||||
except LockException, e:
|
||||
except LockException as e:
|
||||
caller.msg(str(e))
|
||||
if ok:
|
||||
caller.msg("Added lock '%s' to %s." % (lockdef, obj))
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ class CmdIC(MuxPlayerCommand):
|
|||
try:
|
||||
player.puppet_object(sessid, new_character)
|
||||
player.db._last_puppet = new_character
|
||||
except RuntimeError, exc:
|
||||
except RuntimeError as exc:
|
||||
self.msg("{rYou cannot become {C%s{n: %s" % (new_character.name, exc))
|
||||
|
||||
|
||||
|
|
@ -298,7 +298,7 @@ class CmdOOC(MuxPlayerCommand):
|
|||
player.unpuppet_object(sessid)
|
||||
self.msg("\n{GYou go OOC.{n\n")
|
||||
player.execute_cmd("look", sessid=sessid)
|
||||
except RuntimeError, exc:
|
||||
except RuntimeError as exc:
|
||||
self.msg("{rCould not unpuppet from {c%s{n: %s" % (old_char, exc))
|
||||
|
||||
class CmdSessions(MuxPlayerCommand):
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ def _create_player(session, playername, password, permissions, typeclass=None):
|
|||
new_player = create.create_player(playername, None, password,
|
||||
permissions=permissions, typeclass=typeclass)
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
session.msg("There was an error creating the Player:\n%s\n If this problem persists, contact an admin." % e)
|
||||
logger.log_trace()
|
||||
return False
|
||||
|
|
@ -505,7 +505,7 @@ def _create_character(session, new_player, typeclass, home, permissions):
|
|||
new_character.db.desc = "This is a Player."
|
||||
# We need to set this to have @ic auto-connect to this character
|
||||
new_player.db._last_puppet = new_character
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
session.msg("There was an error creating the Character:\n%s\n If this problem persists, contact an admin." % e)
|
||||
logger.log_trace()
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ class DefaultChannel(ChannelDB):
|
|||
# note our addition of the from_channel keyword here. This could be checked
|
||||
# by a custom player.msg() to treat channel-receives differently.
|
||||
entity.msg(msg.message, from_obj=msg.senders, from_channel=self.id)
|
||||
except AttributeError, e:
|
||||
except AttributeError as e:
|
||||
logger.log_trace("%s\nCannot send msg to '%s'." % (e, entity))
|
||||
|
||||
def msg(self, msgobj, header=None, senders=None, sender_strings=None,
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ its and @/./+/-/_ only.") # this echoes the restrictions made by django's auth m
|
|||
new_player = create.create_player(playername, email, password,
|
||||
permissions=permissions)
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e)
|
||||
logger.log_trace()
|
||||
return
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class CmdMenuNode(Command):
|
|||
if self.callback:
|
||||
try:
|
||||
self.callback()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.caller.msg("%s\n{rThere was an error with this selection.{n" % e)
|
||||
else:
|
||||
self.caller.msg("{rThis option is not available.{n")
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class ObjectDB(TypedObject):
|
|||
errmsg = "Error: %s.location = %s creates a location loop." % (self.key, location)
|
||||
logger.log_errmsg(errmsg)
|
||||
raise #RuntimeError(errmsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
errmsg = "Error (%s): %s is not a valid location." % (str(e), location)
|
||||
logger.log_errmsg(errmsg)
|
||||
raise #Exception(errmsg)
|
||||
|
|
|
|||
|
|
@ -527,7 +527,7 @@ def check_database():
|
|||
from evennia.players.models import PlayerDB
|
||||
try:
|
||||
PlayerDB.objects.get(id=1)
|
||||
except django.db.utils.OperationalError, e:
|
||||
except django.db.utils.OperationalError as e:
|
||||
print ERROR_DATABASE.format(traceback=e)
|
||||
sys.exit()
|
||||
except PlayerDB.DoesNotExist:
|
||||
|
|
@ -783,7 +783,7 @@ def init_game_directory(path, check_db=True):
|
|||
# test existence of the settings module
|
||||
try:
|
||||
from django.conf import settings
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
if not str(ex).startswith("No module named"):
|
||||
import traceback
|
||||
print traceback.format_exc().strip()
|
||||
|
|
@ -1226,7 +1226,7 @@ def main():
|
|||
args.append(arg)
|
||||
try:
|
||||
django.core.management.call_command(*args, **kwargs)
|
||||
except django.core.management.base.CommandError, exc:
|
||||
except django.core.management.base.CommandError as exc:
|
||||
args = ", ".join(args)
|
||||
kwargs = ", ".join(["--%s" % kw for kw in kwargs])
|
||||
print ERROR_INPUT.format(traceback=exc, args=args, kwargs=kwargs)
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ def start_services(server_argv, portal_argv):
|
|||
def server_waiter(queue):
|
||||
try:
|
||||
rc = Popen(server_argv, env=getenv()).wait()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print PROCESS_ERROR.format(component="Server", traceback=e)
|
||||
return
|
||||
# this signals the controller that the program finished
|
||||
|
|
@ -153,7 +153,7 @@ def start_services(server_argv, portal_argv):
|
|||
def portal_waiter(queue):
|
||||
try:
|
||||
rc = Popen(portal_argv, env=getenv()).wait()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print PROCESS_ERROR.format(component="Portal", traceback=e)
|
||||
return
|
||||
# this signals the controller that the program finished
|
||||
|
|
@ -168,7 +168,7 @@ def start_services(server_argv, portal_argv):
|
|||
# normal operation: start portal as a daemon;
|
||||
# we don't care to monitor it for restart
|
||||
PORTAL = Popen(portal_argv, env=getenv())
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
print PROCESS_IOERROR.format(component="Portal", traceback=e)
|
||||
return
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ def start_services(server_argv, portal_argv):
|
|||
if server_argv:
|
||||
# start server as a reloadable thread
|
||||
SERVER = thread.start_new_thread(server_waiter, (processes, ))
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
print PROCESS_IOERROR.format(component="Server", traceback=e)
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ def oob_send(session, *args, **kwargs):
|
|||
#print "MSDP SEND inp:", name
|
||||
value = OOB_SENDABLE.get(name, _NA)(obj)
|
||||
ret[name] = value
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
ret[name] = str(e)
|
||||
# return, make sure to use the right case
|
||||
session.msg(oob=("MSDP_TABLE", (), ret))
|
||||
|
|
|
|||
|
|
@ -462,7 +462,7 @@ class OOBHandler(TickerHandler):
|
|||
# we found an oob command. Execute it.
|
||||
try:
|
||||
oobfunc(session, *args, **kwargs)
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
errmsg = "Exception in %s(*%s, **%s):\n%s" % (oobfuncname, args, kwargs, err)
|
||||
if _OOB_ERROR:
|
||||
_OOB_ERROR(session, errmsg, *args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ class SshProtocol(Manhole, session.Session):
|
|||
"""
|
||||
try:
|
||||
text = utils.to_str(text if text else "", encoding=self.encoding)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.lineSend(str(e))
|
||||
return
|
||||
raw = kwargs.get("raw", False)
|
||||
|
|
@ -382,7 +382,7 @@ def makeFactory(configdict):
|
|||
publicKey, privateKey = getKeyPair(pubkeyfile, privkeyfile)
|
||||
factory.publicKeys = {'ssh-rsa': publicKey}
|
||||
factory.privateKeys = {'ssh-rsa': privateKey}
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print " getKeyPair error: %(e)s\n WARNING: Evennia could not auto-generate SSH keypair. Using conch default keys instead." % {'e': e}
|
||||
print " If this error persists, create game/%(pub)s and game/%(priv)s yourself using third-party tools." % {'pub': pubkeyfile, 'priv': privkeyfile}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def verify_SSL_key_and_cert(keyfile, certfile):
|
|||
rsaKey = Key(RSA.generate(KEY_LENGTH))
|
||||
keyString = rsaKey.toString(type="OPENSSH")
|
||||
file(keyfile, 'w+b').write(keyString)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print "rsaKey error: %(e)s\n WARNING: Evennia could not auto-generate SSL private key." % {'e': e}
|
||||
print "If this error persists, create game/%(keyfile)s yourself using third-party tools." % {'keyfile': keyfile}
|
||||
sys.exit(5)
|
||||
|
|
@ -58,7 +58,7 @@ def verify_SSL_key_and_cert(keyfile, certfile):
|
|||
try:
|
||||
#, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
subprocess.call(exestring)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
string = "\n".join([
|
||||
" %s\n" % e,
|
||||
" Evennia's SSL context factory could not automatically",
|
||||
|
|
|
|||
|
|
@ -172,12 +172,12 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
else:
|
||||
self.iaw_mode = False
|
||||
return
|
||||
except Exception, err1:
|
||||
except Exception as err1:
|
||||
conv = ""
|
||||
try:
|
||||
for b in data:
|
||||
conv += " " + repr(ord(b))
|
||||
except Exception, err2:
|
||||
except Exception as err2:
|
||||
conv = str(err2) + ":", str(data)
|
||||
out = "Telnet Error (%s): %s (%s)" % (err1, data, conv)
|
||||
logger.log_trace(out)
|
||||
|
|
@ -299,7 +299,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
|
||||
try:
|
||||
text = utils.to_str(text if text else "", encoding=self.encoding)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.sendLine(str(e))
|
||||
return
|
||||
if "oob" in kwargs and "OOB" in self.protocol_flags:
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class WebSocketClient(Protocol, Session):
|
|||
"""
|
||||
try:
|
||||
text = to_str(text if text else "", encoding=self.encoding)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.sendLine(str(e))
|
||||
if "oob" in kwargs:
|
||||
for cmdname, args, okwargs in kwargs["oob"]:
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ def read_batchfile(pythonpath, file_ending='.py'):
|
|||
try:
|
||||
with codecs.open(abspath, 'r', encoding=file_encoding) as fobj:
|
||||
text = fobj.read()
|
||||
except (ValueError, UnicodeDecodeError), e:
|
||||
except (ValueError, UnicodeDecodeError) as e:
|
||||
# this means an encoding error; try another encoding
|
||||
decoderr.append(str(e))
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -626,7 +626,7 @@ class EvEditor(object):
|
|||
"""
|
||||
try:
|
||||
self._buffer = self._loadfunc(self._caller)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self._caller.msg(_ERROR_LOADFUNC.format(error=e))
|
||||
|
||||
def get_buffer(self):
|
||||
|
|
@ -661,7 +661,7 @@ class EvEditor(object):
|
|||
"""
|
||||
try:
|
||||
self._quitfunc(self._caller)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self._caller.msg(_ERROR_QUITFUNC.format(error=e))
|
||||
del self._caller.ndb._lineeditor
|
||||
self._caller.cmdset.remove(EvEditorCmdSet)
|
||||
|
|
@ -679,7 +679,7 @@ class EvEditor(object):
|
|||
# save worked. The saving function is responsible for
|
||||
# any status messages.
|
||||
self._unsaved = False
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self._caller.msg(_ERROR_SAVEFUNC.format(error=e))
|
||||
else:
|
||||
self._caller.msg(_MSG_SAVE_NO_CHANGE)
|
||||
|
|
|
|||
|
|
@ -1266,7 +1266,7 @@ class EvTable(object):
|
|||
for ix, col in enumerate(self.worktable):
|
||||
try:
|
||||
col.reformat(width=cwidths[ix], **options)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
msg = "ix=%s, width=%s: %s" % (ix, cwidths[ix], e.message)
|
||||
raise #Exception ("Error in horizontal allign:\n %s" % msg)
|
||||
|
||||
|
|
@ -1315,7 +1315,7 @@ class EvTable(object):
|
|||
for iy, cell in enumerate(col):
|
||||
try:
|
||||
col.reformat_cell(iy, height=cheights[iy], **options)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
msg = "ix=%s, iy=%s, height=%s: %s" % (ix, iy, cheights[iy], e.message)
|
||||
raise Exception ("Error in vertical allign:\n %s" % msg)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def log_trace(errmsg=None):
|
|||
if errmsg:
|
||||
try:
|
||||
errmsg = str(errmsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
errmsg = str(e)
|
||||
for line in errmsg.splitlines():
|
||||
log.msg('[EE] %s' % line)
|
||||
|
|
@ -59,7 +59,7 @@ def log_err(errmsg):
|
|||
"""
|
||||
try:
|
||||
errmsg = str(errmsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
errmsg = str(e)
|
||||
for line in errmsg.splitlines():
|
||||
log.msg('[EE] %s' % line)
|
||||
|
|
@ -77,7 +77,7 @@ def log_warn(warnmsg):
|
|||
"""
|
||||
try:
|
||||
warnmsg = str(warnmsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
warnmsg = str(e)
|
||||
for line in warnmsg.splitlines():
|
||||
log.msg('[WW] %s' % line)
|
||||
|
|
@ -93,7 +93,7 @@ def log_info(infomsg):
|
|||
"""
|
||||
try:
|
||||
infomsg = str(infomsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
infomsg = str(e)
|
||||
for line in infomsg.splitlines():
|
||||
log.msg('[..] %s' % line)
|
||||
|
|
@ -109,7 +109,7 @@ def log_dep(depmsg):
|
|||
"""
|
||||
try:
|
||||
depmsg = str(depmsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
depmsg = str(e)
|
||||
for line in depmsg.splitlines():
|
||||
log.msg('[DP] %s' % line)
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ class WebSocketProtocol(ProtocolWrapper):
|
|||
|
||||
try:
|
||||
frames, self.buf = parser(self.buf)
|
||||
except WSException, wse:
|
||||
except WSException as wse:
|
||||
# Couldn't parse all the frames, something went wrong, let's bail.
|
||||
self.close(wse.args[0])
|
||||
return
|
||||
|
|
|
|||
|
|
@ -926,7 +926,7 @@ def mod_import(module):
|
|||
if errmsg:
|
||||
try:
|
||||
errmsg = to_str(errmsg)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
errmsg = str(e)
|
||||
for line in errmsg.splitlines():
|
||||
log.msg('[EE] %s' % line)
|
||||
|
|
@ -941,7 +941,7 @@ def mod_import(module):
|
|||
# first try to import as a python path
|
||||
try:
|
||||
mod = __import__(module, fromlist=["None"])
|
||||
except ImportError, ex:
|
||||
except ImportError as ex:
|
||||
# check just where the ImportError happened (it could have been
|
||||
# an erroneous import inside the module as well). This is the
|
||||
# trivial way to do it ...
|
||||
|
|
@ -1104,7 +1104,7 @@ def fuzzy_import_from_module(path, variable, default=None, defaultpaths=None):
|
|||
for modpath in paths:
|
||||
try:
|
||||
mod = import_module(path)
|
||||
except ImportError, ex:
|
||||
except ImportError as ex:
|
||||
if not str(ex).startswith ("No module named %s" % path):
|
||||
# this means the module was found but it
|
||||
# triggers an ImportError on import.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue