Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44069
| From | Tom P <werotizy@freent.dd> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | HTTPServer again |
| Date | 2013-04-22 15:41 +0200 |
| Message-ID | <atkt0dFtvv0U1@mid.individual.net> (permalink) |
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()
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
HTTPServer again Tom P <werotizy@freent.dd> - 2013-04-22 15:41 +0200
csiph-web