Graham Dumpleton
grahamd at dscpl.com.au
Mon Apr 3 22:52:55 EDT 2006
Graham Dumpleton wrote .. > Alberto Ruiz wrote .. > > Like I mentioned in earlier threads, this code used to work in a Debian > > system, but now it doesn't work on FreeBSD with modpython 2.7.11. > > I'm getting the following error. > > > > Mod_python error: "PythonHandler mod_python.publisher" > > > > Traceback (most recent call last): > > > > File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", > > line 193, in Dispatch > > result = object(req) > > > > File "/usr/local/lib/python2.4/site-packages/mod_python/publisher.py", > > line 106, in handler > > val = File(field) > > > > File "/usr/local/lib/python2.4/site-packages/mod_python/publisher.py", > > line 322, in __init__ > > for m in field.file.__methods__: > > > > AttributeError: 'file' object has no attribute '__methods__' > > ... > > The problem is nothing to do with your code and there is nothing > you can do in your code to get around it. > > The problem is that in mod_python.publisher it uses: > > class File: > """ Like a file, but also has headers and filename > """ > > def __init__(self, field): > > # steal all the file-like methods > for m in field.file.__methods__: > self.__dict__[m] = getattr(field.file, m) > > __methods__ is from Python 1.5 and therefore will no longer work if you > are using a newer version of Python. > > __methods__ > List of the methods of many built-in object types, e.g., [].__methods__ > yields ['append', 'count', 'index', 'insert', 'pop', 'remove', 'reverse', > 'sort']. > > You might be able to modify mod_python 2.7.X source code to do it > differently. You might be able to use something like: > > # steal all the file-like methods > #for m in field.file.__methods__: > # self.__dict__[m] = getattr(field.file, m) > > for k in field.file.__dict__: > if k[:2] != '__': > v = getattr(field.file, k) > if callable(v): > self.__dict__[k] = v > > The file in mod_python source code that needs to be modified is: > > lib/python/mod_python/publisher.py BTW, if you can't modify the source code, for example it is on an ISPs box, instead add the following at the start of your published code file where you want to use a form upload. Note that this is a mega hack as you are patching mod_python on the fly and change may affect other users if you get it wrong. from mod_python import apache # Don't use import to avoid bug in mod_python. _publisher = apache.import_module("mod_python.publisher") class _MyHackFileClass: """ Like a file, but also has headers and filename """ def __init__(self, field): # steal all the file-like methods #for m in field.file.__methods__: # self.__dict__[m] = getattr(field.file, m) for k in field.file.__dict__: if k[:2] != '__': v = getattr(field.file, k) if callable(v): self.__dict__[k] = v self.headers = field.headers self.filename = field.filename _publisher.File = _MyHackFileClass # Now comes your original code. Graham
|