A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

59 行
1.6 KiB

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