hi, I have developed some twisted.web application. It connects to the other server (CalDav) and then it displays back using twisted.web. My problem is when a user logs into my website which is made using twisted.web there is some data fetched from CALDAV server. When another user logs into my website, even his data is downloaded from CalDav server but this data overwrites the data of previous server. I think I am not able to fork the process on each request. This is my just guess. The Code is given below from twisted.web import resource, static, server import vobject import calendarWebUtilities import Calendar import datetime import re,calendar import Month import Week import Day import socket class HomePage(resource.Resource): def render(self,request): return""" <html> <head> <title>VCalendar</title> </head> <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) self.CalendarData = {} self.account = {} def render(self,request): user = request.args["username"] pswd = request.args["pswd"] server = request.args["server"] if user != None: if pswd != None: if server != None: CalendarSource = None CalendarSource = Calendar.CalendarObject(user[0],pswd[0],server[0]) todayDate = datetime.datetime.now() start = datetime.datetime((todayDate.year-1),01,01,00,00) end = datetime.datetime((todayDate.year+1),12,31,23,59,59) self.CalendarData['value'] = CalendarSource.readCalendarComponent(start,end) self.account['value'] = CalendarSource self.index = 1 request.redirect("/optional/Calendar") return " " def getChild(self,path,request): return MainCalendar(self.index,self.CalendarData,self.account) class MainCalendar(resource.Resource): def __init__(self,index,CalendarData,account): resource.Resource.__init__(self) self.index = index self.CalendarData = CalendarData self.account = account self.putChild('Add',AddCalendarComponent(self.CalendarData,self.account)) def render(self,request): global Calendarata global account if request.path == "/optional/Calendar" : request.redirect("/optional/Calendar/Month") return " " def getChild(self,path,request): if request.path == "/optional/Calendar/Month": return Month.month(self.CalendarData,self.index) elif request.path == "/optional/Calendar/Week": return Week.Week(self.CalendarData,self.index) elif request.path == "/optional/Calendar/Day": return Day.Day(self.CalendarData,self.index) class AddCalendarComponent(resource.Resource): def __init__(self,CalendarData,account): resource.Resource.__init__(self) self.CalendarData = CalendarData self.account = account def render (self,request): #if request.args != None: queryString = len(request.args) if queryString !=0: try : summary1 = request.args['summary'] location1 = request.args['location'] startDate1 = request.args['startDate'] endDate1 = request.args['endDate'] CalendarSource = self.account['value'] event = CalendarSource.convertToProperFormatAndAddToCalendar(summary1,location1,startDate1,endDate1) (self.CalendarData['value']).append(event) #CalendarData = {} #print "New Data Created" #print NewCalendar #CalendarData['value'] = NewCalendar request.redirect("/optional/Calendar") return " " except KeyError: request.args = {} request.redirect('/optional/Calendar/Month/Add') else: return""" <html> <head> </head> <body> <form action="/optional/Calendar/Add" method="post"> Summary = <INPUT type="text" name="summary"></br> Location = <input type="text" name="location"></br> Start Date = <input type="text" name="startDate">Should Be in format year/MM/date/HH/MM</br> End Date = <input type="text" name="endDate">Should Be in format year/MM/date/HH/MM</br> <input type="submit"> </form> </body> </html> """ 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() I can guess there should be some method by which I can fork the root for different request,, Please help. Thanks
On Sat, Aug 16, 2008 at 12:24 AM, arun chhetri <uhcops@gmail.com> wrote:
hi, I have developed some twisted.web application. It connects to the other server (CalDav) and then it displays back using twisted.web. My problem is when a user logs into my website which is made using twisted.web there is some data fetched from CALDAV server. When another user logs into my website, even his data is downloaded from CalDav server but this data overwrites the data of previous server. I think I am not able to fork the process on each request. This is my just guess.
The Code is given below
from twisted.web import resource, static, server import vobject import calendarWebUtilities import Calendar import datetime import re,calendar import Month import Week import Day import socket
class HomePage(resource.Resource): def render(self,request): return""" <html> <head> <title>VCalendar</title> </head> <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) self.CalendarData = {} self.account = {} def render(self,request): user = request.args["username"] pswd = request.args["pswd"] server = request.args["server"] if user != None: if pswd != None: if server != None: CalendarSource = None CalendarSource = Calendar.CalendarObject(user[0],pswd[0],server[0]) todayDate = datetime.datetime.now() start = datetime.datetime((todayDate.year-1),01,01,00,00) end = datetime.datetime((todayDate.year+1),12,31,23,59,59) self.CalendarData['value'] = CalendarSource.readCalendarComponent(start,end) self.account['value'] = CalendarSource self.index = 1 request.redirect("/optional/Calendar") return " "
def getChild(self,path,request): return MainCalendar(self.index,self.CalendarData,self.account)
class MainCalendar(resource.Resource): def __init__(self,index,CalendarData,account): resource.Resource.__init__(self) self.index = index self.CalendarData = CalendarData self.account = account
self.putChild('Add',AddCalendarComponent(self.CalendarData,self.account))
def render(self,request): global Calendarata global account if request.path == "/optional/Calendar" : request.redirect("/optional/Calendar/Month") return " "
def getChild(self,path,request): if request.path == "/optional/Calendar/Month": return Month.month(self.CalendarData,self.index) elif request.path == "/optional/Calendar/Week": return Week.Week(self.CalendarData,self.index) elif request.path == "/optional/Calendar/Day": return Day.Day(self.CalendarData,self.index)
class AddCalendarComponent(resource.Resource): def __init__(self,CalendarData,account): resource.Resource.__init__(self) self.CalendarData = CalendarData self.account = account
def render (self,request): #if request.args != None: queryString = len(request.args) if queryString !=0: try : summary1 = request.args['summary'] location1 = request.args['location'] startDate1 = request.args['startDate'] endDate1 = request.args['endDate'] CalendarSource = self.account['value'] event = CalendarSource.convertToProperFormatAndAddToCalendar(summary1,location1,startDate1,endDate1) (self.CalendarData['value']).append(event) #CalendarData = {} #print "New Data Created" #print NewCalendar #CalendarData['value'] = NewCalendar request.redirect("/optional/Calendar") return " " except KeyError: request.args = {} request.redirect('/optional/Calendar/Month/Add') else: return""" <html> <head> </head> <body>
<form action="/optional/Calendar/Add" method="post"> Summary = <INPUT type="text" name="summary"></br> Location = <input type="text" name="location"></br> Start Date = <input type="text" name="startDate">Should Be in format year/MM/date/HH/MM</br> End Date = <input type="text" name="endDate">Should Be in format year/MM/date/HH/MM</br> <input type="submit"> </form> </body> </html> """
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()
I can guess there should be some method by which I can fork the root for different request,, Please help.
Thanks
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Try using a factory for your session storage instead of storing it in the actually resource, that way you will be able to access your session information from the resources without overriding it on every request. Take a look at twisted.internet.protocol.ServerFactory. HTH G
So, does this means that twisted.web can only handle one request at a time,,,,, why It should do that. thanks On Sat, Aug 16, 2008 at 4:46 PM, Graeme Glass <graemeglass@gmail.com> wrote:
On Sat, Aug 16, 2008 at 12:24 AM, arun chhetri <uhcops@gmail.com> wrote:
hi, I have developed some twisted.web application. It connects to the other server (CalDav) and then it displays back using twisted.web. My problem is when a user logs into my website which is made using twisted.web there is some data fetched from CALDAV server. When another user logs into my website, even his data is downloaded from CalDav server but this data overwrites the data of previous server. I think I am not able to fork the process on each request. This is my just guess.
The Code is given below
from twisted.web import resource, static, server import vobject import calendarWebUtilities import Calendar import datetime import re,calendar import Month import Week import Day import socket
class HomePage(resource.Resource): def render(self,request): return""" <html> <head> <title>VCalendar</title> </head> <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) self.CalendarData = {} self.account = {} def render(self,request): user = request.args["username"] pswd = request.args["pswd"] server = request.args["server"] if user != None: if pswd != None: if server != None: CalendarSource = None CalendarSource = Calendar.CalendarObject(user[0],pswd[0],server[0]) todayDate = datetime.datetime.now() start = datetime.datetime((todayDate.year-1),01,01,00,00) end = datetime.datetime((todayDate.year+1),12,31,23,59,59) self.CalendarData['value'] = CalendarSource.readCalendarComponent(start,end) self.account['value'] = CalendarSource self.index = 1 request.redirect("/optional/Calendar") return " "
def getChild(self,path,request): return MainCalendar(self.index,self.CalendarData,self.account)
class MainCalendar(resource.Resource): def __init__(self,index,CalendarData,account): resource.Resource.__init__(self) self.index = index self.CalendarData = CalendarData self.account = account
self.putChild('Add',AddCalendarComponent(self.CalendarData,self.account))
def render(self,request): global Calendarata global account if request.path == "/optional/Calendar" : request.redirect("/optional/Calendar/Month") return " "
def getChild(self,path,request): if request.path == "/optional/Calendar/Month": return Month.month(self.CalendarData,self.index) elif request.path == "/optional/Calendar/Week": return Week.Week(self.CalendarData,self.index) elif request.path == "/optional/Calendar/Day": return Day.Day(self.CalendarData,self.index)
class AddCalendarComponent(resource.Resource): def __init__(self,CalendarData,account): resource.Resource.__init__(self) self.CalendarData = CalendarData self.account = account
def render (self,request): #if request.args != None: queryString = len(request.args) if queryString !=0: try : summary1 = request.args['summary'] location1 = request.args['location'] startDate1 = request.args['startDate'] endDate1 = request.args['endDate'] CalendarSource = self.account['value'] event = CalendarSource.convertToProperFormatAndAddToCalendar(summary1,location1,startDate1,endDate1) (self.CalendarData['value']).append(event) #CalendarData = {} #print "New Data Created" #print NewCalendar #CalendarData['value'] = NewCalendar request.redirect("/optional/Calendar") return " " except KeyError: request.args = {} request.redirect('/optional/Calendar/Month/Add') else: return""" <html> <head> </head> <body>
<form action="/optional/Calendar/Add" method="post"> Summary = <INPUT type="text" name="summary"></br> Location = <input type="text" name="location"></br> Start Date = <input type="text" name="startDate">Should Be in format year/MM/date/HH/MM</br> End Date = <input type="text" name="endDate">Should Be in format year/MM/date/HH/MM</br> <input type="submit"> </form> </body> </html> """
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()
I can guess there should be some method by which I can fork the root for different request,, Please help.
Thanks
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Try using a factory for your session storage instead of storing it in the actually resource, that way you will be able to access your session information from the resources without overriding it on every request. Take a look at twisted.internet.protocol.ServerFactory.
HTH
G
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
On Mon, 18 Aug 2008 10:15:46 -0500, arun chhetri <uhcops@gmail.com> wrote:
So, does this means that twisted.web can only handle one request at a time,,,,, why It should do that. [snip]
class Optional(resource.Resource): [snip] def render(self,request): [snip] self.account['value'] = CalendarSource self.index = 1 request.redirect("/optional/Calendar") return " "
[snip]
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()
There is just one instance of `Optional´ in your application. That instance will be used to render the response to any request for `/optional´. The `Optional´ class also keeps state on itself which appears to be associated with different users. So whenever multiple users make requests of your server, that single `Optional´ instance is going to mix state from them together. What you probably want to do instead is have many instances of `Optional´, perhaps one per user of your system. This means keeping track of them somewhere and finding the right one to use for any particular request. For example, you might keep a dict keyed on username somewhere and in a custom `getChild´ implementation find the right one and return it. Jean-Paul
participants (3)
-
arun chhetri
-
Graeme Glass
-
Jean-Paul Calderone