Python 2.7 在ZPublisher.HTTPRequest.FileUpload上使用is_zipfile

Python 2.7 在ZPublisher.HTTPRequest.FileUpload上使用is_zipfile,python-2.7,plone,zope,Python 2.7,Plone,Zope,我试图检查上传的文件是否是有效的zip文件,但似乎is_zipfile调用了read方法,该方法将文件字符串设置为“”,因此后续的read调用返回零长度字符串 我正试图复制该文件以获得第二个一次性版本,但复制只是一个浅拷贝,而deepcopy返回一个错误TypeError:object.\uu新的\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu(方法包装器)不安全,请使用方法包装器。\ 我可以将文件字符串保存到一个变量

我试图检查上传的文件是否是有效的zip文件,但似乎is_zipfile调用了read方法,该方法将文件字符串设置为“”,因此后续的read调用返回零长度字符串

我正试图复制该文件以获得第二个一次性版本,但复制只是一个浅拷贝,而deepcopy返回一个错误
TypeError:object.\uu新的\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu(方法包装器)不安全,请使用方法包装器。\

我可以将文件字符串保存到一个变量中,然后调用is_zipfile方法,但返回False,因为该文件现在实际上是一个空文件

我如何复制FileUpload对象,或者调用is_zipefile而不调用read方法,或者如何验证该对象是zip文件而不在过程中销毁它

fileToImport = REQUEST.get('sourceFile', None)
if is_zipfile(fileToImport):
    file_string = fileToImport.read()
    self.importDesignFromZip(file_string, replace=replace)
else:
    xmlstring = fileToImport.read()
    self.importDesignFromXML(xmlstring, replace=replace)
干杯 迈克尔

Plone-4.1.3 Zope 2.13.10
Python 2.7.3

返回到文件的开头:

iszip = is_zipfile(fileToImport)
fileToImport.seek(0)
data = fileToImport.read()

if iszip:
    self.importDesignFromZip(data, replace=replace)
else:
    self.importDesignFromXML(data, replace=replace)

查找回文件的开头:

iszip = is_zipfile(fileToImport)
fileToImport.seek(0)
data = fileToImport.read()

if iszip:
    self.importDesignFromZip(data, replace=replace)
else:
    self.importDesignFromXML(data, replace=replace)