Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: socket.makefile raises ValueError when mode = 'rt' (http://www.velocityreviews.com/forums/t956340-re-socket-makefile-raises-valueerror-when-mode-rt.html)

Antoon Pardon 01-09-2013 02:14 PM

Re: socket.makefile raises ValueError when mode = 'rt'
 
Op 01/09/13 14:54, Dave Angel schreef:
> On 01/09/2013 08:22 AM, Antoon Pardon wrote:
>> This is using python 3.2.

....
>> But the documentation states:
>> socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None,
>> newline=None)
>> Return a file object associated with the socket. The exact returned
>> type depends on the arguments given to makefile(). These arguments are
>> interpreted the same way as by the built-in open() function.
>>
>> And since 't' is allowed in the mode of the built-in open() function I
>> would consider this a bug.
>> Unless I am missing something?

> I believe that 't' was a new addition to mode, for Python 3.x So
> perhaps the socket library hasn't kept consistent with it.
>
> I don't really know the socket library. Does it even support text
> mode? Does that make sense? Remember that text mode means a different
> thing in 3.x than it did in 2.x

As far as I understand the code, it does support text. This is part of
the makefile method.

def makefile(self, mode="r", buffering=None, *,
encoding=None, errors=None, newline=None):

for c in mode:
if c not in {"r", "w", "b"}:
raise ValueError("invalid mode %r (only r, w, b allowed)")
writing = "w" in mode
reading = "r" in mode or not writing
assert reading or writing
binary = "b" in mode
...
if binary:
return buffer
text = io.TextIOWrapper(buffer, encoding, errors, newline)
text.mode = mode
return text

So it seems that if the mode is not binary an io.TextIOWrapper is
returned. That indicates to me that
text mode is supported.

--
Antoon Pardon


All times are GMT. The time now is 09:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57