I am playing around on the idea adding a integrated HTTP interface to a daemon i am building using Python. I like this approach because it makes the whole daemon code portable.(rather than having a separate web portion and cli portion).
Everything works great but i am wondering about best practices to parse the actual request i receive in the do_GET
method.
Here is my prototype do_GET
method
def do_GET(self):
str = "OK"
print self.request
self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Content-length", len(str))
self.end_headers()
self.wfile.write(str)
the request
attribute contains the following string when a request is received
127.0.0.1 - - [15/Jan/2014 10:21:23] "GET /" 200 -
Is there a standard library i can use to parse this string? a custom parser that i would need to write i believe first tokenize the string using -
as a delimiter and then handle 3rd element with some sort of a regular expression matching [([^\]]+)]
for request date and "[[^\"]+"
for request path.
i am worried about writing a custom parser because of all the exceptions that i may run into. So i am inquiring about any python standard methods for parsing this.
Thanks for your time.