aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2021-03-09 16:32:55 -0600
committerRossTheRoss <mstrapp@protonmail.com>2021-03-09 16:32:55 -0600
commit82b1ec90dc1abc9600d17f39bcd13596da48b25f (patch)
treea90e5439cad05a80929018c8d7738b79ac9227ef /csci4131
parentAlmost finish redirect (diff)
downloadhomework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.tar
homework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.tar.gz
homework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.tar.bz2
homework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.tar.lz
homework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.tar.xz
homework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.tar.zst
homework-82b1ec90dc1abc9600d17f39bcd13596da48b25f.zip
finish hw
Diffstat (limited to 'csci4131')
-rw-r--r--csci4131/hw4/strap012/strap012.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/csci4131/hw4/strap012/strap012.py b/csci4131/hw4/strap012/strap012.py
index 17571f1..af0f800 100644
--- a/csci4131/hw4/strap012/strap012.py
+++ b/csci4131/hw4/strap012/strap012.py
@@ -25,12 +25,9 @@ def check_perms(resource):
def POST(form):
form = unquote(form)
form = form.replace("+", " ")
- form = form.split("&")
- print(form)
contents = ""
for x in form:
x = x.split("=")
- print(x)
contents = contents + "<tr>\n<td>" + x[0] + "</td>\n<td>" + x[1] + "</td>\n</tr>\n"
table = "<table>" + contents + "</table>"
ret = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset='utf-8'>\n<link rel='stylesheet' href='style.css'>\n<title>Test</title>\n</head>\n<body>\n<h2>\nFollowing Form Data Submitted Successfully:</h2><br>\n{}\n</body>\n</html>".format(table)
@@ -38,14 +35,13 @@ def POST(form):
def getContents(type, file, contents):
if type =="POST":
- if file != "redirect":
- return b"".join(
+ return b"".join(
[OK.encode(), POST(contents).encode(), "{}{}".format(CRLF, CRLF).encode()])
- else:
- contents = contents.split("=")[-1]
- return "HTTP/1.1 307 TEMPORARY REDIRECT{}Connection: close{}Location:{}{}{}".format(CRLF, CRLF, "https://youtube.com/results?search_query=" + contents, CRLF, CRLF).encode()
returnValue = "".encode()
try:
+ if file.split("?")[0] == "redirect":
+ contents = file.split("?")[1].split("=")[-1]
+ return "HTTP/1.1 307 TEMPORARY REDIRECT{}Connection: close{}Location:{}{}{}".format(CRLF, CRLF, "https://youtube.com/results?search_query=" + contents, CRLF, CRLF).encode()
if not check_perms(file):
raise PermissionError
content = open(file, 'rb')