MCPcopy
hub / github.com/django/django / ContentFile

Class ContentFile

django/core/files/base.py:124–146  ·  view source on GitHub ↗

A File-like object that takes just raw content, rather than an actual file.

Source from the content-addressed store, hash-verified

122
123
124class 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
149def endswith_cr(line):

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…