Пример #1
0
def getDummyFileForContent(name, ctype):
    # make output file like and add an headers dict, so the contenttype
    # is properly set in the headers
    output = StringIO()
    output.headers = {'content-type': ctype}
    file_ = File(name, name, output)
    alsoProvides(file_, ICookedFile)
    return file_
def getDummyFileForContent(name, ctype):
    # make output file like and add an headers dict, so the contenttype
    # is properly set in the headers
    output = StringIO()
    output.headers = {'content-type': ctype}
    file_ = File(name, name, output)
    alsoProvides(file_, ICookedFile)
    return file_
Пример #3
0
Файл: mdb.py Проект: louika/vivi
 def get_body(self, mdb_id):
     response = self._request('GET /mdb/%s/file' % mdb_id)
     response = response.text
     # Yep, they're sending megabytes of data in an XML envelope; let's not
     # put that through an XML parser without a really good reason.
     body = XML_TAGS.sub('', response)
     body = base64.b64decode(body)
     # Cannot use cStringIO since we need to set additional attributes.
     result = StringIO(body)
     result.filename = FILE_NAME_ATTRIBUTE.search(response).group(1)
     result.mdb_id = mdb_id
     result.headers = {'content-type': 'image/%s' % os.path.splitext(
         result.filename)[1].lower()}
     return result