Move xmlparser to tools

This commit is contained in:
nemunaire 2014-12-06 09:00:53 +01:00
parent 5dcf0d6961
commit d6ea5736a5
11 changed files with 20 additions and 25 deletions

7
bot.py
View File

@ -26,7 +26,7 @@ import threading
import time import time
import uuid import uuid
__version__ = '3.4.dev2' __version__ = '3.4.dev3'
__author__ = 'nemunaire' __author__ = 'nemunaire'
from consumer import Consumer, EventConsumer, MessageConsumer from consumer import Consumer, EventConsumer, MessageConsumer
@ -504,8 +504,3 @@ def reload():
imp.reload(tools) imp.reload(tools)
tools.reload() tools.reload()
import xmlparser
imp.reload(xmlparser)
import xmlparser.node
imp.reload(xmlparser.node)

View File

@ -29,7 +29,7 @@ import event
import exception import exception
import hooks import hooks
from message import TextMessage from message import TextMessage
import xmlparser from tools.xmlparser import parse_file, module_state
logger = logging.getLogger("nemubot.importer") logger = logging.getLogger("nemubot.importer")
@ -191,7 +191,7 @@ class ModuleLoader(SourceLoader):
module.del_event = del_event module.del_event = del_event
if not hasattr(module, "NODATA"): if not hasattr(module, "NODATA"):
module.DATAS = xmlparser.parse_file(self.context.data_path module.DATAS = parse_file(self.context.data_path
+ module.__name__ + ".xml") + module.__name__ + ".xml")
module.save = mod_save module.save = mod_save
else: else:
@ -200,7 +200,7 @@ class ModuleLoader(SourceLoader):
module.CONF = self.config module.CONF = self.config
module.ModuleEvent = event.ModuleEvent module.ModuleEvent = event.ModuleEvent
module.ModuleState = xmlparser.module_state.ModuleState module.ModuleState = module_state.ModuleState
module.IRCException = exception.IRCException module.IRCException = exception.IRCException
# Load dependancies # Load dependancies

View File

@ -9,7 +9,7 @@ from datetime import date, datetime
from hooks import hook from hooks import hook
from tools.countdown import countdown_format from tools.countdown import countdown_format
from tools.date import extractDate from tools.date import extractDate
from xmlparser.node import ModuleState from tools.xmlparser.node import ModuleState
nemubotversion = 3.4 nemubotversion = 3.4

View File

@ -3,15 +3,15 @@
from urllib.parse import quote from urllib.parse import quote
from urllib.request import urlopen from urllib.request import urlopen
import xmlparser
from tools import web from tools import web
from tools.xmlparser import parse_string
class DDGSearch: class DDGSearch:
def __init__(self, terms): def __init__(self, terms):
self.terms = terms self.terms = terms
raw = urlopen("https://api.duckduckgo.com/?q=%s&format=xml&no_redirect=1" % quote(terms), timeout=10) raw = urlopen("https://api.duckduckgo.com/?q=%s&format=xml&no_redirect=1" % quote(terms), timeout=10)
self.ddgres = xmlparser.parse_string(raw.read()) self.ddgres = parse_string(raw.read())
@property @property
def type(self): def type(self):

View File

@ -3,7 +3,7 @@
from urllib.parse import quote from urllib.parse import quote
from urllib.request import urlopen from urllib.request import urlopen
import xmlparser from tools.xmlparser import parse_string
class WFASearch: class WFASearch:
def __init__(self, terms): def __init__(self, terms):
@ -13,7 +13,7 @@ class WFASearch:
"input=%s&appid=%s" "input=%s&appid=%s"
% (quote(terms), % (quote(terms),
CONF.getNode("wfaapi")["key"]), timeout=15) CONF.getNode("wfaapi")["key"]), timeout=15)
self.wfares = xmlparser.parse_string(raw.read()) self.wfares = parse_string(raw.read())
except (TypeError, KeyError): except (TypeError, KeyError):
print ("You need a Wolfram|Alpha API key in order to use this " print ("You need a Wolfram|Alpha API key in order to use this "
"module. Add it to the module configuration file:\n<wfaapi" "module. Add it to the module configuration file:\n<wfaapi"

View File

@ -13,7 +13,6 @@ nemubotversion = 3.4
from more import Response from more import Response
import xmlparser
LANG = ["ar", "zh", "cz", "en", "fr", "gr", "it", LANG = ["ar", "zh", "cz", "en", "fr", "gr", "it",
"ja", "ko", "pl", "pt", "ro", "es", "tr"] "ja", "ko", "pl", "pt", "ro", "es", "tr"]

View File

@ -44,3 +44,8 @@ def reload():
import tools.web import tools.web
imp.reload(tools.web) imp.reload(tools.web)
import tools.xmlparser
imp.reload(tools.xmlparser)
import tools.xmlparser.node
imp.reload(tools.xmlparser.node)

View File

@ -19,7 +19,7 @@
import logging import logging
import os import os
import xmlparser from tools.xmlparser import parse_file
logger = logging.getLogger("nemubot.tools.config") logger = logging.getLogger("nemubot.tools.config")
@ -98,7 +98,7 @@ def load_file(filename, context):
""" """
if os.path.isfile(filename): if os.path.isfile(filename):
config = xmlparser.parse_file(filename) config = parse_file(filename)
# This is a true nemubot configuration file, load it! # This is a true nemubot configuration file, load it!
if config.getName() == "nemubotconfig": if config.getName() == "nemubotconfig":

View File

@ -26,7 +26,7 @@ from urllib.parse import urlparse
from urllib.request import urlopen from urllib.request import urlopen
from exception import IRCException from exception import IRCException
import xmlparser from tools.xmlparser import parse_string
def isURL(url): def isURL(url):
@ -141,7 +141,7 @@ def getXML(url, timeout=15):
if cnt is None: if cnt is None:
return None return None
else: else:
return xmlparser.parse_string(cnt.encode()) return parse_string(cnt.encode())
def getJSON(url, timeout=15): def getJSON(url, timeout=15):

View File

@ -16,14 +16,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import imp
import logging import logging
import xml.sax import xml.sax
from . import node as module_state from . import node as module_state
logger = logging.getLogger("nemubot.xmlparser") logger = logging.getLogger("nemubot.tools.xmlparser")
class ModuleStatesFile(xml.sax.ContentHandler): class ModuleStatesFile(xml.sax.ContentHandler):

View File

@ -3,11 +3,9 @@
import xml.sax import xml.sax
from datetime import datetime, timezone from datetime import datetime, timezone
import logging import logging
import sys
import time import time
import traceback
logger = logging.getLogger("nemubot.xmlparser.node") logger = logging.getLogger("nemubot.tools.xmlparser.node")
class ModuleState: class ModuleState: