This is Pluto, the webhook server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.py 716B

12345678910111213141516171819202122232425262728293031323334
  1. import json
  2. def header_dumps(hdr):
  3. return '\n'.join('%s: %s'%(k, v) for k, v in hdr.items())
  4. def header_loads(hdr):
  5. d = {}
  6. for line in hdr.split('\n'):
  7. k, _, v = line.partition(': ')
  8. if _:
  9. d[k] = v
  10. return d
  11. def jloads(s):
  12. try:
  13. return json.loads(s)
  14. except ValueError:
  15. return s
  16. def jdumps(obj):
  17. try:
  18. return json.dumps(obj)
  19. except ValueError:
  20. return obj
  21. def checkbox(request, name):
  22. return (True if request.values.get(name, 0, int) else False)
  23. def safe_load(tpn, rowid):
  24. import model
  25. try:
  26. return getattr(model, tpn).get_one(rowid=rowid)
  27. except (AttributeError, model.DBError):
  28. return None