Mercurial > p > roundup > code
comparison roundup/xmlrpc.py @ 5416:56c9bcdea47f
Python 3 preparation: unicode.
This patch introduces roundup/anypy/strings.py, which has a comment
explaining the string representations generally used and common
functions to handle the required conversions. Places in the code that
explicitly reference the "unicode" type / built-in function are
generally changed to use the new functions (or, in a few places where
those new functions don't seem to fit well, other approaches such as
references to type(u'') or use of the codecs module). This patch does
not generally attempt to address text conversions in any places not
currently referencing the "unicode" type (although
scripts/import_sf.py is made to use binary I/O in places as fixing the
"unicode" reference didn't seem coherent otherwise).
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 09:05:58 +0000 |
| parents | e46ce04d5bbc |
| children | 7f3dfdd6a620 |
comparison
equal
deleted
inserted
replaced
| 5415:2d6a92c3e212 | 5416:56c9bcdea47f |
|---|---|
| 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 roundup.anypy import xmlrpc_ | 12 from roundup.anypy import xmlrpc_ |
| 13 SimpleXMLRPCDispatcher = xmlrpc_.server.SimpleXMLRPCDispatcher | 13 SimpleXMLRPCDispatcher = xmlrpc_.server.SimpleXMLRPCDispatcher |
| 14 Binary = xmlrpc_.client.Binary | 14 Binary = xmlrpc_.client.Binary |
| 15 from roundup.anypy.strings import us2s | |
| 15 from traceback import format_exc | 16 from traceback import format_exc |
| 16 | 17 |
| 17 def translate(value): | 18 def translate(value): |
| 18 """Translate value to becomes valid for XMLRPC transmission.""" | 19 """Translate value to becomes valid for XMLRPC transmission.""" |
| 19 | 20 |
| 39 arg = arg.data | 40 arg = arg.data |
| 40 try : | 41 try : |
| 41 key, value = arg.split('=', 1) | 42 key, value = arg.split('=', 1) |
| 42 except ValueError : | 43 except ValueError : |
| 43 raise UsageError('argument "%s" not propname=value'%arg) | 44 raise UsageError('argument "%s" not propname=value'%arg) |
| 44 if isinstance(key, unicode): | 45 key = us2s(key) |
| 45 try: | 46 value = us2s(value) |
| 46 key = key.encode ('ascii') | |
| 47 except UnicodeEncodeError: | |
| 48 raise UsageError('argument %r is no valid ascii keyword'%key) | |
| 49 if isinstance(value, unicode): | |
| 50 value = value.encode('utf-8') | |
| 51 if value: | 47 if value: |
| 52 try: | 48 try: |
| 53 props[key] = hyperdb.rawToHyperdb(db, cl, itemid, | 49 props[key] = hyperdb.rawToHyperdb(db, cl, itemid, |
| 54 key, value) | 50 key, value) |
| 55 except hyperdb.HyperdbValueError as message: | 51 except hyperdb.HyperdbValueError as message: |
