Get array arguments as list. fix #1875
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from couchpotato.core.helpers.request import getParams
|
||||||
from tornado.web import RequestHandler, asynchronous
|
from tornado.web import RequestHandler, asynchronous
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
@@ -54,6 +55,9 @@ class ApiHandler(RequestHandler):
|
|||||||
for x in self.request.arguments:
|
for x in self.request.arguments:
|
||||||
kwargs[x] = urllib.unquote(self.get_argument(x))
|
kwargs[x] = urllib.unquote(self.get_argument(x))
|
||||||
|
|
||||||
|
# Split array arguments
|
||||||
|
kwargs = getParams(kwargs)
|
||||||
|
|
||||||
# Remove t random string
|
# Remove t random string
|
||||||
try: del kwargs['t']
|
try: del kwargs['t']
|
||||||
except: pass
|
except: pass
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
from couchpotato.core.helpers.encoding import toUnicode
|
||||||
|
from couchpotato.core.helpers.variable import natcmp
|
||||||
|
from urllib import unquote
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def getParams(params):
|
||||||
|
|
||||||
|
reg = re.compile('^[a-z0-9_\.]+$')
|
||||||
|
|
||||||
|
current = temp = {}
|
||||||
|
for param, value in sorted(params.iteritems()):
|
||||||
|
|
||||||
|
nest = re.split("([\[\]]+)", param)
|
||||||
|
if len(nest) > 1:
|
||||||
|
nested = []
|
||||||
|
for key in nest:
|
||||||
|
if reg.match(key):
|
||||||
|
nested.append(key)
|
||||||
|
|
||||||
|
current = temp
|
||||||
|
|
||||||
|
for item in nested:
|
||||||
|
if item is nested[-1]:
|
||||||
|
current[item] = toUnicode(unquote(value))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
current[item]
|
||||||
|
except:
|
||||||
|
current[item] = {}
|
||||||
|
|
||||||
|
current = current[item]
|
||||||
|
else:
|
||||||
|
temp[param] = toUnicode(unquote(value))
|
||||||
|
|
||||||
|
return dictToList(temp)
|
||||||
|
|
||||||
|
def dictToList(params):
|
||||||
|
|
||||||
|
if type(params) is dict:
|
||||||
|
new = {}
|
||||||
|
for x, value in params.iteritems():
|
||||||
|
try:
|
||||||
|
new_value = [dictToList(value[k]) for k in sorted(value.iterkeys(), cmp = natcmp)]
|
||||||
|
except:
|
||||||
|
new_value = value
|
||||||
|
|
||||||
|
new[x] = new_value
|
||||||
|
else:
|
||||||
|
new = params
|
||||||
|
|
||||||
|
return new
|
||||||
Reference in New Issue
Block a user