Added remote function call abilities to AMP protocol, courtesy of patch by user Shell.

This allows for Server to call functions on Portal and vice-versa. Some rewrites and
cleanup done before applying /Griatch.
This commit is contained in:
Griatch 2012-10-14 11:53:34 +02:00
parent 049cc84be7
commit 592bc26b99
2 changed files with 71 additions and 5 deletions

View file

@ -10,7 +10,7 @@ import os, sys, imp, types, math
import textwrap, datetime, random
from inspect import ismodule
from collections import defaultdict
from twisted.internet import threads
from twisted.internet import threads, defer, reactor
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
@ -39,6 +39,7 @@ def is_iter(iterable):
except AttributeError:
return False
def make_iter(obj):
"Makes sure that the object is always iterable."
return not hasattr(obj, '__iter__') and [obj] or obj
@ -87,9 +88,15 @@ def list_to_string(inlist, endsep="and", addquote=False):
"""
This pretty-formats a list as string output, adding
an optional alternative separator to the second to last entry.
If addquote is True, the outgoing strints will be surrounded by quotes.
If addquote is True, the outgoing strings will be surrounded by quotes.
[1,2,3] -> '1, 2 and 3'
Examples:
no endsep:
[1,2,3] -> '1, 2, 3'
with endsep=='and':
[1,2,3] -> '1, 2 and 3'
with addquote and endsep
[1,2,3] -> '"1", "2" and "3"'
"""
if not inlist:
return ""
@ -490,7 +497,6 @@ def uses_database(name="sqlite3"):
return engine == "django.db.backends.%s" % name
_FROM_MODEL_MAP = None
_TO_DBOBJ = lambda o: (hasattr(o, "dbobj") and o.dbobj) or o
_TO_PACKED_DBOBJ = lambda natural_key, dbref: ('__packed_dbobj__', natural_key, dbref)