osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

comp.lang.python


Hi, 
  a few weeks back I posed a question about passing static data to a 
request server, and thanks to some useful suggestions, got it working. I 
see yesterday there is a suggestion to use a framework like Tornado 
rather than base classes. However I can't figure achieve the same effect 
using Tornado (BTW this is all python 2.7). The key point is how to 
access the server class from within do_GET, and from the server class 
instance, to access its get and set methods. 

Here are some code fragments that work with HTTPServer: 

class MyHandler(BaseHTTPRequestHandler): 

     def do_GET(self): 
         ss = self.server 
         tracks = ss.tracks 
. . . 
class MyWebServer(object): 
     def get_params(self): 
         return self.global_params 
     def set_params(self, params): 
         self.global_params = params 
     def get_tracks(self): 
         return self.tracks 
     def __init__(self): 
         self.global_params = "" 
         self.tracks = setup_() 
         myServer = HTTPServer 
         myServer.tracks = self.get_tracks() 
         myServer.params = self.get_params() 
         self.server = myServer(('', 7878), MyHandler) 
         print 'started httpserver on port 7878...' 
. . . . 
def main(): 
     aServer = MyWebServer() 
     aServer.runIt() 

if __name__ == '__main__': 
     main() 





Show trimmed content
website-->  http://www.win2job.info/