diff --git a/roundup/xmlrpc.py b/roundup/xmlrpc.py
index 03ef5a1c107fdc812e3f5a5d6fee9ef8866152ef..111a0b72442b87b849db159829dea112a1f919c2 100644 (file)
--- a/roundup/xmlrpc.py
+++ b/roundup/xmlrpc.py
from roundup.date import Date, Range, Interval
from roundup import actions
from SimpleXMLRPCServer import *
+from xmlrpclib import Binary
def translate(value):
"""Translate value to becomes valid for XMLRPC transmission."""
props = {}
for arg in args:
- if arg.find('=') == -1:
+ if isinstance(arg, Binary):
+ arg = arg.data
+ try :
+ key, value = arg.split('=', 1)
+ except ValueError :
raise UsageError, 'argument "%s" not propname=value'%arg
- l = arg.split('=')
- if len(l) < 2:
- raise UsageError, 'argument "%s" not propname=value'%arg
- key, value = l[0], '='.join(l[1:])
+ if isinstance(key, unicode):
+ try:
+ key = key.encode ('ascii')
+ except UnicodeEncodeError:
+ raise UsageError, 'argument %r is no valid ascii keyword'%key
+ if isinstance(value, unicode):
+ value = value.encode('utf-8')
if value:
try:
props[key] = hyperdb.rawToHyperdb(db, cl, itemid,
self.actions = actions
self.translator = translator
+ def schema(self):
+ s = {}
+ for c in self.db.classes:
+ cls = self.db.classes[c]
+ props = [(n,repr(v)) for n,v in cls.properties.items()]
+ s[c] = props
+ return s
+
def list(self, classname, propname=None):
cl = self.db.getclass(classname)
if not propname:
return dict(result)
def create(self, classname, *args):
+
if not self.db.security.hasPermission('Create', self.db.getuid(), classname):
raise Unauthorised('Permission to create %s denied'%classname)
if key and not props.has_key(key):
raise UsageError, 'you must provide the "%s" property.'%key
+ for key in props:
+ if not self.db.security.hasPermission('Create', self.db.getuid(),
+ classname, property=key):
+ raise Unauthorised('Permission to create %s.%s denied'%(classname, key))
+
# do the actual create
try:
result = cl.create(**props)
+ self.db.commit()
except (TypeError, IndexError, ValueError), message:
raise UsageError, message
return result
raise Unauthorised('Permission to edit %s of %s denied'%
(p, designator))
try:
- return cl.set(itemid, **props)
+ result = cl.set(itemid, **props)
+ self.db.commit()
except (TypeError, IndexError, ValueError), message:
raise UsageError, message
+ return result
builtin_actions = {'retire': actions.Retire}
def action(self, name, *args):
- """"""
+ """Execute a named action."""
if name in self.actions:
action_type = self.actions[name]
def __init__(self, db, actions, translator,
allow_none=False, encoding=None):
- SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
+ try:
+ # python2.5 and beyond
+ SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
+ except TypeError:
+ # python2.4
+ SimpleXMLRPCDispatcher.__init__(self)
self.register_instance(RoundupInstance(db, actions, translator))