コード例 #1
0
ファイル: graph.py プロジェクト: Doshmaku/program-y
    def parse_bot_expression(self, expression, branch):

        bot_node = TemplateBotNode()
        branch.children.append(bot_node)

        name_found = False

        if 'name' in expression.attrib:
            node = TemplateNode()
            name_node = TemplateWordNode(expression.attrib['name'])
            node.append(name_node)
            name_found = True
            bot_node.name = node

        self.parse_text(self.get_text_from_element(expression), bot_node)

        for child in expression:

            if child.tag == 'name':
                node = TemplateNode()
                self.parse_text(self.get_text_from_element(child), node)
                for sub_child in child:
                    self.parse_tag_expression(sub_child, node)
                    self.parse_text(self.get_text_from_element(child), node)

                bot_node.name = node
                name_found = True

            else:
                self.parse_tag_expression(child, bot_node)

            self.parse_text(self.get_tail_from_element(child), bot_node)

        if name_found is False:
            raise ParserException("Error, name not found", xml_element=expression)
コード例 #2
0
    def test_to_xml(self):
        root = TemplateNode()
        node = TemplateBotNode()
        node.name = TemplateWordNode("name")
        root.append(node)

        xml = root.xml_tree(self.bot, self.clientid)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual('<template><bot name="name" /></template>', xml_str)
コード例 #3
0
ファイル: test_bot.py プロジェクト: Freiza/program-y
    def test_to_xml(self):
        root = TemplateNode()
        node = TemplateBotNode()
        node.name = TemplateWordNode("name")
        root.append(node)

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual('<template><bot name="name" /></template>', xml_str)
コード例 #4
0
ファイル: test_bot.py プロジェクト: lilnana00/3ddd
    def test_node_no_default_get(self):
        self._client_context.brain.configuration.defaults._default_get = None

        root = TemplateNode()
        node = TemplateBotNode()
        node.name = TemplateWordNode("location")
        root.append(node)

        result = node.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEquals("unknown", result)
