Fixed #18972 - Used xrange to chunk data #415

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@doda

This makes the code more modern although imo the whole thing could do without checking for length and just do in either case

for offset in xrange(0, length, max_chunk_size):
    self._write(data[offset:offset+max_chunk_size])
    self._flush()
@berkerpeksag berkerpeksag commented on the diff Oct 1, 2012
django/core/servers/basehttp.py
length = len(data)
- if length > 33554432:
- offset = 0
- while offset < length:
- chunk_size = min(33554432, length)
- self._write(data[offset:offset+chunk_size])
+ if length > max_chunk_size:
+ for offset in xrange(0, length, max_chunk_size):
@berkerpeksag
berkerpeksag Oct 1, 2012

I think you should use six to support both Python 2 and Python 3.

from django.utils.six.moves import xrange
@doda
doda Oct 1, 2012

Thanks! Didn't know that Py3 didn't also retain the old name for lazy ranges

@ss41153

What about a small change since in at the end there will be less than max_chunk_size of data?

for offset in xrange(0, length, max_chunk_size):
    chunk_size = min(max_chunk_size, length-offset)
    if chunk_size < max_chunk_size:
        self._write(data[offset:])
    else:
        self._write(data[offset:offset+max_chunk_size])
    self._flush()

Maybe it isn't necessary?

@datagrok datagrok referenced this pull request Feb 23, 2013
Closed

Fixed bug #18972 #782

@timgraham timgraham closed this May 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment