473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

BaseHTTPServer and class variables

Yin
Hello.

I am using the basehttpserver to implement the HTTP protocol to serve
a fairly large lexicon that I have loaded as a dictionary in python.
Rather than writing a whole server, I would like to reuse the
BaseHTTPserver classes. I am interested in finding a way to serve the
dict without loading the whole dict into memory everytime an HTTP
request is made. The dict lives in local memory when it is loaded and
takes a long time to load.

Unfortunately with the basehttpserver.httpserver and
basehttpserver.requesthandlerclass, I am not finding it easy to define
a method to load the dict initially. Any thoughts are appreciated.

Ideally, in a do_GET for the requesthandlerclass, it'd be nice to be
able to access the dict as a class variable, but this doesn't work for
me.

Thanks.
Yin
Jul 18 '05 #1
1 1857
yi*******@yahoo.com (Yin) writes:
Hello. I am using the basehttpserver to implement the HTTP protocol to serve
a fairly large lexicon that I have loaded as a dictionary in python.
Rather than writing a whole server, I would like to reuse the
BaseHTTPserver classes. I am interested in finding a way to serve the
dict without loading the whole dict into memory everytime an HTTP
request is made. The dict lives in local memory when it is loaded and
takes a long time to load. Unfortunately with the basehttpserver.httpserver and
basehttpserver.requesthandlerclass, I am not finding it easy to define
a method to load the dict initially. Any thoughts are appreciated. Ideally, in a do_GET for the requesthandlerclass, it'd be nice to be
able to access the dict as a class variable, but this doesn't work for
me.


import BaseHTTPServer

class Serv (BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET (self):
path = self.path.strip('/').split('/')
self.send_response (200)
self.send_header ('Content-type', 'text/html')
self.end_headers()
self.wfile.write (self.dict[path[-1]])

# load dictionary
D={'foo':1, 'bar':2}
server = BaseHTTPServer.HTTPServer (('', 8080), Serv)
server.RequestHandlerClass.dict = D
server.serve_forever()

Possibly not the best way but it should do unless someone less lazy than I
responds. (Assuming I'm understanding your request correctly).

Eddie
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joshua W. Biagio | last post by:
Hello all, I am having difficulty getting the HTTP/1.1 support (i.e. pipelining and persistent connections) for the BaseHTTPServer library to work. When I change the line for the protocol in...
2
by: Tortelini | last post by:
I am making custom web server using HTTPServer and want to be able to access it simultaneously from different computers. To achieve multithreading, I have been experimenting with ThreadingMixIn...
4
by: amfr | last post by:
>From the BaseHTTPServer module, how do i gget the POST or GET data sent by the client? Is it stired the the file they requested? e.g. objectname.path
0
by: Jeff Gercken | last post by:
I want my http server to return a default form, regardless of the GET request, but I'm a bit of a noob and have no idea how. I'm trying to write a platform-independent captured portal for my...
0
by: Ron Garret | last post by:
I'm write a web server using BaseHTTPServer. It can't be a CGI because it has to do some weird server-push stuff as database updates come in. But I still need to process form inputs as if it were...
13
by: Ron Garret | last post by:
I'm trying to figure out how to use BaseHTTPServer. Here's my little test app: ================================= #!/usr/bin/python from BaseHTTPServer import * import cgi
3
by: Ron Garret | last post by:
I have a fairly large web app written in Python as a CGI fairly elaborate CGI. All of the requests go through a single CGI script which does authentication and session management and then...
0
by: samwyse | last post by:
I've just now submitted two issues to the issue tracker: 1491 BaseHTTPServer incorrectly implements response code 100 RFC 2616 sec 8.2.3 states, "An origin server that sends a 100...
4
by: sebsauvage | last post by:
Hello. I'm using SimpleHTTPServer (work well) but it always sends "Server" header in response: "Server: SimpleHTTP/0.6 Python/2.5.1" How can I remove that ? I tried:
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.