"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "roundup/xmlrpc.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

xmlrpc.py  (roundup-1.6.1):xmlrpc.py  (roundup-2.0.0)
skipping to change at line 12 skipping to change at line 12
# Copyright (C) 2007 Stefan Seefeld # Copyright (C) 2007 Stefan Seefeld
# All rights reserved. # All rights reserved.
# For license terms see the file COPYING.txt. # For license terms see the file COPYING.txt.
# #
import logging import logging
from roundup import hyperdb from roundup import hyperdb
from roundup.exceptions import Unauthorised, UsageError from roundup.exceptions import Unauthorised, UsageError
from roundup.date import Date, Range, Interval from roundup.date import Date, Range, Interval
from roundup import actions from roundup import actions
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher from roundup.anypy.strings import us2s
from xmlrpclib import Binary
from traceback import format_exc from traceback import format_exc
from roundup.anypy import xmlrpc_
SimpleXMLRPCDispatcher = xmlrpc_.server.SimpleXMLRPCDispatcher
Binary = xmlrpc_.client.Binary
def translate(value): def translate(value):
"""Translate value to becomes valid for XMLRPC transmission.""" """Translate value to becomes valid for XMLRPC transmission."""
if isinstance(value, (Date, Range, Interval)): if isinstance(value, (Date, Range, Interval)):
return repr(value) return repr(value)
elif type(value) is list: elif type(value) is list:
return [translate(v) for v in value] return [translate(v) for v in value]
elif type(value) is tuple: elif type(value) is tuple:
return tuple([translate(v) for v in value]) return tuple([translate(v) for v in value])
skipping to change at line 38 skipping to change at line 40
return value return value
def props_from_args(db, cl, args, itemid=None): def props_from_args(db, cl, args, itemid=None):
"""Construct a list of properties from the given arguments, """Construct a list of properties from the given arguments,
and return them after validation.""" and return them after validation."""
props = {} props = {}
for arg in args: for arg in args:
if isinstance(arg, Binary): if isinstance(arg, Binary):
arg = arg.data arg = arg.data
try : try:
key, value = arg.split('=', 1) key, value = arg.split('=', 1)
except ValueError : except ValueError:
raise UsageError, 'argument "%s" not propname=value'%arg raise UsageError('argument "%s" not propname=value' % arg)
if isinstance(key, unicode): key = us2s(key)
try: value = us2s(value)
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: if value:
try: try:
props[key] = hyperdb.rawToHyperdb(db, cl, itemid, props[key] = hyperdb.rawToHyperdb(db, cl, itemid,
key, value) key, value)
except hyperdb.HyperdbValueError as message: except hyperdb.HyperdbValueError as message:
raise UsageError, message raise UsageError(message)
else: else:
# If we're syncing a file the contents may not be None # If we're syncing a file the contents may not be None
if key == 'content': if key == 'content':
props[key] = '' props[key] = ''
else: else:
props[key] = None props[key] = None
return props return props
class RoundupInstance: class RoundupInstance:
skipping to change at line 78 skipping to change at line 75
def __init__(self, db, actions, translator): def __init__(self, db, actions, translator):
self.db = db self.db = db
self.actions = actions self.actions = actions
self.translator = translator self.translator = translator
def schema(self): def schema(self):
s = {} s = {}
for c in self.db.classes: for c in self.db.classes:
cls = self.db.classes[c] cls = self.db.classes[c]
props = [(n,repr(v)) for n,v in cls.properties.items()] props = [(n, repr(v)) for n, v in sorted(cls.properties.items())]
s[c] = props s[c] = props
return s return s
def list(self, classname, propname=None): def list(self, classname, propname=None):
cl = self.db.getclass(classname) cl = self.db.getclass(classname)
if not propname: if not propname:
propname = cl.labelprop() propname = cl.labelprop()
result = [cl.get(itemid, propname) result = [cl.get(itemid, propname)
for itemid in cl.list() for itemid in cl.list()
if self.db.security.hasPermission('View', self.db.getuid(), if self.db.security.hasPermission('View', self.db.getuid(),
classname, propname, itemid) classname, propname,
itemid)
] ]
return result return result
def filter(self, classname, search_matches, filterspec, def filter(self, classname, search_matches, filterspec,
sort=[], group=[]): sort=[], group=[]):
cl = self.db.getclass(classname) cl = self.db.getclass(classname)
uid = self.db.getuid() uid = self.db.getuid()
security = self.db.security security = self.db.security
filterspec = security.filterFilterspec (uid, classname, filterspec) filterspec = security.filterFilterspec(uid, classname, filterspec)
sort = security.filterSortspec (uid, classname, sort) sort = security.filterSortspec(uid, classname, sort)
group = security.filterSortspec (uid, classname, group) group = security.filterSortspec(uid, classname, group)
result = cl.filter(search_matches, filterspec, sort=sort, group=group) result = cl.filter(search_matches, filterspec, sort=sort, group=group)
check = security.hasPermission check = security.hasPermission
x = [id for id in result if check('View', uid, classname, itemid=id)] x = [id for id in result if check('View', uid, classname, itemid=id)]
return x return x
def lookup(self, classname, key): def lookup(self, classname, key):
cl = self.db.getclass(classname) cl = self.db.getclass(classname)
uid = self.db.getuid() uid = self.db.getuid()
prop = cl.getkey() prop = cl.getkey()
search = self.db.security.hasSearchPermission search = self.db.security.hasSearchPermission
access = self.db.security.hasPermission access = self.db.security.hasPermission
if (not search(uid, classname, prop) if (not search(uid, classname, prop)
and not access('View', uid, classname, prop)): and not access('View', uid, classname, prop)):
raise Unauthorised('Permission to lookup %s denied'%classname) raise Unauthorised('Permission to lookup %s denied' % classname)
return cl.lookup(key) return cl.lookup(key)
def display(self, designator, *properties): def display(self, designator, *properties):
classname, itemid = hyperdb.splitDesignator(designator) classname, itemid = hyperdb.splitDesignator(designator)
cl = self.db.getclass(classname) cl = self.db.getclass(classname)
props = properties and list(properties) or cl.properties.keys() props = properties and list(properties) or list(cl.properties.keys())
props.sort() props.sort()
for p in props: for p in props:
if not self.db.security.hasPermission('View', self.db.getuid(), if not self.db.security.hasPermission('View', self.db.getuid(),
classname, p, itemid): classname, p, itemid):
raise Unauthorised('Permission to view %s of %s denied'% raise Unauthorised('Permission to view %s of %s denied' %
(p, designator)) (p, designator))
result = [(prop, cl.get(itemid, prop)) for prop in props] result = [(prop, cl.get(itemid, prop)) for prop in props]
return dict(result) return dict(result)
def create(self, classname, *args): def create(self, classname, *args):
if not self.db.security.hasPermission('Create', self.db.getuid(),
if not self.db.security.hasPermission('Create', self.db.getuid(), classn classname):
ame): raise Unauthorised('Permission to create %s denied' % classname)
raise Unauthorised('Permission to create %s denied'%classname)
cl = self.db.getclass(classname) cl = self.db.getclass(classname)
# convert types # convert types
props = props_from_args(self.db, cl, args) props = props_from_args(self.db, cl, args)
# check for the key property # check for the key property
key = cl.getkey() key = cl.getkey()
if key and not props.has_key(key): if key and key not in props:
raise UsageError, 'you must provide the "%s" property.'%key raise UsageError('you must provide the "%s" property.' % key)
for key in props: for key in props:
if not self.db.security.hasPermission('Create', self.db.getuid(), if not self.db.security.hasPermission('Create', self.db.getuid(),
classname, property=key): classname, property=key):
raise Unauthorised('Permission to create %s.%s denied'%(classnam raise Unauthorised('Permission to create %s.%s denied' %
e, key)) (classname, key))
# do the actual create # do the actual create
try: try:
result = cl.create(**props) result = cl.create(**props)
self.db.commit() self.db.commit()
except (TypeError, IndexError, ValueError) as message: except (TypeError, IndexError, ValueError) as message:
# The exception we get may be a real error, log the traceback if we' # The exception we get may be a real error, log the traceback
re debugging # if we're debugging
logger = logging.getLogger('roundup.xmlrpc') logger = logging.getLogger('roundup.xmlrpc')
for l in format_exc().split('\n'): for l in format_exc().split('\n'):
logger.debug(l) logger.debug(l)
raise UsageError (message) raise UsageError(message)
return result return result
def set(self, designator, *args): def set(self, designator, *args):
classname, itemid = hyperdb.splitDesignator(designator) classname, itemid = hyperdb.splitDesignator(designator)
cl = self.db.getclass(classname) cl = self.db.getclass(classname)
props = props_from_args(self.db, cl, args, itemid) # convert types props = props_from_args(self.db, cl, args, itemid) # convert types
for p in props.iterkeys(): for p in props.keys():
if not self.db.security.hasPermission('Edit', self.db.getuid(), if not self.db.security.hasPermission('Edit', self.db.getuid(),
classname, p, itemid): classname, p, itemid):
raise Unauthorised('Permission to edit %s of %s denied'% raise Unauthorised('Permission to edit %s of %s denied' %
(p, designator)) (p, designator))
try: try:
result = cl.set(itemid, **props) result = cl.set(itemid, **props)
self.db.commit() self.db.commit()
except (TypeError, IndexError, ValueError) as message: except (TypeError, IndexError, ValueError) as message:
# The exception we get may be a real error, log the traceback if we' # The exception we get may be a real error, log the
re debugging # traceback if we're debugging
logger = logging.getLogger('roundup.xmlrpc') logger = logging.getLogger('roundup.xmlrpc')
for l in format_exc().split('\n'): for l in format_exc().split('\n'):
logger.debug(l) logger.debug(l)
raise UsageError (message) raise UsageError(message)
return result return result
builtin_actions = {'retire': actions.Retire} builtin_actions = dict(retire=actions.Retire, restore=actions.Restore)
def action(self, name, *args): def action(self, name, *args):
"""Execute a named action.""" """Execute a named action."""
if name in self.actions: if name in self.actions:
action_type = self.actions[name] action_type = self.actions[name]
elif name in self.builtin_actions: elif name in self.builtin_actions:
action_type = self.builtin_actions[name] action_type = self.builtin_actions[name]
else: else:
raise Exception('action "%s" is not supported %s' % (name, ','.join( raise Exception('action "%s" is not supported %s'
self.actions.keys()))) % (name, ','.join(self.actions.keys())))
action = action_type(self.db, self.translator) action = action_type(self.db, self.translator)
return action.execute(*args) return action.execute(*args)
class RoundupDispatcher(SimpleXMLRPCDispatcher): class RoundupDispatcher(SimpleXMLRPCDispatcher):
"""RoundupDispatcher bridges from cgi.client to RoundupInstance. """RoundupDispatcher bridges from cgi.client to RoundupInstance.
It expects user authentication to be done.""" It expects user authentication to be done."""
def __init__(self, db, actions, translator, def __init__(self, db, actions, translator,
allow_none=False, encoding=None): allow_none=False, encoding=None):
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding) SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
 End of changes. 22 change blocks. 
43 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)