Parse query string with urlparse instead of manually.

pull/7/head
Ferry Boender 10 years ago
parent 19967cd014
commit 7e568d5fcd
  1. 16
      src/scriptform.py

@ -23,6 +23,7 @@ import subprocess
import base64 import base64
import tempfile import tempfile
import hashlib import hashlib
import urlparse
html_header = '''<html> html_header = '''<html>
@ -516,14 +517,13 @@ class WebAppHandler(BaseHTTPRequestHandler):
self.call(self.path.strip('/'), params={'form_values': form_values}) self.call(self.path.strip('/'), params={'form_values': form_values})
def parse(self, reqinfo): def parse(self, reqinfo):
if '?' in reqinfo: url_comp = urlparse.urlsplit(reqinfo)
path, params = reqinfo.split('?', 1) path = url_comp.path
params = dict( qs = urlparse.parse_qs(url_comp.query)
[p.split('=', 1) for p in params.split('&') if '=' in p] # Only return the first value of each query var. E.g. for
) # "?foo=1&foo=2" return '1'.
return (path.strip('/'), params) vars = dict( [(k, v[0]) for k, v in qs.items()] )
else: return (path.strip('/'), vars)
return (self.path.strip('/'), {})
def call(self, path, params): def call(self, path, params):
""" """

Loading…
Cancel
Save