Mercurial > p > roundup > code
comparison roundup/xmlrpc.py @ 4371:40d7414592ac
- fix coding style from yesterday
- Allow encoding of parameters as "Binary" (this is encoded as base64 in
xmlrpc). Example:
s.create("file", "name=bla", "type=application/octet-stream",
xmlrpclib.Binary("content=\0"))
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Fri, 09 Apr 2010 09:49:06 +0000 |
| parents | 2188c9de5bdd |
| children | 261c9f913ff7 |
comparison
equal
deleted
inserted
replaced
| 4370:3fd24c10c2bb | 4371:40d7414592ac |
|---|---|
| 8 from roundup.cgi.exceptions import * | 8 from roundup.cgi.exceptions import * |
| 9 from roundup.exceptions import UsageError | 9 from roundup.exceptions import UsageError |
| 10 from roundup.date import Date, Range, Interval | 10 from roundup.date import Date, Range, Interval |
| 11 from roundup import actions | 11 from roundup import actions |
| 12 from SimpleXMLRPCServer import * | 12 from SimpleXMLRPCServer import * |
| 13 from xmlrpclib import Binary | |
| 13 | 14 |
| 14 def translate(value): | 15 def translate(value): |
| 15 """Translate value to becomes valid for XMLRPC transmission.""" | 16 """Translate value to becomes valid for XMLRPC transmission.""" |
| 16 | 17 |
| 17 if isinstance(value, (Date, Range, Interval)): | 18 if isinstance(value, (Date, Range, Interval)): |
| 30 """Construct a list of properties from the given arguments, | 31 """Construct a list of properties from the given arguments, |
| 31 and return them after validation.""" | 32 and return them after validation.""" |
| 32 | 33 |
| 33 props = {} | 34 props = {} |
| 34 for arg in args: | 35 for arg in args: |
| 35 if arg.find('=') == -1: | 36 if isinstance(arg, Binary): |
| 36 raise UsageError, 'argument "%s" not propname=value'%arg | 37 arg = arg.data |
| 37 try : | 38 try : |
| 38 key, value = arg.split('=', 1) | 39 key, value = arg.split('=', 1) |
| 39 except ValueError : | 40 except ValueError : |
| 40 raise UsageError, 'argument "%s" not propname=value'%arg | 41 raise UsageError, 'argument "%s" not propname=value'%arg |
| 41 if isinstance (key, unicode) : | 42 if isinstance(key, unicode): |
| 42 try : | 43 try: |
| 43 key = key.encode ('ascii') | 44 key = key.encode ('ascii') |
| 44 except UnicodeEncodeError: | 45 except UnicodeEncodeError: |
| 45 raise UsageError, 'argument %r is no valid ascii keyword'%key | 46 raise UsageError, 'argument %r is no valid ascii keyword'%key |
| 46 if isinstance (value, unicode) : | 47 if isinstance(value, unicode): |
| 47 value = value.encode ('utf-8') | 48 value = value.encode('utf-8') |
| 48 if value: | 49 if value: |
| 49 try: | 50 try: |
| 50 props[key] = hyperdb.rawToHyperdb(db, cl, itemid, | 51 props[key] = hyperdb.rawToHyperdb(db, cl, itemid, |
| 51 key, value) | 52 key, value) |
| 52 except hyperdb.HyperdbValueError, message: | 53 except hyperdb.HyperdbValueError, message: |
