Add shorthand requests for connections and validation
This commit is contained in:
parent
03d9adbe22
commit
d43138016c
1 changed files with 29 additions and 4 deletions
33
main.py
33
main.py
|
@ -15,8 +15,33 @@ def application(env, re):
|
||||||
re("405 Method Not Allowed", [])
|
re("405 Method Not Allowed", [])
|
||||||
return
|
return
|
||||||
|
|
||||||
|
conn = False
|
||||||
|
val = False
|
||||||
|
cfrm = None
|
||||||
|
cto = None
|
||||||
|
|
||||||
|
split = env["PATH_INFO"].split("/")
|
||||||
|
|
||||||
|
while "" in split:
|
||||||
|
split.remove("")
|
||||||
|
|
||||||
|
if len(split) > 2:
|
||||||
|
re("400 Bad Request", [])
|
||||||
|
yield "<h1>400 Bad Request</h1>".encode()
|
||||||
|
yield "Only one (validate) or two (conn) arguments may be passed as path."
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(split) > 0:
|
||||||
|
if len(split) == 1:
|
||||||
|
val = True
|
||||||
|
else:
|
||||||
|
conn = True
|
||||||
|
cto = split[1]
|
||||||
|
|
||||||
|
cfrm = split[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rtype = args["type"][0]
|
rtype = "conn" if conn else "val" if val else args["type"][0]
|
||||||
except:
|
except:
|
||||||
re("400 Bad Request", [])
|
re("400 Bad Request", [])
|
||||||
yield "<h1>400 Bad Request</h1>".encode()
|
yield "<h1>400 Bad Request</h1>".encode()
|
||||||
|
@ -27,8 +52,8 @@ def application(env, re):
|
||||||
|
|
||||||
if rtype.lower() in ["conn", "connection"]:
|
if rtype.lower() in ["conn", "connection"]:
|
||||||
try:
|
try:
|
||||||
frm = args["from"][0]
|
frm = cfrm or args["from"][0]
|
||||||
to = args["to"][0]
|
to = cto or args["to"][0]
|
||||||
|
|
||||||
if not frm or not to:
|
if not frm or not to:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
@ -78,7 +103,7 @@ def application(env, re):
|
||||||
|
|
||||||
elif rtype.lower() in ["val", "validate"]:
|
elif rtype.lower() in ["val", "validate"]:
|
||||||
try:
|
try:
|
||||||
name = args["name"]
|
name = cfrm or args["name"]
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
Loading…
Reference in a new issue