|
[
Permlink
| « Hide
]
Graham Dumpleton added a comment - 13/Aug/05 10:44 AM
Attached path for this change. Why can't you attache patches when issue created. :-(
Graham Dumpleton made changes - 13/Aug/05 10:44 AM
Checked in Graham's patch and wrote a unit test for it. Everything is OK.
Nicolas Lehuen made changes - 01/Sep/05 06:05 PM
BTW Graham, after I wrote the unit test, I remembered that your patch should not be needed. With the new publisher, the hierarchy traversal is taken care of at the publisher level, and apply_fs_data don't have to worry about it. Indeed, I've reverted your patch on my working copy and ran the new unit test, and mod_python behaved as you want without changing anything to apply_fs_data. Unless I missed something in your enhancement request ?
Note that util.apply_fs_data() can be called directly independent of mod_python.publisher.
Thus it may be redundant within the context of mod_python.publisher but still useful as a separate change when the function is used directly, which is what I had in mind for it. I checked again, you mustn't have it quite right as it definitely fails for me. Eg:
def index(): return "<html></body><p>XOX</p></body></html>" class _Dummy: pass dummy = _Dummy() dummy.__call__ = index When I use URL /~grahamd/mp32/page/dummy I get: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 213, in handler published = publish_object(req, object) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 410, in publish_object return publish_object(req,util.apply_fs_data(object, req.form, req=req)) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 398, in apply_fs_data fc = object.__call__.im_func.func_code AttributeError: 'function' object has no attribute 'im_func' With the fix I suggested, it works. If I import the file into Python command line, can call it okay: >>> import page >>> page.dummy() '<html></body><p>XOX</p></body></html>' So it is valid to do in Python. OK, the unit test I performed was not exactly what you meant :
class Mapping(object): def __init__(self,name): self.name = name def __call__(self,req): return "Called %s"%self.name hierarchy_root = Mapping("root"); hierarchy_root.page1 = Mapping("page1") hierarchy_root.page1.subpage1 = Mapping("subpage1") hierarchy_root.page2 = Mapping("page2") This worked before your patch and still works after, but that wasn't what you meant. I've added a new unit test to match your needs : class Mapping2: pass hierarchy_root_2 = Mapping2() hierarchy_root_2.__call__ = index hierarchy_root_2.page1 = index hierarchy_root_2.page2 = index And indeed, your patch is required for this to work.
Graham Dumpleton made changes - 05/Mar/06 02:20 PM
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||