Message165124
Thanks Martin. I was thinking of adding special-casing inside the rpcproxy class, but the wrapping is pretty clean and clear. Works great in 3.3 Win7-64.
The 2.7 message 'expected a character buffer object' is technically correct*, but opaque, especially to beginners. I actually prefer the 3.x style message, except that 'str' should be expanded to 'string'. (We especially should not say 'character buffer object' until we test for exactly that.)
*My impression is that 2.7 unicode is not a character buffer object, but gets auto converted to str/bytes, which is.
On the technically correct front, bytearray in 2.7 is a character buffer object that .write() can write, but it is not a subclass of basestring. So the widened test in the followup patch
http://hg.python.org/cpython/rev/2993f566c82e
should be widened further.
- if not isinstance(s, basestring):
- raise TypeError('must be str, not ' + type(s).__name__)
+ if not isinstance(s, (basestring, bytearray)):
+ raise TypeError('must be string, not ' + type(s).__name__)
Are there any other 'character buffer' classes that should be included? What *is* the test that 2.7 .write() uses to determine what is such? Can it even be written in Python (rather than C)? |
|
Date |
User |
Action |
Args |
2012-07-09 20:45:14 | terry.reedy | set | recipients:
+ terry.reedy, loewis, orsenthil, roger.serwy, python-dev, Ramchandra Apte, serhiy.storchaka |
2012-07-09 20:45:14 | terry.reedy | set | messageid: <1341866714.49.0.704249949017.issue13532@psf.upfronthosting.co.za> |
2012-07-09 20:45:13 | terry.reedy | link | issue13532 messages |
2012-07-09 20:45:13 | terry.reedy | create | |
|