A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

misc.py 1.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from Cookie import CookieError, SimpleCookie
  3. from os.path import expanduser
  4. from urlparse import parse_qs
  5. import oursql
  6. class Query(object):
  7. def __init__(self, environ):
  8. self.query = {}
  9. parsed = parse_qs(environ["QUERY_STRING"])
  10. for key, value in parsed.iteritems():
  11. self.query[key] = value[-1].decode("utf8")
  12. def __getattr__(self, key):
  13. try:
  14. return self.query[key]
  15. except KeyError:
  16. return None
  17. def __setattr__(self, key, value):
  18. if key == "query":
  19. super(Query, self).__setattr__(key, value)
  20. else:
  21. self.query[key] = value
  22. def open_sql_connection(bot, dbname):
  23. conn_args = bot.config.wiki["_toolserverSQL"][dbname]
  24. if "read_default_file" not in conn_args and "user" not in conn_args and "passwd" not in conn_args:
  25. conn_args["read_default_file"] = expanduser("~/.my.cnf")
  26. if "autoping" not in conn_args:
  27. conn_args["autoping"] = True
  28. if "autoreconnect" not in conn_args:
  29. conn_args["autoreconnect"] = True
  30. return oursql.connect(**conn_args)
  31. def urlstrip(context, url):
  32. if url.startswith("http://"):
  33. url = url[7:]
  34. if url.startswith("https://"):
  35. url = url[8:]
  36. if url.startswith("www."):
  37. url = url[4:]
  38. if url.endswith("/"):
  39. url = url[:-1]
  40. return url
  41. def parse_cookies(context, environ):
  42. try:
  43. return SimpleCookie(environ["HTTP_COOKIE"])
  44. except CookieError:
  45. return SimpleCookie()