mirror of
https://github.com/evennia/evennia.git
synced 2026-04-03 14:37:17 +02:00
Moved inlinefunc-parsing to sessionhandler level. First text throughput for webclient alongside telnet.
This commit is contained in:
parent
2890371900
commit
1044006303
4 changed files with 49 additions and 31 deletions
|
|
@ -300,7 +300,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
"""
|
||||
for session in self.values():
|
||||
session.data_out(text=(message,))
|
||||
self.data_out(session, text=message)
|
||||
|
||||
def data_in(self, session, **kwargs):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ from django.utils import timezone
|
|||
from django.conf import settings
|
||||
from evennia.comms.models import ChannelDB
|
||||
from evennia.utils import logger
|
||||
from evennia.utils.inlinefunc import parse_inlinefunc
|
||||
from evennia.utils.nested_inlinefuncs import parse_inlinefunc as parse_nested_inlinefunc
|
||||
from evennia.utils.utils import make_iter, lazy_property
|
||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||
from evennia.server.session import Session
|
||||
|
|
@ -25,7 +23,6 @@ _GA = object.__getattribute__
|
|||
_SA = object.__setattr__
|
||||
_ObjectDB = None
|
||||
_ANSI = None
|
||||
_INLINEFUNC_ENABLED = settings.INLINEFUNC_ENABLED
|
||||
|
||||
# i18n
|
||||
from django.utils.translation import ugettext as _
|
||||
|
|
@ -333,7 +330,7 @@ class ServerSession(Session):
|
|||
self.cmd_last_visible = self.cmd_last
|
||||
|
||||
|
||||
def data_out(self, text=None, **kwargs):
|
||||
def data_out(self, **kwargs):
|
||||
"""
|
||||
Sending data from Evennia->Player
|
||||
|
||||
|
|
@ -343,28 +340,29 @@ class ServerSession(Session):
|
|||
by their keys. Or "options", carrying options
|
||||
for the protocol(s).
|
||||
|
||||
Notes:
|
||||
We need to handle inlinefunc-parsing at this point
|
||||
since we must have access to the database and the
|
||||
Server Session.
|
||||
"""
|
||||
print "serversession.data_out:", kwargs
|
||||
|
||||
self.sessionhandler.data_out(self, **kwargs)
|
||||
|
||||
def msg(self, text=None, **kwargs):
|
||||
"""
|
||||
Wrapper to mimic msg() functionality elsewhere.
|
||||
|
||||
Args:
|
||||
text (str): String input.
|
||||
|
||||
Kwargs:
|
||||
any (str or tuple): Send-commands identified
|
||||
by their keys. Or "options", carrying options
|
||||
for the protocol(s).
|
||||
|
||||
"""
|
||||
print "serversession.data_out:", text, kwargs
|
||||
if text:
|
||||
if hasattr(text, "__iter__"):
|
||||
text, args = text[0], list(text[1:])
|
||||
else:
|
||||
text, args = text, []
|
||||
options = kwargs.get("options", None) or {}
|
||||
raw = options.get("raw", False)
|
||||
strip_inlinefunc = options.get("strip_inlinefunc", False)
|
||||
if _INLINEFUNC_ENABLED and not raw:
|
||||
text = parse_inlinefunc(text, strip=strip_inlinefunc, session=self)
|
||||
text = parse_nested_inlinefunc(text, strip=strip_inlinefunc, session=self)
|
||||
text = [text] + args
|
||||
self.data_out(text=text, **kwargs)
|
||||
else:
|
||||
self.data_out(**kwargs)
|
||||
|
||||
self.sessionhandler.data_out(self, text=text, **kwargs)
|
||||
msg = data_out # alias
|
||||
|
||||
def __eq__(self, other):
|
||||
"Handle session comparisons"
|
||||
|
|
|
|||
|
|
@ -23,12 +23,15 @@ from evennia.utils.utils import (variable_from_module, is_iter,
|
|||
to_str, to_unicode,
|
||||
make_iter,
|
||||
callables_from_module)
|
||||
from evennia.utils.inlinefunc import parse_inlinefunc
|
||||
from evennia.utils.nested_inlinefuncs import parse_inlinefunc as parse_nested_inlinefunc
|
||||
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
_INLINEFUNC_ENABLED = settings.INLINEFUNC_ENABLED
|
||||
|
||||
# delayed imports
|
||||
_PlayerDB = None
|
||||
|
|
@ -129,7 +132,7 @@ class SessionHandler(dict):
|
|||
|
||||
def clean_senddata(self, session, kwargs):
|
||||
"""
|
||||
Clean up data for sending across the AMP wire.
|
||||
Clean up data for sending across the AMP wire. Also apply INLINEFUNCS.
|
||||
|
||||
Args:
|
||||
session (Session): The relevant session instance.
|
||||
|
|
@ -146,9 +149,14 @@ class SessionHandler(dict):
|
|||
Returns:
|
||||
kwargs (dict): A cleaned dictionary of cmdname:[[args],{kwargs}] pairs,
|
||||
where the keys, args and kwargs have all been converted to
|
||||
send-safe entities (strings or numbers).
|
||||
send-safe entities (strings or numbers), and inlinefuncs have been
|
||||
applied.
|
||||
|
||||
"""
|
||||
options = kwargs.get("options", None) or {}
|
||||
raw = options.get("raw", False)
|
||||
strip_inlinefunc = options.get("strip_inlinefunc", False)
|
||||
|
||||
def _validate(data):
|
||||
"Helper function to convert data to AMP-safe (picketable) values"
|
||||
if isinstance(data, dict):
|
||||
|
|
@ -161,11 +169,15 @@ class SessionHandler(dict):
|
|||
elif isinstance(data, basestring):
|
||||
# make sure strings are in a valid encoding
|
||||
try:
|
||||
return data and to_str(to_unicode(data), encoding=session.encoding)
|
||||
data = data and to_str(to_unicode(data), encoding=session.encoding)
|
||||
except LookupError:
|
||||
# wrong encoding set on the session. Set it to a safe one
|
||||
session.encoding = "utf-8"
|
||||
return to_str(to_unicode(data), encoding=session.encoding)
|
||||
data = to_str(to_unicode(data), encoding=session.encoding)
|
||||
if _INLINEFUNC_ENABLED and not raw:
|
||||
data = parse_inlinefunc(data, strip=strip_inlinefunc, session=session) # deprecated!
|
||||
data = parse_nested_inlinefunc(data, strip=strip_inlinefunc, session=session)
|
||||
return data
|
||||
elif hasattr(data, "id") and hasattr(data, "db_date_created") \
|
||||
and hasattr(data, '__dbclass__'):
|
||||
# convert database-object to their string representation.
|
||||
|
|
@ -176,14 +188,20 @@ class SessionHandler(dict):
|
|||
rkwargs = {}
|
||||
for key, data in kwargs.iteritems():
|
||||
print "sessionhandler.clean_senddata:", key, data
|
||||
key = _validate(key)
|
||||
if not data:
|
||||
rkwargs[key] = [ [], {} ]
|
||||
elif isinstance(data, dict):
|
||||
rkwargs[key] = [ [], _validate(data) ]
|
||||
elif hasattr(data, "__iter__"):
|
||||
if isinstance(data[-1], dict):
|
||||
# last entry is a kwarg dict
|
||||
rkwargs[key] = [ _validate(data[:-1]), _validate(data[-1]) ]
|
||||
if len(data) == 2:
|
||||
if hasattr(data[0], "__iter__"):
|
||||
rkwargs[key] = [_validate(data[0]), _validate(data[1])]
|
||||
else:
|
||||
rkwargs[key] = [[_validate(data[0])], _validate(data[1])]
|
||||
else:
|
||||
rkwargs[key] = [ _validate(data[:-1]), _validate(data[-1]) ]
|
||||
else:
|
||||
rkwargs[key] = [ _validate(data), {} ]
|
||||
else:
|
||||
|
|
@ -586,9 +604,11 @@ class ServerSessionHandler(SessionHandler):
|
|||
the wire here.
|
||||
"""
|
||||
# clean output for sending
|
||||
print "sessionhandler before clean_senddata:", kwargs
|
||||
kwargs = self.clean_senddata(session, kwargs)
|
||||
|
||||
# send across AMP
|
||||
print "sessionhandler.data_out:", kwargs
|
||||
print "sessionhandler after clean_senddata:", kwargs
|
||||
self.server.amp_protocol.send_MsgServer2Portal(session,
|
||||
**kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
var sendInput = function() {
|
||||
var inmsg = $("#maininput").val();
|
||||
log("sendInput: " + inmsg);
|
||||
Evennia.msg("text", [inmsg], {});
|
||||
Evennia.msg("echo", [inmsg], {});
|
||||
};
|
||||
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue