Current py3k stage and next steps

Benoit Boissinot bboissin at gmail.com
Sat Jun 26 02:45:59 CDT 2010


On Fri, Jun 25, 2010 at 11:40 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Renato Cunha <renatoc <at> gmail.com> writes:
>>
>
>> > I don't think so. Why does hg inherit from file in the first place?
>>
>> Hmm, to operate on file-like objects? Consider the only instance where this
>> happens, as defined in url.py:
>>
>> class httpsendfile(file):
>>     def __len__(self):
>>         return os.fstat(self.fileno()).st_size
>
> That's the first time I see someone implement a __len__ method on a file-like
> object. Is there any point in doing so, since file-consuming functions are
> unlikely to call len() on a file-like object?
>

We use it to stream files in HTTP POST.
urllib2 uses len() on the object passed in data= to construct the
Content-length header (but since we already have a work-around to add
the headers manually because of potential overflow, we can probably
get rid of it in httpsendfile).

Then we override send() from HTTPConnection to stream the file when
it's an instance of httpsendfile.

regards,

Benoit


More information about the Mercurial-devel mailing list