A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. from os.path import expanduser
  3. from urlparse import parse_qs
  4. from earwigbot.bot import Bot
  5. import oursql
  6. _bot = None
  7. _connections = {}
  8. class Query(object):
  9. def __init__(self, environ, method="GET"):
  10. self.query = {}
  11. if method == "GET":
  12. parsed = parse_qs(environ["QUERY_STRING"])
  13. elif method == "POST":
  14. size = environ.get("CONTENT_LENGTH", 0)
  15. parsed = parse_qs(environ["wsgi.input"].read(size))
  16. else:
  17. parsed = {}
  18. for key, value in parsed.iteritems():
  19. try:
  20. self.query[key] = value[-1].decode("utf8")
  21. except UnicodeDecodeError:
  22. pass
  23. def __getattr__(self, key):
  24. try:
  25. return self.query[key]
  26. except KeyError:
  27. return None
  28. def __setattr__(self, key, value):
  29. if key == "query":
  30. super(Query, self).__setattr__(key, value)
  31. else:
  32. self.query[key] = value
  33. def get_bot():
  34. global _bot
  35. if not _bot:
  36. _bot = Bot(".earwigbot", 100) # Don't print any logs to the console
  37. return _bot
  38. def open_sql_connection(bot, dbname):
  39. if dbname in _connections:
  40. return _connections[dbname]
  41. conn_args = bot.config.wiki["_toolserverSQL"][dbname]
  42. if "read_default_file" not in conn_args and "user" not in conn_args and "passwd" not in conn_args:
  43. conn_args["read_default_file"] = expanduser("~/.my.cnf")
  44. if "autoping" not in conn_args:
  45. conn_args["autoping"] = True
  46. if "autoreconnect" not in conn_args:
  47. conn_args["autoreconnect"] = True
  48. conn = oursql.connect(**conn_args)
  49. _connections[dbname] = conn
  50. return conn
  51. def urlstrip(context, url):
  52. if url.startswith("http://"):
  53. url = url[7:]
  54. if url.startswith("https://"):
  55. url = url[8:]
  56. if url.startswith("www."):
  57. url = url[4:]
  58. if url.endswith("/"):
  59. url = url[:-1]
  60. return url