Esempio n. 1
0
    def get(self, section, item, default):

        if section in self.items:
            if item in self.items[section].config:
                return self.items[section][item]

            elif default == None:
                raise ParsingError(
                    "Config worker section : subsection %s : item %s not found "
                    % (section, item))

        elif default == None:
            raise ParsingError("Config %s section : subsection %s not found " %
                               section)

        return default
Esempio n. 2
0
    def __init__(self, config, name, params, configdata):

        config_sections = config_base.get_sections(configdata)

        self.items = OrderedDict()
        self.request_elems = []
        self.response_elems = []
        self.messagetype = params[0]
        self.request_value_count = 0
        self.reply_value_count = 0

        # populate request and reply data

        fields = {
            "messageType": (config_base.read_string, True),
            "workerMessageType": (config_base.read_string, True)
        }

        for n, l in config_sections["main"][1]:
            try:
                what = l.split("=")[0]
                which = l.split("=")[1]
                self.items[what] = config_base.read_config(fields, what, which)
            except Exception, e:
                raise ParsingError("Config line %s : invalid item : %s " %
                                   (n, str(e)))
Esempio n. 3
0
    def __init__(self, data):

        self.config = OrderedDict()
        params, block = data

        okparams = [["terminated", "http"]]
        fields = {
            "contentType": (config_base.read_string, False),
            "requestMethod": (config_base.read_string, False),
            "requestURI": (config_base.read_string, False)
        }
        config_base.myassert(
            len(params) == len(okparams), "Invalid encapsulation definition")
        config_base.myassert(params[0] in okparams[0],
                             "Invalid encapsulation parameter " + params[0])
        self.config["type"] = params[0]

        fields = {}

        for n, l in block:
            try:
                what = l.split("=")[0]
                which = l.split("=")[1]
                self.config[what] = config_base.read_config(
                    fields, what, which)
            except Exception, e:
                raise ParsingError("Config line %s : invalid item : %s " %
                                   (n, str(e)))
Esempio n. 4
0
    def __init__(self, data):

        okparams = [["translatedXML"]]
        fields = {
            "messageID": (config_base.read_message_id, True),
            "replymessageID": (config_base.read_message_id, True)
        }

        self.config = OrderedDict()
        self.messages = []
        params, block = data

        config_base.myassert(
            len(params) == len(okparams), "Invalid message definition")
        config_base.myassert(params[0] in okparams[0],
                             "Invalid message parameter " + params[0])
        self.type = params[0]

        for n, l in block:
            try:
                what = l.split("=")[0]
                which = l.split("=")[1]
                if what == "message":
                    self.messages.append(which)
                else:
                    self.config[what] = config_base.read_config(
                        fields, what, which)
            except Exception, e:
                raise ParsingError("Config line %s : invalid item : %s " %
                                   (n, str(e)))
Esempio n. 5
0
    def __init__(self, argv):
 
        # config file is in argv 
        
        self.file=argv[1] 
 
        # for each config section, instantiate and populate a relevant config object 
        # worker section is mandatory
        
        self.config_classes={ 
                        "worker"     : WorkerConfig ,
                        "xmlmessage" : config_xml.XMLMessageConfig, 
                        "xmlrepeat"  : config_xml.XMLRepeatConfig
                      } 
        try:
            self.data=[ i for i in open(self.file,"r")]
            self.configs=OrderedDict()
            self.block=[]
            self.curr_section=""
            self.curr_params=[]
    
            for number, line in enumerate(self.data):
                 
                if line[0]=="\n" or line[0]=="#" or line[0]==" ":
                    continue
                
                if re_section.search(line)!=None:
                    if self.curr_section != "":
                        
                        config_obj=self.config_classes[self.curr_section](self, self.curr_section,self.curr_params, self.block )
                        self.configs[self.curr_section]=config_obj
     
                    self.block=[]
                    s=config_base.get_section(line)  
                    self.curr_section=s[0] 
                    self.curr_params=s[1:]
                
                else:
                    self.block.append((number+1,line[:-1]))
                    
            config_obj=self.config_classes[self.curr_section](self, self.curr_section, self.curr_params, self.block )
            self.configs[self.curr_section]=config_obj
            
            if not "worker" in self.configs:
                raise ParsingError("Worker section not defined in config file")
            
            # ensure all messages listed in the worker section have definitions in the message items sections 
            self.configs["worker"].check()
            
            # ensure messageID/replymessageID are valid in all the XMLmessage defs 
            messageIDpath=self.configs["worker"].get("message","messageID",None)
            replymessageIDpath=self.configs["worker"].get("message","replymessageID",None)
            for _,message in self.configs["xmlmessage"].iterate_message_list():
                message.check_messageID_path(messageIDpath)
                message.check_replymessageID_path(replymessageIDpath)
                
        except ParsingError,e:
            print >>sys.stderr, "%s : %s " % (type(e).__name__, str(e))
            raise #exit()
Esempio n. 6
0
    def check_replymessageID_path(self, path):

        pathlist = etree_fns.get_path_list(path)
        for resp_elem in self.response_elems:
            resppath = etree_fns.get_path_list(resp_elem.path)
            if pathlist[0] != resppath[0]:
                raise ParsingError(
                    "replymessageID path %s does not match reply path at config line %s : %s "
                    % (path, resp_elem.lineno, resp_elem.path))
Esempio n. 7
0
    def __init__(self, data):

        okparams = [["raw", "tls"]]
        fields = {"port": (config_base.read_string, True)}

        self.config = OrderedDict()
        params, block = data

        config_base.myassert(
            len(params) == len(okparams), "Invalid transport definition")
        config_base.myassert(params[0] in okparams[0],
                             "Invalid worker parameter " + params[0])
        self.config["type"] = params[0]

        for n, l in block:
            try:
                what = l.split("=")[0]
                which = l.split("=")[1]
                self.config[what] = config_base.read_config(
                    fields, what, which)
            except Exception, e:
                raise ParsingError("Config line %s : invalid item : %s " %
                                   (n, str(e)))
Esempio n. 8
0
    def __init__(self, data):

        self.config = OrderedDict()
        _, block = data

        fields = {
            "command": (config_base.read_string, True),
            "remoteserver": (config_base.read_string, True),
            "remoteport": (config_base.read_string, True),
            "fromdelimiter": (config_base.read_delimiter, True),
            "todelimiter": (config_base.read_delimiter, True),
            "fromterminator": (config_base.read_delimiter, True),
            "toterminator": (config_base.read_delimiter, True)
        }

        for n, l in block:
            try:
                what = l.split("=")[0]
                which = l.split("=")[1]
                self.config[what] = config_base.read_config(
                    fields, what, which)
            except Exception, e:
                raise ParsingError("Config line %s : invalid item : %s " %
                                   (n, str(e)))
Esempio n. 9
0
class XMLMessageConfig():
    """ 
    holds config data for an individual xml message defn
    """

    # class level dict of message types
    xml_messages = OrderedDict()
    xml_workermessages = OrderedDict()

    def __init__(self, config, name, params, configdata):

        config_sections = config_base.get_sections(configdata)

        self.items = OrderedDict()
        self.request_elems = []
        self.response_elems = []
        self.messagetype = params[0]
        self.request_value_count = 0
        self.reply_value_count = 0

        # populate request and reply data

        fields = {
            "messageType": (config_base.read_string, True),
            "workerMessageType": (config_base.read_string, True)
        }

        for n, l in config_sections["main"][1]:
            try:
                what = l.split("=")[0]
                which = l.split("=")[1]
                self.items[what] = config_base.read_config(fields, what, which)
            except Exception, e:
                raise ParsingError("Config line %s : invalid item : %s " %
                                   (n, str(e)))

        config_base.check_config("Message %s" % self.messagetype, fields,
                                 self.items)
        self.xml_messages[self.items["messageType"]] = self
        self.xml_workermessages[self.items["workerMessageType"]] = self

        if "request" in config_sections:
            for n, l in config_sections["request"][1]:
                try:
                    which, what = l.split("=")
                    if which == "valueCount":
                        self.request_value_count = int(what)
                    else:
                        lineclass = classlookup[which]
                        if lineclass:
                            self.request_elems.append(
                                lineclass(config, n, what))
                except:
                    raise ParsingError(
                        "Invalid configuration : %s at line %s " % (l, n))
        else:
            raise ParsingError("xmlmessage %s missing request definition" %
                               self.messagetype)

        if "reply" in config_sections:
            for n, l in config_sections["reply"][1]:
                try:
                    which, what = l.split("=")
                    if which == "valueCount":
                        self.reply_value_count = int(what)
                    else:
                        lineclass = classlookup[which]
                        if lineclass:
                            self.response_elems.append(
                                lineclass(config, n, what))
                except:
                    raise ParsingError(
                        "Invalid configuration : %s at line %s " % (l, n))
        else:
            raise ParsingError("xmlmessage %s missing reply definition" %
                               self.messagetype)

        if self.request_value_count == 0:
            raise ParsingError("xmlmessage %s missing request value count " %
                               self.messagetype)
        if self.request_value_count - 1 != self.request_elems[-1].ssv_col:
            raise ParsingError(
                "xmlmessage %s invalid request value count %s " %
                (self.messagetype, self.request_value_count))
        if self.reply_value_count == 0:
            raise ParsingError("xmlmessage %s missing reply value count " %
                               self.messagetype)
        if self.reply_value_count - 1 != self.response_elems[-1].ssv_col:
            raise ParsingError("xmlmessage %s invalid reply value count %s " %
                               (self.messagetype, self.reply_value_count))
Esempio n. 10
0
    def check(self):
        # ensure all messages listed in the worker section have definitions in the message config sections
        for k in self.items["message"].messages:

            if not self.config.check_message_defined(k):
                raise ParsingError("Message type %s is not defined " % k)