bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.33k stars 1.46k forks source link

Please explain #1347

Closed valq7711 closed 2 years ago

valq7711 commented 2 years ago

Hi guys! Could anyone explain the logic behind the following piece of code: https://github.com/bottlepy/bottle/blob/71bb933649ba009cd537c2e973519d6e024c02a2/bottle.py#L1333-L1339 As I see buff[maxread:] always returns an empty string, since buff length cannot be greater than maxread, no?

Thanks in advance!

defnull commented 2 years ago

Yeah, that part looks strange and can probably be simplified.

while maxread > 0:
    buff = read(min(maxread, bufsize))
    if not buff: raise err
    yield buff
    maxread -= len(buff)
valq7711 commented 2 years ago

Yes, this looks much better ;)

Irtiza90 commented 2 years ago

Just adding a tiny tiny bit to @defnull's answer, don't even know if this helps much but i think this is more read-able

while maxread > 0:
    buff = read(min(maxread, bufsize))
    if not buff: 
        raise err
    # else
    yield buff
    maxread -= len(buff)
Irtiza90 commented 2 years ago

also @valq7711 please close the issue, if you have gotten your answer