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 година
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, 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, 1095)
  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, 1095)
  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, 1095)
  33. delete_cookie(headers, cookies, "EarwigBackgroundCache")
  34. changes.add("background")
  35. if changes:
  36. changes = ", ".join(sorted(list(changes)))
  37. return "Updated {0}.".format(changes)
  38. return None
  39. def _do_delete(query, headers, cookies):
  40. if query.cookie in cookies:
  41. delete_cookie(headers, cookies, query.cookie.encode("utf8"))
  42. template = u"Deleted cookie <b><tt>{0}</tt></b>."
  43. return template.format(escape(query.cookie))
  44. elif query.all:
  45. number = len(cookies)
  46. for cookie in cookies.values():
  47. delete_cookie(headers, cookies, cookie.key)
  48. return "Deleted <b>{0}</b> cookies.".format(number)
  49. return None