adding XML parsing to make sure POST content is welformed

0.6.3-post-fixes
Dr Scofield 2009-01-26 21:34:59 +00:00
parent 10f7e534c9
commit 0aafeb5da3
1 changed files with 17 additions and 0 deletions

View File

@ -29,6 +29,9 @@
import logging import logging
import BaseHTTPServer import BaseHTTPServer
import xml.etree.ElementTree as ET
import xml.parsers.expat
# enable debug level logging # enable debug level logging
logging.basicConfig(level = logging.DEBUG, logging.basicConfig(level = logging.DEBUG,
@ -58,6 +61,13 @@ class ConciergeHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.logResponse(200) self.logResponse(200)
def dumpXml(xml):
logging.debug('[ConciergeHandler] %s', xml.tag)
for attr in xml.attrib:
logging.debug('[ConciergeHandler] %s [%s] %s', xml.tag, attr, xml.attrib[attr])
for kid in xml.getchildren:
dumpXml(kid)
def do_POST(self): def do_POST(self):
self.logRequest() self.logRequest()
hdrs = {} hdrs = {}
@ -69,6 +79,13 @@ class ConciergeHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.rfile.close() self.rfile.close()
logging.debug('[ConciergeHandler] POST: content: %s', content) logging.debug('[ConciergeHandler] POST: content: %s', content)
try:
postXml = ET.parse(content)
dumpXml(postXml)
except xml.parsers.expat.ExpatError, xmlError:
logging.error('[ConciergeHandler] POST illformed:%s', xmlError)
self.send_response(500)
return
self.send_response(200) self.send_response(200)
self.send_header('Content-type', 'text/html') self.send_header('Content-type', 'text/html')