diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-05-19 17:43:34 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-05-19 17:43:34 +0200 |
| commit | 38408f8007eae21b9f1cbbcc7f86d4b2042ff86a (patch) | |
| tree | 16cc42e7033bd03077f51ac6868569968e3bc14c /django/http | |
| parent | 822d6d6dabc959532fb2904376580e8947c519f6 (diff) | |
Marked bytestrings with b prefix. Refs #18269
This is a preparation for unicode literals general usage in
Django (Python 3 compatibility).
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 6 | ||||
| -rw-r--r-- | django/http/multipartparser.py | 38 |
2 files changed, 22 insertions, 22 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index 2bad146010..bf848deb38 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -18,7 +18,7 @@ _cookie_encodes_correctly = Cookie.SimpleCookie().value_encode(';') == (';', '"\ # See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256 _tc = Cookie.SimpleCookie() try: - _tc.load('foo:bar=1') + _tc.load(b'foo:bar=1') _cookie_allows_colon_in_names = True except Cookie.CookieError: _cookie_allows_colon_in_names = False @@ -650,8 +650,8 @@ class HttpResponse(object): def _get_content(self): if self.has_header('Content-Encoding'): - return ''.join([str(e) for e in self._container]) - return ''.join([smart_str(e, self._charset) for e in self._container]) + return b''.join([str(e) for e in self._container]) + return b''.join([smart_str(e, self._charset) for e in self._container]) def _set_content(self, value): if hasattr(value, '__iter__'): diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py index d09c8fba86..162c08e38d 100644 --- a/django/http/multipartparser.py +++ b/django/http/multipartparser.py @@ -268,7 +268,7 @@ class LazyStream(object): """ self._producer = producer self._empty = False - self._leftover = '' + self._leftover = b'' self.length = length self.position = 0 self._remaining = length @@ -282,7 +282,7 @@ class LazyStream(object): remaining = (size is not None and [size] or [self._remaining])[0] # do the whole thing in one shot if no limit was provided. if remaining is None: - yield ''.join(self) + yield b''.join(self) return # otherwise do some bookkeeping to return exactly enough @@ -298,7 +298,7 @@ class LazyStream(object): remaining -= len(emitting) yield emitting - out = ''.join(parts()) + out = b''.join(parts()) return out def next(self): @@ -311,7 +311,7 @@ class LazyStream(object): """ if self._leftover: output = self._leftover - self._leftover = '' + self._leftover = b'' else: output = next(self._producer) self._unget_history = [] @@ -341,7 +341,7 @@ class LazyStream(object): return self._update_unget_history(len(bytes)) self.position -= len(bytes) - self._leftover = ''.join([bytes, self._leftover]) + self._leftover = b''.join([bytes, self._leftover]) def _update_unget_history(self, num_bytes): """ @@ -459,7 +459,7 @@ class BoundaryIter(object): if not chunks: raise StopIteration() - chunk = ''.join(chunks) + chunk = b''.join(chunks) boundary = self._find_boundary(chunk, len(chunk) < self._rollback) if boundary: @@ -495,9 +495,9 @@ class BoundaryIter(object): end = index next = index + len(self._boundary) # backup over CRLF - if data[max(0,end-1)] == '\n': + if data[max(0,end-1)] == b'\n': end -= 1 - if data[max(0,end-1)] == '\r': + if data[max(0,end-1)] == b'\r': end -= 1 return end, next @@ -531,7 +531,7 @@ def parse_boundary_stream(stream, max_header_size): # 'find' returns the top of these four bytes, so we'll # need to munch them later to prevent them from polluting # the payload. - header_end = chunk.find('\r\n\r\n') + header_end = chunk.find(b'\r\n\r\n') def _parse_header(line): main_value_pair, params = parse_header(line) @@ -557,7 +557,7 @@ def parse_boundary_stream(stream, max_header_size): outdict = {} # Eliminate blank lines - for line in header.split('\r\n'): + for line in header.split(b'\r\n'): # This terminology ("main value" and "dictionary of # parameters") is from the Python docs. try: @@ -580,7 +580,7 @@ def parse_boundary_stream(stream, max_header_size): class Parser(object): def __init__(self, stream, boundary): self._stream = stream - self._separator = '--' + boundary + self._separator = b'--' + boundary def __iter__(self): boundarystream = InterBoundaryIter(self._stream, self._separator) @@ -590,27 +590,27 @@ class Parser(object): def parse_header(line): """ Parse the header into a key-value. """ - plist = _parse_header_params(';' + line) + plist = _parse_header_params(b';' + line) key = plist.pop(0).lower() pdict = {} for p in plist: - i = p.find('=') + i = p.find(b'=') if i >= 0: name = p[:i].strip().lower() value = p[i+1:].strip() - if len(value) >= 2 and value[0] == value[-1] == '"': + if len(value) >= 2 and value[0] == value[-1] == b'"': value = value[1:-1] - value = value.replace('\\\\', '\\').replace('\\"', '"') + value = value.replace(b'\\\\', b'\\').replace(b'\\"', b'"') pdict[name] = value return key, pdict def _parse_header_params(s): plist = [] - while s[:1] == ';': + while s[:1] == b';': s = s[1:] - end = s.find(';') - while end > 0 and s.count('"', 0, end) % 2: - end = s.find(';', end + 1) + end = s.find(b';') + while end > 0 and s.count(b'"', 0, end) % 2: + end = s.find(b';', end + 1) if end < 0: end = len(s) f = s[:end] |
