Add shorthand requests for connections and validation
This commit is contained in:
parent
03d9adbe22
commit
d43138016c
33
main.py
33
main.py
|
@ -15,8 +15,33 @@ def application(env, re):
|
|||
re("405 Method Not Allowed", [])
|
||||
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:
|
||||
rtype = args["type"][0]
|
||||
rtype = "conn" if conn else "val" if val else args["type"][0]
|
||||
except:
|
||||
re("400 Bad Request", [])
|
||||
yield "<h1>400 Bad Request</h1>".encode()
|
||||
|
@ -27,8 +52,8 @@ def application(env, re):
|
|||
|
||||
if rtype.lower() in ["conn", "connection"]:
|
||||
try:
|
||||
frm = args["from"][0]
|
||||
to = args["to"][0]
|
||||
frm = cfrm or args["from"][0]
|
||||
to = cto or args["to"][0]
|
||||
|
||||
if not frm or not to:
|
||||
raise ValueError()
|
||||
|
@ -78,7 +103,7 @@ def application(env, re):
|
|||
|
||||
elif rtype.lower() in ["val", "validate"]:
|
||||
try:
|
||||
name = args["name"]
|
||||
name = cfrm or args["name"]
|
||||
|
||||
if not name:
|
||||
raise ValueError()
|
||||
|
|
Loading…
Reference in New Issue