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.
 
 
 
 
 

61 lines
1.7 KiB

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