[gen] When duplicating a file via appy.fields.file::FileInfo.replicateFile, the source file can be binary data in a str instead of an opened file handler.

This commit is contained in:
Gaetan Delannay 2014-10-01 16:21:12 +02:00
parent ae69509354
commit a671094167
3 changed files with 6 additions and 1 deletions

View file

@ -16,6 +16,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import time, os.path, mimetypes, shutil import time, os.path, mimetypes, shutil
from cStringIO import StringIO
from appy import Object from appy import Object
from appy.fields import Field from appy.fields import Field
from appy.px import Px from appy.px import Px
@ -123,8 +124,10 @@ class FileInfo:
def replicateFile(self, src, dest): def replicateFile(self, src, dest):
'''p_src and p_dest are open file handlers. This method copies content '''p_src and p_dest are open file handlers. This method copies content
of p_src to p_dest and returns the file size.''' of p_src to p_dest and returns the file size. Note that p_src can
also be binary data in a string.'''
size = 0 size = 0
if isinstance(src, str): src = StringIO(src)
while True: while True:
chunk = src.read(self.BYTES) chunk = src.read(self.BYTES)
if not chunk: break if not chunk: break

View file

@ -1203,6 +1203,7 @@ class ToolMixin(BaseMixin):
user = tool.user user = tool.user
else: else:
user = tool.search1('User', noSecurity=True, login=login) user = tool.search1('User', noSecurity=True, login=login)
if not user: return login
return user.getTitle(normalized=normalized) return user.getTitle(normalized=normalized)
def tempFile(self): def tempFile(self):

View file

@ -249,6 +249,7 @@ class XmlParser(ContentHandler, ErrorHandler):
from cStringIO import StringIO from cStringIO import StringIO
except ImportError: except ImportError:
from StringIO import StringIO from StringIO import StringIO
self._xml = xml
self.parser.setContentHandler(self) self.parser.setContentHandler(self)
self.parser.setErrorHandler(self) self.parser.setErrorHandler(self)
self.parser.setFeature(feature_external_ges, False) self.parser.setFeature(feature_external_ges, False)