mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Marked bytestrings with b prefix. Refs #18269
This is a preparation for unicode literals general usage in Django (Python 3 compatibility).
This commit is contained in:
@@ -22,7 +22,7 @@ def csrf(request):
|
||||
# In order to be able to provide debugging info in the
|
||||
# case of misconfiguration, we use a sentinel value
|
||||
# instead of returning an empty dict.
|
||||
return 'NOTPROVIDED'
|
||||
return b'NOTPROVIDED'
|
||||
else:
|
||||
return token
|
||||
_get_val = lazy(_get_val, str)
|
||||
|
||||
@@ -125,7 +125,7 @@ class ContentFile(File):
|
||||
A File-like object that takes just raw content, rather than an actual file.
|
||||
"""
|
||||
def __init__(self, content, name=None):
|
||||
content = content or ''
|
||||
content = content or b''
|
||||
super(ContentFile, self).__init__(BytesIO(content), name=name)
|
||||
self.size = len(content)
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ class UploadedFile(File):
|
||||
self.charset = charset
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s: %s (%s)>" % (
|
||||
self.__class__.__name__, smart_str(self.name), self.content_type)
|
||||
return smart_str("<%s: %s (%s)>" % (
|
||||
self.__class__.__name__, self.name, self.content_type))
|
||||
|
||||
def _get_name(self):
|
||||
return self._name
|
||||
|
||||
@@ -78,14 +78,14 @@ class LimitedStream(object):
|
||||
def __init__(self, stream, limit, buf_size=64 * 1024 * 1024):
|
||||
self.stream = stream
|
||||
self.remaining = limit
|
||||
self.buffer = ''
|
||||
self.buffer = b''
|
||||
self.buf_size = buf_size
|
||||
|
||||
def _read_limited(self, size=None):
|
||||
if size is None or size > self.remaining:
|
||||
size = self.remaining
|
||||
if size == 0:
|
||||
return ''
|
||||
return b''
|
||||
result = self.stream.read(size)
|
||||
self.remaining -= len(result)
|
||||
return result
|
||||
@@ -93,17 +93,17 @@ class LimitedStream(object):
|
||||
def read(self, size=None):
|
||||
if size is None:
|
||||
result = self.buffer + self._read_limited()
|
||||
self.buffer = ''
|
||||
self.buffer = b''
|
||||
elif size < len(self.buffer):
|
||||
result = self.buffer[:size]
|
||||
self.buffer = self.buffer[size:]
|
||||
else: # size >= len(self.buffer)
|
||||
result = self.buffer + self._read_limited(size - len(self.buffer))
|
||||
self.buffer = ''
|
||||
self.buffer = b''
|
||||
return result
|
||||
|
||||
def readline(self, size=None):
|
||||
while '\n' not in self.buffer and \
|
||||
while b'\n' not in self.buffer and \
|
||||
(size is None or len(self.buffer) < size):
|
||||
if size:
|
||||
# since size is not None here, len(self.buffer) < size
|
||||
|
||||
Reference in New Issue
Block a user