A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

settings.py 1.6 KiB

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