Issue Details (XML | Word | Printable)

Key: MODPYTHON-16
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Nicolas Lehuen
Reporter: Nicolas Lehuen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Publisher : classes could be published

Created: 29/Jan/05 09:53 PM   Updated: 22/Oct/05 03:59 PM
Return to search
Component/s: publisher
Affects Version/s: 3.1.3
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide
Suppose this in a published Module :

class index(object):
    def __init__(self,req,name):
        self.buffer ='<html><body><p>Hello, %s !</p></body></html>'%name
    
    def __str__(self):
        return self.buffer

The publisher could notice that the index object is in fact a class, instantiate it and write the result of a str() conversion to the client.

Why should we do this ?
1) we can ;)
2) this could be done by a class definition + a index function which does the job, but this way, we save a function definition.


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton added a comment - 30/Jan/05 09:48 AM
Doing this would require a special case check. At the moment the fact that a class is callable takes precedence and so all it does is create the object. To be able to convert that then back to a string requires an extra step.


Graham Dumpleton added a comment - 30/Jan/05 09:57 AM
Whoops. Sorry, current behaviour is not that callable() takes precedence in this case but conversion of class to a string, which is just yielding a name of the class in appropriate module context. Thus apply_fs_data() needs to understand the type which I see you have done. Since all results of callables have to be converted to strings anyway by str(), then yes it would automatically be converted to custom string if __str__() defined. Thus my comments are redundant.