[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
>