I am looking at the source code for Python-2.7.6 to figure this out.
In Objects/fileobject.c, line 1052, there is a function called file_read, which I am guessing corresponds to the function read on the file object in Python.
On line 1067 of the same file, I see the following line. Note that bytesrequested is used further down in the function to decide the size of the buffer to allocate for storing the file.
if (!PyArg_ParseTuple(args, "|l:read", &bytesrequested))
It looks like the number of bytes requested is somehow encoded inside args, which has type PyObject*. Thus, the natural place to continue the search is to find out where file_read is called.
However, I cannot find any place in the entire Python source tree (recursive grep) where file_read is actually called, so I cannot continue the trace to find out how bytesrequested is actually computed.
Is file_read somehow called under a different name in a different part of the source tree?
Look at line 2114
file_readis python'sfile.readmethod. Theargsin the C code are the arguments that you pass tofile.read.bytesrequestedis whatever you pass as the argument tofile.read