A File-like object that takes just raw content, rather than an actual file.
| 122 | |
| 123 | |
| 124 | class ContentFile(File): |
| 125 | """ |
| 126 | A File-like object that takes just raw content, rather than an actual file. |
| 127 | """ |
| 128 | |
| 129 | def __init__(self, content, name=None): |
| 130 | stream_class = StringIO if isinstance(content, str) else BytesIO |
| 131 | super().__init__(stream_class(content), name=name) |
| 132 | self.size = len(content) |
| 133 | |
| 134 | def __str__(self): |
| 135 | return "Raw content" |
| 136 | |
| 137 | def open(self, mode=None): |
| 138 | self.seek(0) |
| 139 | return self |
| 140 | |
| 141 | def close(self): |
| 142 | pass |
| 143 | |
| 144 | def write(self, data): |
| 145 | self.__dict__.pop("size", None) # Clear the computed size. |
| 146 | return self.file.write(data) |
| 147 | |
| 148 | |
| 149 | def endswith_cr(line): |
no outgoing calls
searching dependent graphs…