First test of the future search engine

This commit is contained in:
Stephane Bortzmeyer 2023-06-12 09:11:18 +02:00
parent 0383522a2c
commit 4ffae2f437
2 changed files with 51 additions and 0 deletions

43
search.py Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
# You can test it with:
# curl --request POST --data name=foobar http://localhost:4000
import wsgiref.simple_server as server
import urllib.parse
import psycopg2
PORT = 4000
def pack(start_response, status, data):
datae = data.encode() # Always encode to UTF-8
response_headers = [("Content-type", "text/plain; charset=UTF-8"),
("Content-Length", str(len(datae)))]
start_response(status, response_headers)
return [datae]
def application(environ, start_response):
status = "200 OK"
output = "TODO\r\n"
# REQUEST_METHOD
for variable in environ:
print("%s: %s" % (variable, environ[variable]))
try:
body_size = int(environ.get("CONTENT_LENGTH", 0))
except (ValueError):
body_size = 0
body = environ["wsgi.input"].read(body_size)
print("")
print("Body \"%s\"" % body.decode())
query = urllib.parse.parse_qsl(body.decode())
print("")
print("Query \"%s\"" % query)
return pack(start_response, status, output)
if __name__ == "__main__":
conn = psycopg2.connect("dbname=lsr")
cursor = conn.cursor()
httpd = server.make_server("", PORT, application)
print("Listening on port %s" % PORT)
httpd.serve_forever()

8
search.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<page title="Search TODO">
<p>TODO</p>
<form action="http://localhost:4000/" method="POST" name="Search">
<p>Name: <input type="text" name="name"/></p>
<p><input type="submit" value="Search"/></p>
</form>
</page>