コード例 #5
0
    def test_node_no_value(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self.bot.brain.properties.add_property("default-property", "unknown")

        result = node.resolve(self.bot, self.clientid)
        self.assertIsNotNone(result)
        self.assertEqual("unknown", result)
コード例 #6
0
ファイル: test_bot.py プロジェクト: Freiza/program-y
    def test_node_no_value(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self._client_context.brain.properties.add_property("default-property", "unknown")

        result = node.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("unknown", result)
コード例 #7
0
ファイル: test_bot.py プロジェクト: Doshmaku/program-y
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self.bot.brain.properties.add_property("location", "Scotland")

        result = node.resolve(self.bot, self.clientid)
        self.assertIsNotNone(result)
        self.assertEqual("Scotland", result)
コード例 #8
0
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self._client_context.brain.properties.add_property("location", "Scotland")

        result = node.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("Scotland", result)
コード例 #9
0
ファイル: condition.py プロジェクト: Freiza/program-y
 def get_condition_variable_value(self, client_context, var_type, name):
     if var_type == TemplateConditionVariable.GLOBAL:
         return TemplateGetNode.get_property_value(client_context, False, name)
     elif var_type == TemplateConditionVariable.LOCAL:
         return TemplateGetNode.get_property_value(client_context, True, name)
     elif var_type == TemplateConditionVariable.BOT:
         return TemplateBotNode.get_bot_variable(client_context, name)
     else:
         return"unknown"
コード例 #10
0
 def get_condition_variable_value(self, client_context, var_type, name):
     if var_type == TemplateConditionVariable.GLOBAL:
         return TemplateGetNode.get_property_value(client_context, False,
                                                   name)
     elif var_type == TemplateConditionVariable.LOCAL:
         return TemplateGetNode.get_property_value(client_context, True,
                                                   name)
     elif var_type == TemplateConditionVariable.BOT:
         return TemplateBotNode.get_bot_variable(client_context, name)
     else:
         return "unknown"
コード例 #11
0
    def execute(self, client_context, data):
        YLogger.debug(client_context, "Properties Admin - [%s]", data)

        properties = ""

        splits = data.split()
        if splits[0] == 'GET':

            if splits[1] == 'BOT':
                properties = TemplateBotNode.get_bot_variable(
                    client_context, splits[2])

            elif splits[1] == "USER":
                if splits[2].upper() == 'NAME':
                    properties = TemplateGetNode.get_property_value(
                        client_context, 'name', splits[3])
                elif splits[2].upper() == 'DATA':
                    properties = TemplateGetNode.get_property_value(
                        client_context, 'data', splits[3])
                elif splits[2].upper() == 'VAR':
                    properties = TemplateGetNode.get_property_value(
                        client_context, 'var', splits[3])

        elif splits[0] == 'BOT':
            properties += "Properties:<br /><ul>"
            for pair in client_context.brain.properties.pairs:
                properties += "<li>%s = %s</li>" % (pair[0], pair[1])
            properties += "</ul>"
            properties += "<br />"

        elif splits[0] == "USER":
            if client_context.bot.has_conversation(client_context):
                conversation = client_context.bot.get_conversation(
                    client_context)

                properties += "Properties:<br /><ul>"
                for name, value in conversation.properties.items():
                    properties += "<li>%s = %s</li>" % (name, value)
                properties += "</ul>"
                properties += "<br />"

            else:
                properties += "No conversation currently available"

        return properties
コード例 #12
0
    def execute(self, bot, clientid, data):
        if logging.getLogger().isEnabledFor(logging.DEBUG):
            logging.debug("Properties Admin - [%s]", data)

        properties = ""

        splits = data.split()
        if splits[0] == 'GET':

            if splits[1] == 'BOT':
                properties = TemplateBotNode.get_bot_variable(bot, clientid, splits[2])

            elif splits[1] == "USER":
                local = bool(splits[2].upper == 'LOCAL')
                properties = TemplateGetNode.get_property_value(bot, clientid, local, splits[3])

        elif splits[0] == 'BOT':
            properties += "Properties:<br /><ul>"
            for pair in bot.brain.properties.pairs:
                properties += "<li>%s = %s</li>"%(pair[0], pair[1])
            properties += "</ul>"
            properties += "<br />"

        elif splits[0] == "USER":
            if bot.has_conversation(clientid):
                conversation = bot.conversation(clientid)

                properties += "Properties:<br /><ul>"
                for name, value in conversation.properties.items():
                    properties += "<li>%s = %s</li>"%(name, value)
                properties += "</ul>"
                properties += "<br />"

            else:
                properties += "No conversation currently available"

        return properties
コード例 #13
0
ファイル: properties.py プロジェクト: Freiza/program-y
    def execute(self, client_context, data):
        YLogger.debug(client_context, "Properties Admin - [%s]", data)

        properties = ""

        splits = data.split()
        if splits[0] == 'GET':

            if splits[1] == 'BOT':
                properties = TemplateBotNode.get_bot_variable(client_context, splits[2])

            elif splits[1] == "USER":
                local = bool(splits[2].upper == 'LOCAL')
                properties = TemplateGetNode.get_property_value(client_context, local, splits[3])

        elif splits[0] == 'BOT':
            properties += "Properties:<br /><ul>"
            for pair in client_context.brain.properties.pairs:
                properties += "<li>%s = %s</li>"%(pair[0], pair[1])
            properties += "</ul>"
            properties += "<br />"

        elif splits[0] == "USER":
            if client_context.bot.has_conversation(client_context):
                conversation = client_context.bot.conversation(client_context)

                properties += "Properties:<br /><ul>"
                for name, value in conversation.properties.items():
                    properties += "<li>%s = %s</li>"%(name, value)
                properties += "</ul>"
                properties += "<br />"

            else:
                properties += "No conversation currently available"

        return properties
コード例 #14
0
 def __init__(self):
     TemplateBotNode.__init__(self)
コード例 #15
0
ファイル: test_bot.py プロジェクト: Freiza/program-y
 def __init__(self):
     TemplateBotNode.__init__(self)
コード例 #16
0
ファイル: properties.py プロジェクト: lilnana00/3ddd
    def execute(self, client_context, data):
        YLogger.debug(client_context, "Properties Admin - [%s]", data)

        properties = ""

        splits = data.split()
        command = splits[0]
        if command == 'GET':

            get_command = splits[1]
            if get_command == 'BOT':
                if len(splits) == 3:
                    var_name = splits[2]
                    properties = TemplateBotNode.get_bot_variable(
                        client_context, var_name)
                else:
                    return "Missing variable name for GET BOT"

            elif get_command == "USER":
                if len(splits) < 3:
                    return "Invalid syntax for GET USER, LOCAL or GLOBAL"

                var_type = splits[2].upper()
                if var_type not in ['LOCAL', 'GLOBAL']:
                    return "Invalid GET USER var type [%s]" % var_type

                if len(splits) < 4:
                    return "Missing variable name for GET USER"
                var_name = splits[3]

                if var_type == 'LOCAL':
                    properties = TemplateGetNode.get_property_value(
                        client_context, True, var_name)

                else:
                    properties = TemplateGetNode.get_property_value(
                        client_context, False, var_name)

            else:
                return "Unknown GET command [%s]" % get_command

        elif command == 'BOT':
            properties += "Properties:<br /><ul>"
            for pair in client_context.brain.properties.pairs:
                properties += "<li>%s = %s</li>" % (pair[0], pair[1])
            properties += "</ul>"
            properties += "<br />"

        elif command == "USER":
            if client_context.bot.has_conversation(client_context):
                conversation = client_context.bot.get_conversation(
                    client_context)

                properties += "Properties:<br /><ul>"
                for name, value in conversation.properties.items():
                    properties += "<li>%s = %s</li>" % (name, value)
                properties += "</ul>"
                properties += "<br />"

            else:
                properties += "No conversation currently available"

        else:
            return "Unknown properties command [%s]" % command

        return properties