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():
|
for session in self.values():
|
||||||
session.data_out(text=(message,))
|
self.data_out(session, text=message)
|
||||||
|
|
||||||
def data_in(self, session, **kwargs):
|
def data_in(self, session, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from evennia.comms.models import ChannelDB
|
from evennia.comms.models import ChannelDB
|
||||||
from evennia.utils import logger
|
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.utils.utils import make_iter, lazy_property
|
||||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||||
from evennia.server.session import Session
|
from evennia.server.session import Session
|
||||||
|
|
@ -25,7 +23,6 @@ _GA = object.__getattribute__
|
||||||
_SA = object.__setattr__
|
_SA = object.__setattr__
|
||||||
_ObjectDB = None
|
_ObjectDB = None
|
||||||
_ANSI = None
|
_ANSI = None
|
||||||
_INLINEFUNC_ENABLED = settings.INLINEFUNC_ENABLED
|
|
||||||
|
|
||||||
# i18n
|
# i18n
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
@ -333,7 +330,7 @@ class ServerSession(Session):
|
||||||
self.cmd_last_visible = self.cmd_last
|
self.cmd_last_visible = self.cmd_last
|
||||||
|
|
||||||
|
|
||||||
def data_out(self, text=None, **kwargs):
|
def data_out(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Sending data from Evennia->Player
|
Sending data from Evennia->Player
|
||||||
|
|
||||||
|
|
@ -343,28 +340,29 @@ class ServerSession(Session):
|
||||||
by their keys. Or "options", carrying options
|
by their keys. Or "options", carrying options
|
||||||
for the protocol(s).
|
for the protocol(s).
|
||||||
|
|
||||||
Notes:
|
"""
|
||||||
We need to handle inlinefunc-parsing at this point
|
print "serversession.data_out:", kwargs
|
||||||
since we must have access to the database and the
|
|
||||||
Server Session.
|
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 text:
|
||||||
if hasattr(text, "__iter__"):
|
self.data_out(text=text, **kwargs)
|
||||||
text, args = text[0], list(text[1:])
|
else:
|
||||||
else:
|
self.data_out(**kwargs)
|
||||||
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.sessionhandler.data_out(self, text=text, **kwargs)
|
|
||||||
msg = data_out # alias
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"Handle session comparisons"
|
"Handle session comparisons"
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,15 @@ from evennia.utils.utils import (variable_from_module, is_iter,
|
||||||
to_str, to_unicode,
|
to_str, to_unicode,
|
||||||
make_iter,
|
make_iter,
|
||||||
callables_from_module)
|
callables_from_module)
|
||||||
|
from evennia.utils.inlinefunc import parse_inlinefunc
|
||||||
|
from evennia.utils.nested_inlinefuncs import parse_inlinefunc as parse_nested_inlinefunc
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
_INLINEFUNC_ENABLED = settings.INLINEFUNC_ENABLED
|
||||||
|
|
||||||
# delayed imports
|
# delayed imports
|
||||||
_PlayerDB = None
|
_PlayerDB = None
|
||||||
|
|
@ -129,7 +132,7 @@ class SessionHandler(dict):
|
||||||
|
|
||||||
def clean_senddata(self, session, kwargs):
|
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:
|
Args:
|
||||||
session (Session): The relevant session instance.
|
session (Session): The relevant session instance.
|
||||||
|
|
@ -146,9 +149,14 @@ class SessionHandler(dict):
|
||||||
Returns:
|
Returns:
|
||||||
kwargs (dict): A cleaned dictionary of cmdname:[[args],{kwargs}] pairs,
|
kwargs (dict): A cleaned dictionary of cmdname:[[args],{kwargs}] pairs,
|
||||||
where the keys, args and kwargs have all been converted to
|
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):
|
def _validate(data):
|
||||||
"Helper function to convert data to AMP-safe (picketable) values"
|
"Helper function to convert data to AMP-safe (picketable) values"
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
|
|
@ -161,11 +169,15 @@ class SessionHandler(dict):
|
||||||
elif isinstance(data, basestring):
|
elif isinstance(data, basestring):
|
||||||
# make sure strings are in a valid encoding
|
# make sure strings are in a valid encoding
|
||||||
try:
|
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:
|
except LookupError:
|
||||||
# wrong encoding set on the session. Set it to a safe one
|
# wrong encoding set on the session. Set it to a safe one
|
||||||
session.encoding = "utf-8"
|
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") \
|
elif hasattr(data, "id") and hasattr(data, "db_date_created") \
|
||||||
and hasattr(data, '__dbclass__'):
|
and hasattr(data, '__dbclass__'):
|
||||||
# convert database-object to their string representation.
|
# convert database-object to their string representation.
|
||||||
|
|
@ -176,14 +188,20 @@ class SessionHandler(dict):
|
||||||
rkwargs = {}
|
rkwargs = {}
|
||||||
for key, data in kwargs.iteritems():
|
for key, data in kwargs.iteritems():
|
||||||
print "sessionhandler.clean_senddata:", key, data
|
print "sessionhandler.clean_senddata:", key, data
|
||||||
|
key = _validate(key)
|
||||||
if not data:
|
if not data:
|
||||||
rkwargs[key] = [ [], {} ]
|
rkwargs[key] = [ [], {} ]
|
||||||
elif isinstance(data, dict):
|
elif isinstance(data, dict):
|
||||||
rkwargs[key] = [ [], _validate(data) ]
|
rkwargs[key] = [ [], _validate(data) ]
|
||||||
elif hasattr(data, "__iter__"):
|
elif hasattr(data, "__iter__"):
|
||||||
if isinstance(data[-1], dict):
|
if isinstance(data[-1], dict):
|
||||||
# last entry is a kwarg dict
|
if len(data) == 2:
|
||||||
rkwargs[key] = [ _validate(data[:-1]), _validate(data[-1]) ]
|
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:
|
else:
|
||||||
rkwargs[key] = [ _validate(data), {} ]
|
rkwargs[key] = [ _validate(data), {} ]
|
||||||
else:
|
else:
|
||||||
|
|
@ -586,9 +604,11 @@ class ServerSessionHandler(SessionHandler):
|
||||||
the wire here.
|
the wire here.
|
||||||
"""
|
"""
|
||||||
# clean output for sending
|
# clean output for sending
|
||||||
|
print "sessionhandler before clean_senddata:", kwargs
|
||||||
kwargs = self.clean_senddata(session, kwargs)
|
kwargs = self.clean_senddata(session, kwargs)
|
||||||
|
|
||||||
# send across AMP
|
# send across AMP
|
||||||
print "sessionhandler.data_out:", kwargs
|
print "sessionhandler after clean_senddata:", kwargs
|
||||||
self.server.amp_protocol.send_MsgServer2Portal(session,
|
self.server.amp_protocol.send_MsgServer2Portal(session,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
var sendInput = function() {
|
var sendInput = function() {
|
||||||
var inmsg = $("#maininput").val();
|
var inmsg = $("#maininput").val();
|
||||||
log("sendInput: " + inmsg);
|
log("sendInput: " + inmsg);
|
||||||
Evennia.msg("text", [inmsg], {});
|
Evennia.msg("echo", [inmsg], {});
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue