A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

52 líneas
1.4 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):
  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 get_bot():
  42. return Bot(".earwigbot", 100) # Don't print any logs to the console