Beispiel #1
0
def generate_edit_call_form(product, call, call_id):
    count = 1
    if len(call.variables) > 1:
        count = len(call.variables)

    form = add_fields_to_form(count)
    if len(call.variables) > 0:
        for i in range(count):
            temp = getattr(form, 'variable_%i' % i)
            temp_variable = Variable(call.variables[i])
            temp.form.field_type.data = temp_variable.field_type
            temp.form.required.data = temp_variable.required
            temp.form.description.data = temp_variable.description
            temp.form.variable_name.data = temp_variable.variable_name
            temp.form.field_display.data = temp_variable.field_display
            temp.form.field_display_data.data = (
                temp_variable.field_display_data)
            temp.form.id_value.data = temp_variable.id_value

    for key, value in call.__dict__.iteritems():
        if key != 'variables':
            setattr(getattr(form, key), 'data', value)

    form.id.data = call_id
    return form, count
Beispiel #2
0
 def __on_var_created(self, expression, frame, data):
     # Created variable info
     try:
         type = Type.parse(data.type)
         numchild = int(data.numchild)
         name = data.name
         value = [] if numchild else data.value
         # Update the model and notify
         self.vars.add(name, Variable(name, expression, type, children=numchild, data=value, frame=frame))
         self.post_event(GDBEvent(EVT_GDB_UPDATE_VARS, self, data=[name]))
     except Exception, e:
         print "Exception creating variable: %s" % e
         print data
Beispiel #3
0
    def set(self, name, value, group=None, host=None):
        if group:
            item = self.session.query(Group).filter(Group.name == group).one()
        elif host:
            item = self.session.query(Host).filter(Host.name == host).one()

        # find or create the variable
        found = False
        for var in item.variables:
            if var.name == name:
                var.value = value
                self.session.add(var)
                found = True
                break
        if not found:
            var = Variable(name=name, value=value)
            item.variables.append(var)
            self.session.add(item)
        self.session.commit()
Beispiel #4
0
    def __on_var_list_children(self, data):
        kids = []
        updated_kids =[]
        for item in data.children:
            child = item['child']
            numchild = int(child['numchild'])
            value = [] if numchild else child['value']
            type = Type.parse(child['type'])
            expression = child['exp']
            name = child['name']
            parent = GDBVarModel.parent_name(name)
            if name not in self.vars:
                self.vars.add(name, Variable(name, expression, type, children=numchild, data=value))
                updated_kids.append(name)
            kids.append(name)
        if parent:
            self.vars[parent].data = kids

        if updated_kids:
            self.post_event(GDBEvent(EVT_GDB_UPDATE_VARS, self, data=kids))
Beispiel #5
0
def get_vars_for_call(submissions):
    data, count = [], []
    for key, value in submissions:
        temp = re.search('variable_(\d+?)-(\w.*)', key)
        if temp:
            if count:
                if not int(temp.group(1)) in count:
                    count.append(int(temp.group(1)))
            else:
                count.append(int(temp.group(1)))

    for placeholder in range(len(count)):
        data.append({'ignore': 'placeholder'})

    for key, value in submissions:
        temp = re.search('variable_(\d+?)-(\w.*)', key)
        if temp:
            if temp.group(2) != 'csrf_token':
                if str(temp.group(2)) == 'required':
                    if value[0]:
                        data[int(temp.group(1))][str(temp.group(2))] = bool(
                            value[0]
                        )
                elif str(temp.group(2)) == 'id_value':
                    if value[0]:
                        data[int(temp.group(1))][str(temp.group(2))] = int(
                            value[0]
                        )
                else:
                    data[int(temp.group(1))][str(temp.group(2))] = value[0]

    return_data = []
    for variable in data:
        if variable.get('variable_name'):
            temp_var = Variable(variable)
            return_data.append(temp_var.__dict__)

    return return_data
Beispiel #6
0
    def parse_argument(arg: Element) -> InstructionArgument:
        """ Zpracovani parametru instrukce.

        Parameters
        ----------
        arg: Element
            XML element parametru.
        Returns
        -------
        InstructionArgument
            Zpracovany parametr.
        """

        if len(list(arg)) > 0:
            exit_app(exitCodes.INVALID_XML_STRUCT,
                     'Argument contains unexpected elements.', True)

        arg_type = arg.attrib.get('type')
        arg_value = arg.text if arg.text is not None else ''

        if arg_type == ArgumentTypes.LABEL.value:
            InstructionsParser.validate_variable_name(arg_value, True)
            return Label(arg_value)
        elif arg_type == ArgumentTypes.VARIABLE.value:
            variable_parts = arg_value.split('@', 1)

            if len(variable_parts) == 2:
                InstructionsParser.validate_scope(variable_parts[0])
                InstructionsParser.validate_variable_name(variable_parts[1])

                if variable_parts[0] == 'GF':
                    return Variable(Frames.GLOBAL, variable_parts[1])
                elif variable_parts[0] == 'TF':
                    return Variable(Frames.TEMPORARY, variable_parts[1])
                elif variable_parts[0] == 'LF':
                    return Variable(Frames.LOCAL, variable_parts[1])
            else:
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Invalid variable. ({})'.format(arg_value), True)
        elif arg_type == 'nil':
            if arg_value != 'nil':
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Invalid value of nil. ({})'.format(arg_value), True)

            return Symbol(DataTypes.NIL, None)
        elif arg_type == 'int':
            try:
                return Symbol(DataTypes.INT, int(arg_value))
            except ValueError:
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Invalid int value. ({})'.format(arg_value), True)
        elif arg_type == 'bool':
            if arg_value == 'true':
                return Symbol(DataTypes.BOOL, True)
            elif arg_value == 'false':
                return Symbol(DataTypes.BOOL, False)
            else:
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Invalid boolean value. ({})'.format(arg_value), True)
        elif arg_type == 'string':
            if re.compile('.*#.*').match(arg_value):
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Text cannot contains #.', True)

            fixed_string = InstructionsParser.fix_string(arg_value)
            return Symbol(DataTypes.STRING, fixed_string)
        elif arg_type == 'type':
            if arg_value == 'int':
                return Type(int)
            elif arg_value == 'string':
                return Type(str)
            elif arg_value == 'bool':
                return Type(bool)
            elif arg_value == 'float':
                return Type(float)
            else:
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Unknown type value. ({})'.format(arg_value), True)
        elif arg_type == 'float':
            try:
                return Symbol(DataTypes.FLOAT, float.fromhex(arg_value))
            except Exception:
                exit_app(exitCodes.INVALID_XML_STRUCT,
                         'Invalid format of operand.')
        else:
            exit_app(exitCodes.INVALID_XML_STRUCT,
                     'Unknown argument type. ({})'.format(arg_type), True)