Rework XML parser: part 1

This is the first step of the parser refactoring: here we change
	the configuration, next step will change data saving.
This commit is contained in:
nemunaire 2015-10-27 18:03:28 +01:00
commit c560e13f24
18 changed files with 370 additions and 122 deletions

View file

@ -15,7 +15,7 @@ from more import Response
# LOADING #############################################################
def load(context):
if not context.config or not context.config.getAttribute("goodreadskey"):
if not context.config or "goodreadskey" not in context.config:
raise ImportError("You need a Goodreads API key in order to use this "
"module. Add it to the module configuration file:\n"
"<module name=\"books\" goodreadskey=\"XXXXXX\" />\n"

View file

@ -16,7 +16,7 @@ from more import Response
URL_API = "http://open.mapquestapi.com/geocoding/v1/address?key=%s&location=%%s"
def load(context):
if not context.config or not context.config.hasAttribute("apikey"):
if not context.config or "apikey" not in context.config:
raise ImportError("You need a MapQuest API key in order to use this "
"module. Add it to the module configuration file:\n"
"<module name=\"mapquest\" key=\"XXXXXXXXXXXXXXXX\" "

View file

@ -11,7 +11,7 @@ URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?rid=1&domainNam
def load(CONF, add_hook):
global URL_WHOIS
if not CONF or not CONF.hasNode("whoisxmlapi") or not CONF.getNode("whoisxmlapi").hasAttribute("username") or not CONF.getNode("whoisxmlapi").hasAttribute("password"):
if not CONF or not CONF.hasNode("whoisxmlapi") or "username" not in CONF.getNode("whoisxmlapi") or "password" not in CONF.getNode("whoisxmlapi"):
raise ImportError("You need a WhoisXML API account in order to use "
"the !netwhois feature. Add it to the module "
"configuration file:\n<whoisxmlapi username=\"XX\" "

View file

@ -21,7 +21,7 @@ def help_full():
def load(context):
global lang_binding
if not context.config or not context.config.hasAttribute("bighugelabskey"):
if not context.config or not "bighugelabskey" in context.config:
logger.error("You need a NigHugeLabs API key in order to have english "
"theasorus. Add it to the module configuration file:\n"
"<module name=\"syno\" bighugelabskey=\"XXXXXXXXXXXXXXXX\""

View file

@ -13,7 +13,7 @@ from more import Response
URL_TPBAPI = None
def load(context):
if not context.config or not context.config.hasAttribute("url"):
if not context.config or "url" not in context.config:
raise ImportError("You need a TPB API in order to use the !tpb feature"
". Add it to the module configuration file:\n<module"
"name=\"tpb\" url=\"http://tpbapi.org/\" />\nSample "

View file

@ -19,7 +19,7 @@ LANG = ["ar", "zh", "cz", "en", "fr", "gr", "it",
URL = "http://api.wordreference.com/0.8/%s/json/%%s%%s/%%s"
def load(context):
if not context.config or not context.config.hasAttribute("wrapikey"):
if not context.config or "wrapikey" not in context.config:
raise ImportError("You need a WordReference API key in order to use "
"this module. Add it to the module configuration "
"file:\n<module name=\"translate\" wrapikey=\"XXXXX\""

View file

@ -18,7 +18,7 @@ URL_API = None # http://www.velib.paris.fr/service/stationdetails/paris/%s
def load(context):
global URL_API
if not context.config or not context.config.hasAttribute("url"):
if not context.config or "url" not in context.config:
raise ImportError("Please provide url attribute in the module configuration")
URL_API = context.config["url"]
context.data.setIndex("name", "station")

View file

@ -21,7 +21,7 @@ from more import Response
URL_DSAPI = "https://api.forecast.io/forecast/%s/%%s,%%s"
def load(context):
if not context.config or not context.config.hasAttribute("darkskyapikey"):
if not context.config or "darkskyapikey" not in context.config:
raise ImportError("You need a Dark-Sky API key in order to use this "
"module. Add it to the module configuration file:\n"
"<module name=\"weather\" darkskyapikey=\"XXX\" />\n"

View file

@ -16,7 +16,7 @@ PASSWD_FILE = None
def load(context):
global PASSWD_FILE
if not context.config or not context.config.hasAttribute("passwd"):
if not context.config or "passwd" not in context.config:
print("No passwd file given")
return None
PASSWD_FILE = context.config["passwd"]

View file

@ -19,7 +19,7 @@ URL_API = "http://api.wolframalpha.com/v2/query?input=%%s&appid=%s"
def load(context):
global URL_API
if not context.config or not context.config.hasAttribute("apikey"):
if not context.config or "apikey" not in context.config:
raise ImportError ("You need a Wolfram|Alpha API key in order to use "
"this module. Add it to the module configuration: "
"\n<module name=\"wolframalpha\" "