Analyzing Python Code: Modulus Operator

Posted by Bhubhu Hbuhdbus on Stack Overflow See other posts from Stack Overflow or by Bhubhu Hbuhdbus
Published on 2012-06-23T21:06:51Z Indexed on 2012/06/23 21:16 UTC
Read the original article Hit count: 234

Filed under:
|

I was looking at some code in Python (I know nothing about Python) and I came across this portion:

def do_req(body):
    global host, req
    data = ""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, 80))
    s.sendall(req % (len(body), body))
    tmpdata = s.recv(8192)
    while len(tmpdata) > 0:
        data += tmpdata
        tmpdata = s.recv(8192)
    s.close()
    return data

This is then called later on with body of huge size, as in over 500,000 bytes. This is sent to an Apache server that has the max request size on the default 8190 bytes.

My question is what is happening at the "s.sendall()" part? Obviously the entire body cannot be sent at once and I'm guessing it is reduced by way of the modulus operator. I don't know how it works in Python, though. Can anyone explain? Thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about networking