Fix some formatting affected by the space conversion. IMPORTANT: Channel list attributes are now stored via Django's bundled version of simplejson instead of cPickle/pickle. Pickle isn't unicode-capable in 2.5 and lower, plus JSON is going to be a lot more accessible for web-stuff.

This commit is contained in:
Greg Taylor 2008-06-14 04:18:20 +00:00
parent ffe9a563e0
commit 131f6410d4
6 changed files with 22 additions and 21 deletions

View file

@ -1,6 +1,7 @@
import cPickle as pickle
import time, datetime import time, datetime
from django.utils import simplejson
from apps.objects.models import CommChannel, CommChannelMessage from apps.objects.models import CommChannel, CommChannelMessage
import session_mgr import session_mgr
import ansi import ansi
@ -125,7 +126,7 @@ def plr_set_channel_listening(session, alias, listening):
listening: (bool) A True or False value to determine listening status. listening: (bool) A True or False value to determine listening status.
""" """
plr_get_cdict(session).get(alias)[1] = listening plr_get_cdict(session).get(alias)[1] = listening
plr_pickle_channels(session) plr_jsondump_channels(session)
def plr_set_channel(session, alias, cname, listening): def plr_set_channel(session, alias, cname, listening):
""" """
@ -138,15 +139,15 @@ def plr_set_channel(session, alias, cname, listening):
listening: (bool) A True or False value to determine listening status. listening: (bool) A True or False value to determine listening status.
""" """
plr_get_cdict(session)[alias] = [cname, listening] plr_get_cdict(session)[alias] = [cname, listening]
plr_pickle_channels(session) plr_jsondump_channels(session)
def plr_pickle_channels(session): def plr_jsondump_channels(session):
""" """
Save the player's channel list to the CHANLIST attribute. Save the player's channel list to the CHANLIST attribute.
session: (SessionProtocol) A reference to the player session. session: (SessionProtocol) A reference to the player session.
""" """
session.get_pobject().set_attribute("CHANLIST", pickle.dumps(plr_get_cdict(session))) session.get_pobject().set_attribute("CHANLIST", simplejson.dumps(plr_get_cdict(session)))
def plr_del_channel(session, alias): def plr_del_channel(session, alias):
""" """

View file

@ -1,7 +1,7 @@
import os import os
from traceback import format_exc from traceback import format_exc
from apps.config.models import ConfigValue, ConnectScreen from apps.config.models import ConfigValue
import functions_general import functions_general
""" """
Handle the setting/retrieving of server config directives. Handle the setting/retrieving of server config directives.

View file

@ -1,6 +1,6 @@
import time, sys import time, sys
from datetime import datetime from datetime import datetime
import cPickle as pickle from django.utils import simplejson
from twisted.conch.telnet import StatefulTelnetProtocol from twisted.conch.telnet import StatefulTelnetProtocol
@ -68,11 +68,11 @@ class SessionProtocol(StatefulTelnetProtocol):
def load_user_channels(self): def load_user_channels(self):
""" """
Un-pickle a user's channel list from their CHANLIST attribute. Parse JSON dict of a user's channel list from their CHANLIST attribute.
""" """
chan_list = self.get_pobject().get_attribute_value("CHANLIST") chan_list = self.get_pobject().get_attribute_value("CHANLIST")
if chan_list: if chan_list:
self.channels_subscribed = pickle.loads(chan_list) self.channels_subscribed = simplejson.loads(chan_list)
def lineReceived(self, data): def lineReceived(self, data):
""" """
@ -159,7 +159,7 @@ class SessionProtocol(StatefulTelnetProtocol):
pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),)) pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),))
pobject.set_attribute("Lastsite", "%s" % (self.address[0],)) pobject.set_attribute("Lastsite", "%s" % (self.address[0],))
# Load their channel selection from a pickled attribute. # Load their channel selection from a JSON-encoded string attribute.
self.load_user_channels() self.load_user_channels()
def msg(self, message): def msg(self, message):