A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
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.

преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. from markupsafe import escape
  3. from .cookies import set_cookie, delete_cookie
  4. from .misc import get_bot, Query
  5. from .sites import get_sites
  6. def main(context, environ, headers, cookies):
  7. query = Query(environ, method="POST")
  8. if query.action == "set":
  9. status = _do_set(query, headers, cookies)
  10. elif query.action == "delete":
  11. status = _do_delete(query, headers, cookies)
  12. else:
  13. status = None
  14. bot = get_bot()
  15. langs, projects = get_sites(bot)
  16. return bot, cookies, status, langs, projects
  17. def _do_set(query, headers, cookies):
  18. changes = set()
  19. if query.lang:
  20. key = "EarwigDefaultLang"
  21. if key not in cookies or cookies[key].value != query.lang:
  22. set_cookie(headers, cookies, key, query.lang, 365)
  23. changes.add("site")
  24. if query.project:
  25. key = "EarwigDefaultProject"
  26. if key not in cookies or cookies[key].value != query.project:
  27. set_cookie(headers, cookies, key, query.project, 365)
  28. changes.add("site")
  29. if query.background:
  30. key = "EarwigBackground"
  31. if key not in cookies or cookies[key].value != query.background:
  32. set_cookie(headers, cookies, key, query.background, 365)
  33. changes.add("background")
  34. if changes:
  35. changes = ", ".format(sorted(list(changes)))
  36. return "Updated {0}.".format(changes)
  37. return None
  38. def _do_delete(query, headers, cookies):
  39. if query.cookie in cookies:
  40. delete_cookie(headers, cookies, query.cookie.encode("utf8"))
  41. template = "Deleted cookie <b><tt>{0}</tt></b>."
  42. return template.format(escape(query.cookie))
  43. elif query.all:
  44. number = len(cookies)
  45. for cookie in cookies.values():
  46. delete_cookie(headers, cookies, cookie.key)
  47. return "Deleted <b>{0}</b> cookies.".format(number)
  48. return None