

def save_upload(uploaded, filename, raw_data):
    '\n    raw_data: if True, uploaded is an HttpRequest object with the file being\n              the raw post data\n              if False, uploaded has been submitted via the basic form\n              submission and is a regular Django UploadedFile in request.FILES\n    '
    try:
        from io import FileIO, BufferedWriter
        with BufferedWriter(FileIO(filename, 'wb')) as dest:
            if raw_data:
                if isinstance(uploaded, basestring):
                    dest.write(uploaded)
                else:
                    foo = uploaded.read(1024)
                    while foo:
                        dest.write(foo)
                        foo = uploaded.read(1024)
            else:
                for c in uploaded.chunks():
                    dest.write(c)
            return True
    except IOError:
        pass
    return False

dataset/ETHPy150Open treeio/treeio/treeio/core/views.py save_upload/original