[mod_python] upload file?

John Mudd JohnMudd at mindspring.com
Fri May 7 04:23:33 EST 2004


I added your patch but it didn't seem to change the results.  I was able
to check the type of the object though.  Here are the results of my
debug code.

item=Field('inputJar', 'zopeIntro.txt')
item.type='text/plain'
item.type_options={}
type(item)=<type 'instance'>

It's interesting.  I am able to execute item.read().  But it returns
'zopeIntro.txt', the name of the file, not the contents.

John


On Thu, 2004-05-06 at 13:49, Maxime Yve wrote:
> Hi,
> 
>  
> 
> I have the same problem with mod_python 3.1.3 on windows:
> 
> This comes from the __getitem__ method of FieldStorage
> 
>  
> 
> Indeed => :
> 
> On windows
> 
>  
> 
> >>> import tempfile
> 
> >>> glop = tempfile.TemporaryFile('w+b')
> 
> >>> type(glop)
> 
>       <type 'instance'>
> 
>  
> 
> On Unix :
> 
> >>> import tempfile
> 
> >>> glop = tempfile.TemporaryFile('w+b')
> 
> >>> type(glop)
> 
>       <type 'file'>
> 
>  
> 
> And isinstance(item.file, FileType) return false on Windows, this
> cause the bug on __getitem__
> 
>  
> 
> To correct temporary this problem (I'm not active on the community and
> I can't correct the mistake)
> 
> You can do this monkey hook on your own file before using
> FieldStorage:
> 
>  
> 
> from types import *
> 
> from mod_python.util import StringField
> 
>  
> 
>  
> 
> # patch bug on windows for mod_python 3.1.3
> 
> def patch_getitem(self, key):
> 
>       """Dictionary style indexing."""
> 
>       if self.list is None:
> 
>             raise TypeError, "not indexable"
> 
>       found = []
> 
>       for item in self.list:
> 
>             if item.name == key:
> 
>                   if isinstance(item.file, FileType) or
> isinstance(item.file, InstanceType):
> 
>                         found.append(item)
> 
>                   else:
> 
>                         found.append(StringField(item.value))
> 
>       if not found:
> 
>             raise KeyError, key
> 
>       if len(found) == 1:
> 
>             return found[0]
> 
>       else:
> 
>             return found
> 
> util.FieldStorage.__getitem__ = patch_getitem
> 
>  
> 
> Max
> 
>  
> 
> -----Original Message-----
> From: mod_python-bounces at modpython.org
> [mailto:mod_python-bounces at modpython.org] On Behalf Of John Mudd
> Sent: jeudi 6 mai 2004 19:21
> To: mod_python at modpython.org
> Subject: [mod_python] upload file?
> 
>  
> 
> (Sorry if you see this msg twice.  I submitted this earlier today by
> under a non-member email address.)
> 
>  
> 
> I'm trying to upload a file.  I specified a "file" type input field in
> my HTML, it displays as expected with the "Browse..." button, I'm able
> to select a file but...
> 
>  
> 
> When I look in the FieldStorage dictionary for the field I only get a
> String type field that is the file name.  I was expecting a "Field"
> type object that would provide access to the file name and contents.
> 
>  
> 
> What am I missing? 
> 
>  
> 
> John
> 
> _______________________________________________
> 
> Mod_python mailing list
> 
> Mod_python at modpython.org
> 
> http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> 



More information about the Mod_python mailing list