Para quien le sirva, me he pasado un rato haciendo una función en python que fuera equivalente a http_build_query de PHP.
## # Mimics the behaviour of http_build_query PHP function # This method can be useful for sending data to flash applications ################################################## def http_build_query(params, topkey = ''): from urllib import quote if len(params) == 0: return "" result = "" # is a dictionary? if type (params) is dict: for key in params.keys(): newkey = quote (key) if topkey != '': newkey = topkey + quote('[' + key + ']') if type(params[key]) is dict: result += http_build_query (params[key], newkey) elif type(params[key]) is list: i = 0 for val in params[key]: result += newkey + quote('[' + str(i) + ']') + "=" + quote(str(val)) + "&" i = i + 1 # boolean should have special treatment as well elif type(params[key]) is bool: result += newkey + "=" + quote (str(int(params[key]))) + "&" # assume string (integers and floats work well) else: result += newkey + "=" + quote (str(params[key])) + "&" # remove the last '&' if (result) and (topkey == '') and (result[-1] == '&'): result = result[:-1] return result |
English
23/04/2010 at 2:38 pm Permalink
Huy, ¿tu no tenías aversión a python?
24/04/2010 at 1:04 am Permalink
@maeghith ciertamente tenía… sinceramente, sigue sin gustarme el tema de no poder usar las llaves ‘{‘ y ‘}’. Si bien python tiene algunas ventajas sobre otros lenguages.
Para un proyecto que estoy desarrollando en Google App Engine, la alternativa era java. Y el caso es que java me parece fácil como lenguaje, pero eso de tener que compilar… me cansa. Además, tiene bastantes limitaciones en GAE.
Así que puestos a elegir, me he decantado por usar Python