Made GridFSProxy a bit stricter / safer
This commit is contained in:
parent
32e66b29f4
commit
1849f75ad0
@ -511,6 +511,10 @@ class BinaryField(BaseField):
|
|||||||
raise ValidationError('Binary value is too long')
|
raise ValidationError('Binary value is too long')
|
||||||
|
|
||||||
|
|
||||||
|
class GridFSError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GridFSProxy(object):
|
class GridFSProxy(object):
|
||||||
"""Proxy object to handle writing and reading of files to and from GridFS
|
"""Proxy object to handle writing and reading of files to and from GridFS
|
||||||
"""
|
"""
|
||||||
@ -541,12 +545,18 @@ class GridFSProxy(object):
|
|||||||
self.grid_id = self.newfile._id
|
self.grid_id = self.newfile._id
|
||||||
|
|
||||||
def put(self, file, **kwargs):
|
def put(self, file, **kwargs):
|
||||||
|
if self.grid_id:
|
||||||
|
raise GridFSError('This document alreay has a file. Either delete '
|
||||||
|
'it or call replace to overwrite it')
|
||||||
self.grid_id = self.fs.put(file, **kwargs)
|
self.grid_id = self.fs.put(file, **kwargs)
|
||||||
|
|
||||||
def write(self, string):
|
def write(self, string):
|
||||||
|
if self.grid_id:
|
||||||
if not self.newfile:
|
if not self.newfile:
|
||||||
|
raise GridFSError('This document alreay has a file. Either '
|
||||||
|
'delete it or call replace to overwrite it')
|
||||||
|
else:
|
||||||
self.new_file()
|
self.new_file()
|
||||||
self.grid_id = self.newfile._id
|
|
||||||
self.newfile.write(string)
|
self.newfile.write(string)
|
||||||
|
|
||||||
def writelines(self, lines):
|
def writelines(self, lines):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user