hi friends,
as per the previous question I think I have found my answer,, the structure
of my program is something like this


from twisted.web import resource, static, server

import sys
sys.path.append("/Library/WebServer/Documents/VCalendar/bin/Client2")
import Calendar

account = None
account = []

class HomePage(resource.Resource):
    def render(self,request):
        return"""
    <html>
    <body>
    <form action=/optional method="post">
        User Name <input type="text" name="username"><br/>
        Pass Word <input type="password" name="pswd"><br/>
        ServerAdd <input type="text" name="server"><br/>
        <input type="submit" Value="Submit"><br/>
    </form>
    </body>
    </html>"""


class Optional(resource.Resource):
    def __init__(self):
        resource.Resource.__init__(self)
    def render(self,request):
        self.user = request.args["username"]
        self.pswd = request.args["pswd"]
        self.server = request.args["server"]
        return "<a href = /optional/Calendar> Click this link"
    def getChild(self,path,request):
        return MainCalendar(self.user[0],self.pswd[0],self.server[0])

class MainCalendar(resource.Resource):
    def __init__(self,user,pswd,server):
        resource.Resource.__init__(self)
        if user != None:
            if pswd != None:
                if server != None:
                    self.user = user
                    self.pswd = pswd
                    self.server = server
                    self.CalendarObject =
Calendar.CalendarObject(self.user,self.pswd,self.server)
                    self.putChild('month',month(self.CalendarObject))
                    self.putChild('week',week(self.CalendarObject))
                    self.putChild('day',day(self.CalendarObject))
    def render(self,request):
        return """ <p><a href = /optional/calendar/month> Month View</br>
                    <p><a href = /optional/calendar/week> Month View</br>
                    <p><a href = /optional/calendar/day> Day View"""
    def getChild(self,path,request):
        if path == "/optional/calendar/month":
            return Month(self.CalendarObject)

        elif path == "/optional/calendar/week":
            return week(self.CalendarObject)

        elif path == "/optional/calendar/day":
            return day(self.CalendarObject)


class month(resource.Resource):
    def __init__(self,CalendarObject):
        self.CalendarObject = CalendarObject
    def render(self,request):
        return "Month for %s is good
"%self.CalendarObject.account.session.user
class week(resource.Resource):
    def __init__(self,CalendarObject):
        self.CalendarObject = CalendarObject
    def render(self,request):
        return "Week for %s is
good"%self.CalendarObject.account.session.user
class day(resource.Resource):
    def __init__(self,CalendarObject):
        self.CalendarObject = CalendarObject
    def render(self,request):
        return "Day for %s is good"%self.CalendarObject.account.session.user


if __name__ == "__main__":
    from twisted.internet import reactor
    root = resource.Resource()
    root.putChild('',HomePage())
    root.putChild('optional',Optional())
    site = server.Site(root)
    reactor.listenTCP(8000,site)
    reactor.run()

Is there any fault in the structure of my code, or any error which i cannot
see.
There is one more question,, how can I bind this to my website for ex
www.xyz.com:10

cheers
Thanks to all

On Wed, Jul 23, 2008 at 2:30 PM, Maarten ter Huurne
<[EMAIL PROTECTED]>wrote:

> On Wednesday 23 July 2008, Christopher Armstrong wrote:
> > On Tue, Jul 22, 2008 at 11:26 PM, Maarten ter Huurne
> > <[EMAIL PROTECTED]> wrote:
> >
> > > The information about the user does not belong in any Resource
> > > subclass: a Resource is a page that can be generated for different
> > > users, so it should only contain information that is the same for all
> > > users. Any user specific data should be fetched via the request object.
> >
> > This is totally inaccurate. It's perfectly reasonable to store
> > user-specific data in Resource objects.  "a Resource is a page that
> > can be generated for different users" is either irrelevant or not
> > true, I can't tell which. You can dynamically and return Resources
> > based on which user is making the request.
>
> Ah, I never realized it could be used like that. I thought "resource" was
> intended to be used as "something reachable by URL", with a 1:1 mapping of
> URL path to Resource instance. Sorry for spreading misinformation.
>
> It is still not entirely clear to me what an avatar is though and how it
> relates to resources and authorization.
>
> When accessing a file system, would the "traditional" authorization
> approach
> be to have permission bits on every file indicating whether that file can
> be read or written by a certain users, while the "avatar" approach would be
> to give the user a chroot environment with only files under it that that
> user should have access to?
>
> On Wednesday 23 July 2008, Phil Mayers wrote:
> > Since this is a common mis-conception (one I suffered from and have now
> > disabused myself of) it's worth discussing.
> >
> > If my understanding is correct: twisted.cred uses the concept of an
> > "avatar". Avatars (I think...):
> >
> >   * are protocol objects
> >   * represent the user
> >
> > In twisted.web, the Resource *is* the avatar. In twisted.mail.imap, the
> > Mailbox is the avatar. In twisted.conch, the Shell is the avatar (and so
> > on).
>
> In what way does the avatar represent the user? Is it like a Mars lander
> representing the control team on Earth?
>
> > I found this initially confusing, because in many web frameworks e.g.
> > Zope, where I came from, the objects representing resources are:
> >
> >   * long lived
> >   * the same instances serve >1 HTTP request
> >   * instantiated at process start time
>
> That is the approach I was familiar with from Java servlets and from
> Webware. Since this approach can be mapped onto twisted.web easily I never
> realized it was designed for a different approach.
>
> On Wednesday 23 July 2008, Jean-Paul Calderone wrote:
> > Sounds like you're basically on target.  One area that you didn't talk
> > much about is what the role of the user object is.  It's possible to
> > just examine the user object and then, in your custom Resource, decide
> > what to do based on that examination.  A more powerful approach is to
> > actually delegate those decisions to the user object (and this is why
> > twisted.web.guard makes the user object a Resource).  This removes all
> > checking from your code and just makes the right code for each user
> > execute automatically.  Explicit checking is tedious and error prone.
> > Delegating all authorization decisions to the avatar simplifies the
> > code and makes it less likely that you'll introduce a security issue.
>
> Does this mean the top-level Resource node is the user object, so in fact
> there is a user-specific Resource tree?
>
> Bye,
>                 Maarten
>
> _______________________________________________
> Twisted-web mailing list
> Twisted-web@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>
>
_______________________________________________
Twisted-web mailing list
Twisted-web@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to