1234567891011121314151617181920212223 |
- def _save_large_file(self, os_path, content, format):
- """Save content of a generic file."""
- if format not in {'text', 'base64'}:
- raise web.HTTPError(
- 400,
- "Must specify format of file contents as 'text' or 'base64'",
- )
- try:
- if format == 'text':
- bcontent = content.encode('utf8')
- else:
- b64_bytes = content.encode('ascii')
- bcontent = base64.b64decode(b64_bytes)
- except Exception as e:
- raise web.HTTPError(
- 400, u'Encoding error saving %s: %s' % (os_path, e)
- )
- with self.perm_to_403(os_path):
- if os.path.islink(os_path):
- os_path = os.path.join(os.path.dirname(os_path), os.readlink(os_path))
- with io.open(os_path, 'ab') as f:
- f.write(bcontent)
|