mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
magic-removal: Merged to [2675]
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2676 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
737a317a23
commit
15e368eed6
@ -154,10 +154,10 @@ class HttpResponse(object):
|
|||||||
if not mimetype:
|
if not mimetype:
|
||||||
mimetype = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, settings.DEFAULT_CHARSET)
|
mimetype = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, settings.DEFAULT_CHARSET)
|
||||||
if hasattr(content, '__iter__'):
|
if hasattr(content, '__iter__'):
|
||||||
self.iterator = content
|
self._iterator = content
|
||||||
self._is_string = False
|
self._is_string = False
|
||||||
else:
|
else:
|
||||||
self.iterator = [content]
|
self._iterator = [content]
|
||||||
self._is_string = True
|
self._is_string = True
|
||||||
self.headers = {'Content-Type': mimetype}
|
self.headers = {'Content-Type': mimetype}
|
||||||
self.cookies = SimpleCookie()
|
self.cookies = SimpleCookie()
|
||||||
@ -203,23 +203,32 @@ class HttpResponse(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_content(self):
|
def _get_content(self):
|
||||||
content = ''.join(self.iterator)
|
content = ''.join(self._iterator)
|
||||||
if isinstance(content, unicode):
|
if isinstance(content, unicode):
|
||||||
content = content.encode(self._charset)
|
content = content.encode(self._charset)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def _set_content(self, value):
|
def _set_content(self, value):
|
||||||
self.iterator = [value]
|
self._iterator = [value]
|
||||||
self._is_string = True
|
self._is_string = True
|
||||||
|
|
||||||
content = property(_get_content, _set_content)
|
content = property(_get_content, _set_content)
|
||||||
|
|
||||||
|
def _get_iterator(self):
|
||||||
|
"Output iterator. Converts data into client charset if necessary."
|
||||||
|
for chunk in self._iterator:
|
||||||
|
if isinstance(chunk, unicode):
|
||||||
|
chunk = chunk.encode(self._charset)
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
iterator = property(_get_iterator)
|
||||||
|
|
||||||
# The remaining methods partially implement the file-like object interface.
|
# The remaining methods partially implement the file-like object interface.
|
||||||
# See http://docs.python.org/lib/bltin-file-objects.html
|
# See http://docs.python.org/lib/bltin-file-objects.html
|
||||||
def write(self, content):
|
def write(self, content):
|
||||||
if not self._is_string:
|
if not self._is_string:
|
||||||
raise Exception, "This %s instance is not writable" % self.__class__
|
raise Exception, "This %s instance is not writable" % self.__class__
|
||||||
self.iterator.append(content)
|
self._iterator.append(content)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
@ -227,7 +236,7 @@ class HttpResponse(object):
|
|||||||
def tell(self):
|
def tell(self):
|
||||||
if not self._is_string:
|
if not self._is_string:
|
||||||
raise Exception, "This %s instance cannot tell its position" % self.__class__
|
raise Exception, "This %s instance cannot tell its position" % self.__class__
|
||||||
return sum([len(chunk) for chunk in self.iterator])
|
return sum([len(chunk) for chunk in self._iterator])
|
||||||
|
|
||||||
class HttpResponseRedirect(HttpResponse):
|
class HttpResponseRedirect(HttpResponse):
|
||||||
def __init__(self, redirect_to):
|
def __init__(self, redirect_to):
|
||||||
|
@ -655,14 +655,14 @@ returns an empty string.
|
|||||||
get_FOO_size()
|
get_FOO_size()
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
For every ``FileField``, the object will have a ``get_FOO_filename()`` method,
|
For every ``FileField``, the object will have a ``get_FOO_size()`` method,
|
||||||
where ``FOO`` is the name of the field. This returns the size of the file, in
|
where ``FOO`` is the name of the field. This returns the size of the file, in
|
||||||
bytes. (Behind the scenes, it uses ``os.path.getsize``.)
|
bytes. (Behind the scenes, it uses ``os.path.getsize``.)
|
||||||
|
|
||||||
save_FOO_file(filename, raw_contents)
|
save_FOO_file(filename, raw_contents)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
For every ``FileField``, the object will have a ``get_FOO_filename()`` method,
|
For every ``FileField``, the object will have a ``save_FOO_file()`` method,
|
||||||
where ``FOO`` is the name of the field. This saves the given file to the
|
where ``FOO`` is the name of the field. This saves the given file to the
|
||||||
filesystem, using the given filename. If a file with the given filename already
|
filesystem, using the given filename. If a file with the given filename already
|
||||||
exists, Django adds an underscore to the end of the filename (but before the
|
exists, Django adds an underscore to the end of the filename (but before the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user