Ticket #8204: filestorage.2.diff
File filestorage.2.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/core/files/base.py
4 4 5 5 try: 6 6 from cStringIO import StringIO 7 c_string_io = True 7 8 except ImportError: 8 9 from StringIO import StringIO 10 c_string_io = False 9 11 10 12 class File(object): 11 13 DEFAULT_CHUNK_SIZE = 64 * 2**10 … … 151 153 """ 152 154 A File-like object that takes just raw content, rather than an actual file. 153 155 """ 154 def __init__(self, content): 155 self.file = StringIO(content or '') 156 def __init__(self, content = None): 157 if c_string_io: 158 if content: 159 self.file = StringIO(content) 160 self._mode = "r" 161 else: 162 self.file = StringIO() 163 self._mode = "w" 164 else: 165 self.file = StringIO(content or '') 166 self._mode = "w" 156 167 self.size = len(content or '') 157 168 self.file.seek(0) 169 self._name = "contentfile" 158 170 self._closed = False 159 171 160 172 def __str__(self): … … 163 175 def __nonzero__(self): 164 176 return True 165 177 178 def _get_size(self): 179 old_position = self.file.tell() 180 self.file.seek(0, 2) 181 size = self.file.tell() 182 self.file.seek(old_position) 183 return size 184 185 def _set_size(self, value): pass 186 187 size = property(_get_size, _set_size) 188 166 189 def open(self, mode=None): 167 190 if self._closed: 168 191 self._closed = False