当前位置: 首页>>代码示例>>Python>>正文


Python safe_eval.eval函数代码示例

本文整理汇总了Python中safe_eval.eval函数的典型用法代码示例。如果您正苦于以下问题:Python eval函数的具体用法?Python eval怎么用?Python eval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了eval函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _eval_params

 def _eval_params(self, model, params):
     args = []
     for i, param in enumerate(params):
         if isinstance(param, types.ListType):
             value = self._eval_params(model, param)
         elif is_ref(param):
             value = self.process_ref(param)
         elif is_eval(param):
             value = self.process_eval(param)
         elif isinstance(param, types.DictionaryType): # supports XML syntax
             param_model = self.get_model(param.get('model', model))
             if 'search' in param:
                 q = eval(param['search'], self.eval_context)
                 ids = param_model.search(self.cr, self.uid, q)
                 value = self._get_first_result(ids)
             elif 'eval' in param:
                 local_context = {'obj': lambda x: param_model.browse(self.cr, self.uid, x, self.context)}
                 local_context.update(self.id_map)
                 value = eval(param['eval'], self.eval_context, local_context)
             else:
                 raise YamlImportException('You must provide either a !ref or at least a "eval" or a "search" to function parameter #%d.' % i)
         else:
             value = param # scalar value
         args.append(value)
     return args
开发者ID:AbdAllah-Ahmed,项目名称:openerp-env,代码行数:25,代码来源:yaml_import.py

示例2: process_report

    def process_report(self, node):
        values = {}
        for dest, f in (("name", "string"), ("model", "model"), ("report_name", "name")):
            values[dest] = getattr(node, f)
            assert values[dest], "Attribute %s of report is empty !" % (f,)
        for field, dest in (
            ("rml", "report_rml"),
            ("file", "report_rml"),
            ("xml", "report_xml"),
            ("xsl", "report_xsl"),
            ("attachment", "attachment"),
            ("attachment_use", "attachment_use"),
        ):
            if getattr(node, field):
                values[dest] = getattr(node, field)
        if node.auto:
            values["auto"] = eval(node.auto)
        if node.sxw:
            sxw_file = misc.file_open(node.sxw)
            try:
                sxw_content = sxw_file.read()
                values["report_sxw_content"] = sxw_content
            finally:
                sxw_file.close()
        if node.header:
            values["header"] = eval(node.header)
        values["multi"] = node.multi and eval(node.multi)
        xml_id = node.id
        self.validate_xml_id(xml_id)

        self._set_group_values(node, values)

        id = self.pool["ir.model.data"]._update(
            self.cr,
            SUPERUSER_ID,
            "ir.actions.report.xml",
            self.module,
            values,
            xml_id,
            noupdate=self.isnoupdate(node),
            mode=self.mode,
        )
        self.id_map[xml_id] = int(id)

        if not node.menu or eval(node.menu):
            keyword = node.keyword or "client_print_multi"
            value = "ir.actions.report.xml,%s" % id
            replace = node.replace or True
            self.pool["ir.model.data"].ir_set(
                self.cr,
                SUPERUSER_ID,
                "action",
                keyword,
                values["name"],
                [values["model"]],
                value,
                replace=replace,
                isobject=True,
                xml_id=xml_id,
            )
开发者ID:tomisweet,项目名称:odoo,代码行数:60,代码来源:yaml_import.py

示例3: _tag_wizard

    def _tag_wizard(self, cr, rec, data_node=None):
        string = rec.get("string",'').encode('utf8')
        model = rec.get("model",'').encode('utf8')
        name = rec.get("name",'').encode('utf8')
        xml_id = rec.get('id','').encode('utf8')
        self._test_xml_id(xml_id)
        multi = rec.get('multi','') and eval(rec.get('multi','False'))
        res = {'name': string, 'wiz_name': name, 'multi': multi, 'model': model}

        if rec.get('groups'):
            g_names = rec.get('groups','').split(',')
            groups_value = []
            for group in g_names:
                if group.startswith('-'):
                    group_id = self.id_get(cr, group[1:])
                    groups_value.append((3, group_id))
                else:
                    group_id = self.id_get(cr, group)
                    groups_value.append((4, group_id))
            res['groups_id'] = groups_value

        id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.wizard", self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
        self.idref[xml_id] = int(id)
        # ir_set
        if (not rec.get('menu') or eval(rec.get('menu','False'))) and id:
            keyword = str(rec.get('keyword','') or 'client_action_multi')
            value = 'ir.actions.wizard,'+str(id)
            replace = rec.get("replace",'') or True
            self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', keyword, string, [model], value, replace=replace, isobject=True, xml_id=xml_id)
        elif self.mode=='update' and (rec.get('menu') and eval(rec.get('menu','False'))==False):
            # Special check for wizard having attribute menu=False on update
            value = 'ir.actions.wizard,'+str(id)
            self._remove_ir_values(cr, string, value, model)
开发者ID:ccdos,项目名称:OpenERP,代码行数:33,代码来源:convert.py

示例4: process_report

    def process_report(self, node):
        values = {}
        for dest, f in (('name','string'), ('model','model'), ('report_name','name')):
            values[dest] = getattr(node, f)
            assert values[dest], "Attribute %s of report is empty !" % (f,)
        for field,dest in (('rml','report_rml'),('file','report_rml'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment'),('attachment_use','attachment_use')):
            if getattr(node, field):
                values[dest] = getattr(node, field)
        if node.auto:
            values['auto'] = eval(node.auto)
        if node.sxw:
            sxw_file = misc.file_open(node.sxw)
            try:
                sxw_content = sxw_file.read()
                values['report_sxw_content'] = sxw_content
            finally:
                sxw_file.close()
        if node.header:
            values['header'] = eval(node.header)
        values['multi'] = node.multi and eval(node.multi)
        xml_id = node.id
        self.validate_xml_id(xml_id)

        self._set_group_values(node, values)

        id = self.pool.get('ir.model.data')._update(self.cr, SUPERUSER_ID, "ir.actions.report.xml", \
                self.module, values, xml_id, noupdate=self.isnoupdate(node), mode=self.mode)
        self.id_map[xml_id] = int(id)

        if not node.menu or eval(node.menu):
            keyword = node.keyword or 'client_print_multi'
            value = 'ir.actions.report.xml,%s' % id
            replace = node.replace or True
            self.pool.get('ir.model.data').ir_set(self.cr, SUPERUSER_ID, 'action', \
                    keyword, values['name'], [values['model']], value, replace=replace, isobject=True, xml_id=xml_id)
开发者ID:AbdAllah-Ahmed,项目名称:openerp-env,代码行数:35,代码来源:yaml_import.py

示例5: _tag_report

    def _tag_report(self, cr, rec, data_node=None, mode=None):
        res = {}
        for dest,f in (('name','string'),('model','model'),('report_name','name')):
            res[dest] = rec.get(f,'').encode('utf8')
            assert res[dest], "Attribute %s of report is empty !" % (f,)
        for field,dest in (('rml','report_rml'),('file','report_rml'),('xml','report_xml'),('xsl','report_xsl'),
                           ('attachment','attachment'),('attachment_use','attachment_use'), ('usage','usage'),
                           ('report_type', 'report_type'), ('parser', 'parser')):
            if rec.get(field):
                res[dest] = rec.get(field).encode('utf8')
        if rec.get('auto'):
            res['auto'] = eval(rec.get('auto','False'))
        if rec.get('sxw'):
            sxw_content = misc.file_open(rec.get('sxw')).read()
            res['report_sxw_content'] = sxw_content
        if rec.get('header'):
            res['header'] = eval(rec.get('header','False'))

        res['multi'] = rec.get('multi') and eval(rec.get('multi','False'))

        xml_id = rec.get('id','').encode('utf8')
        self._test_xml_id(xml_id)

        if rec.get('groups'):
            g_names = rec.get('groups','').split(',')
            groups_value = []
            for group in g_names:
                if group.startswith('-'):
                    group_id = self.id_get(cr, group[1:])
                    groups_value.append((3, group_id))
                else:
                    group_id = self.id_get(cr, group)
                    groups_value.append((4, group_id))
            res['groups_id'] = groups_value
        if rec.get('paperformat'):
            pf_name = rec.get('paperformat')
            pf_id = self.id_get(cr,pf_name)
            res['paperformat_id'] = pf_id

        id = self.pool['ir.model.data']._update(cr, self.uid, "ir.actions.report.xml", self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
        self.idref[xml_id] = int(id)

        if not rec.get('menu') or eval(rec.get('menu','False')):
            keyword = str(rec.get('keyword', 'client_print_multi'))
            value = 'ir.actions.report.xml,'+str(id)
            ir_values_id = self.pool['ir.values'].set_action(cr, self.uid, res['name'], keyword, res['model'], value)
            self.pool['ir.actions.report.xml'].write(cr, self.uid, id, {'ir_values_id': ir_values_id})
        elif self.mode=='update' and eval(rec.get('menu','False'))==False:
            # Special check for report having attribute menu=False on update
            value = 'ir.actions.report.xml,'+str(id)
            self._remove_ir_values(cr, res['name'], value, res['model'])
            self.pool['ir.actions.report.xml'].write(cr, self.uid, id, {'ir_values_id': False})
        return id
开发者ID:Ben17000,项目名称:odoo,代码行数:53,代码来源:convert.py

示例6: process_ref

 def process_ref(self, node, field=None):
     assert node.search or node.id, '!ref node should have a `search` attribute or `id` attribute'
     if node.search:
         if node.model:
             model_name = node.model
         elif field:
             model_name = field.comodel_name
         else:
             raise YamlImportException('You need to give a model for the search, or a field to infer it.')
         model = self.get_model(model_name)
         q = eval(node.search, self.eval_context)
         ids = model.search(self.cr, self.uid, q)
         if node.use:
             instances = model.browse(self.cr, self.uid, ids)
             value = [inst[node.use] for inst in instances]
         else:
             value = ids
     elif node.id:
         if field and field.type == 'reference':
             record = self.get_record(node.id)
             value = "%s,%s" % (record._name, record.id)
         else:
             value = self.get_id(node.id)
     else:
         value = None
     return value
开发者ID:golivecloud,项目名称:clouderp,代码行数:26,代码来源:yaml_import.py

示例7: process_url

    def process_url(self, node):
        self.validate_xml_id(node.id)

        res = {"name": node.name, "url": node.url, "target": node.target}

        id = self.pool["ir.model.data"]._update(
            self.cr, SUPERUSER_ID, "ir.actions.act_url", self.module, res, node.id, mode=self.mode
        )
        self.id_map[node.id] = int(id)
        # ir_set
        if (not node.menu or eval(node.menu)) and id:
            keyword = node.keyword or "client_action_multi"
            value = "ir.actions.act_url,%s" % id
            replace = node.replace or True
            self.pool["ir.model.data"].ir_set(
                self.cr,
                SUPERUSER_ID,
                "action",
                keyword,
                node.url,
                ["ir.actions.act_url"],
                value,
                replace=replace,
                noupdate=self.isnoupdate(node),
                isobject=True,
                xml_id=node.id,
            )
开发者ID:tomisweet,项目名称:odoo,代码行数:27,代码来源:yaml_import.py

示例8: process_workflow

    def process_workflow(self, node):
        workflow, values = node.items()[0]
        if self.isnoupdate(workflow) and self.mode != "init":
            return
        if workflow.ref:
            id = self.get_id(workflow.ref)
        else:
            if not values:
                raise YamlImportException("You must define a child node if you do not give a ref.")
            if not len(values) == 1:
                raise YamlImportException("Only one child node is accepted (%d given)." % len(values))
            value = values[0]
            if not "model" in value and (not "eval" in value or not "search" in value):
                raise YamlImportException('You must provide a "model" and an "eval" or "search" to evaluate.')
            value_model = self.get_model(value["model"])
            local_context = {"obj": lambda x: value_model.browse(self.cr, self.uid, x, context=self.context)}
            local_context.update(self.id_map)
            id = eval(value["eval"], self.eval_context, local_context)

        if workflow.uid is not None:
            uid = workflow.uid
        else:
            uid = self.uid
        self.cr.execute("select distinct signal, sequence, id from wkf_transition ORDER BY sequence,id")
        signals = [x["signal"] for x in self.cr.dictfetchall()]
        if workflow.action not in signals:
            raise YamlImportException("Incorrect action %s. No such action defined" % workflow.action)
        openerp.workflow.trg_validate(uid, workflow.model, id, workflow.action, self.cr)
开发者ID:tomisweet,项目名称:odoo,代码行数:28,代码来源:yaml_import.py

示例9: process_workflow

    def process_workflow(self, node):
        workflow, values = node.items()[0]
        if self.isnoupdate(workflow) and self.mode != 'init':
            return
        if workflow.ref:
            id = self.get_id(workflow.ref)
        else:
            if not values:
                raise YamlImportException('You must define a child node if you do not give a ref.')
            if not len(values) == 1:
                raise YamlImportException('Only one child node is accepted (%d given).' % len(values))
            value = values[0]
            if not 'model' in value and (not 'eval' in value or not 'search' in value):
                raise YamlImportException('You must provide a "model" and an "eval" or "search" to evaluate.')
            value_model = self.get_model(value['model'])
            local_context = {'obj': lambda x: value_model.browse(self.cr, self.uid, x, context=self.context)}
            local_context.update(self.id_map)
            id = eval(value['eval'], self.eval_context, local_context)

        if workflow.uid is not None:
            uid = workflow.uid
        else:
            uid = self.uid
        self.cr.execute('select distinct signal from wkf_transition')
        signals=[x['signal'] for x in self.cr.dictfetchall()]
        if workflow.action not in signals:
            raise YamlImportException('Incorrect action %s. No such action defined' % workflow.action)
        import openerp.netsvc as netsvc
        wf_service = netsvc.LocalService("workflow")
        wf_service.trg_validate(uid, workflow.model, id, workflow.action, self.cr)
开发者ID:AbdAllah-Ahmed,项目名称:openerp-env,代码行数:30,代码来源:yaml_import.py

示例10: run

 def run(self, cr, uid, ids, context=None):
     "Run fix for 'other' type actions"
     act_ids = []
     for action in self.browse(cr, uid, ids, context):
         obj_pool = self.pool.get(action.model_id.model)
         obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
         cxt = {
             'context': context,
             'object': obj,
             'time': time,
             'cr': cr,
             'pool': self.pool,
             'uid': uid
         }
         expr = eval(str(action.condition), cxt)
         if not expr:
             continue
         if action.state == 'other':
             res = []
             for act in action.child_ids:
                 if not context.get('active_id'):
                     context['active_id'] = context['active_ids'][0]
                 result = self.run(cr, uid, [act.id], context)
                 if result:
                     res.append(result)
             return res
     else:
         act_ids.append(action.id)
     if act_ids:
         return super(IrActionsServer, self).run(cr, uid, act_ids, context)
     else:
         return False
开发者ID:tejastank,项目名称:smile_openerp_addons_6.0,代码行数:32,代码来源:ir_actions_patch.py

示例11: _get_assertion_id

 def _get_assertion_id(self, assertion):
     if assertion.id:
         ids = [self.get_id(assertion.id)]
     elif assertion.search:
         q = eval(assertion.search, self.eval_context)
         ids = self.pool.get(assertion.model).search(self.cr, self.uid, q, context=assertion.context)
     else:
         raise YamlImportException('Nothing to assert: you must give either an id or a search criteria.')
     return ids
开发者ID:AbdAllah-Ahmed,项目名称:openerp-env,代码行数:9,代码来源:yaml_import.py

示例12: _tag_wizard

    def _tag_wizard(self, cr, rec, data_node=None):
        string = rec.get("string", "").encode("utf8")
        model = rec.get("model", "").encode("utf8")
        name = rec.get("name", "").encode("utf8")
        xml_id = rec.get("id", "").encode("utf8")
        self._test_xml_id(xml_id)
        multi = rec.get("multi", "") and eval(rec.get("multi", "False"))
        res = {"name": string, "wiz_name": name, "multi": multi, "model": model}

        if rec.get("groups"):
            g_names = rec.get("groups", "").split(",")
            groups_value = []
            for group in g_names:
                if group.startswith("-"):
                    group_id = self.id_get(cr, group[1:])
                    groups_value.append((3, group_id))
                else:
                    group_id = self.id_get(cr, group)
                    groups_value.append((4, group_id))
            res["groups_id"] = groups_value

        id = self.pool.get("ir.model.data")._update(
            cr,
            self.uid,
            "ir.actions.wizard",
            self.module,
            res,
            xml_id,
            noupdate=self.isnoupdate(data_node),
            mode=self.mode,
        )
        self.idref[xml_id] = int(id)
        # ir_set
        if (not rec.get("menu") or eval(rec.get("menu", "False"))) and id:
            keyword = str(rec.get("keyword", "") or "client_action_multi")
            value = "ir.actions.wizard," + str(id)
            replace = rec.get("replace", "") or True
            self.pool.get("ir.model.data").ir_set(
                cr, self.uid, "action", keyword, string, [model], value, replace=replace, isobject=True, xml_id=xml_id
            )
        elif self.mode == "update" and (rec.get("menu") and eval(rec.get("menu", "False")) == False):
            # Special check for wizard having attribute menu=False on update
            value = "ir.actions.wizard," + str(id)
            self._remove_ir_values(cr, string, value, model)
开发者ID:ovnicraft,项目名称:openerp-server,代码行数:44,代码来源:convert.py

示例13: process_delete

 def process_delete(self, node):
     assert getattr(node, 'model'), "Attribute %s of delete tag is empty !" % ('model',)
     if self.pool.get(node.model):
         if node.search:
             ids = self.pool.get(node.model).search(self.cr, self.uid, eval(node.search, self.eval_context))
         else:
             ids = [self.get_id(node.id)]
         if len(ids):
             self.pool.get(node.model).unlink(self.cr, self.uid, ids)
     else:
         self._log("Record not deleted.")
开发者ID:AbdAllah-Ahmed,项目名称:openerp-env,代码行数:11,代码来源:yaml_import.py

示例14: _tag_url

    def _tag_url(self, cr, rec, data_node=None):
        url = rec.get("url", "").encode("utf8")
        target = rec.get("target", "").encode("utf8")
        name = rec.get("name", "").encode("utf8")
        xml_id = rec.get("id", "").encode("utf8")
        self._test_xml_id(xml_id)

        res = {"name": name, "url": url, "target": target}

        id = self.pool.get("ir.model.data")._update(
            cr,
            self.uid,
            "ir.actions.url",
            self.module,
            res,
            xml_id,
            noupdate=self.isnoupdate(data_node),
            mode=self.mode,
        )
        self.idref[xml_id] = int(id)
        # ir_set
        if (not rec.get("menu") or eval(rec.get("menu", "False"))) and id:
            keyword = str(rec.get("keyword", "") or "client_action_multi")
            value = "ir.actions.url," + str(id)
            replace = rec.get("replace", "") or True
            self.pool.get("ir.model.data").ir_set(
                cr,
                self.uid,
                "action",
                keyword,
                url,
                ["ir.actions.url"],
                value,
                replace=replace,
                isobject=True,
                xml_id=xml_id,
            )
        elif self.mode == "update" and (rec.get("menu") and eval(rec.get("menu", "False")) == False):
            # Special check for URL having attribute menu=False on update
            value = "ir.actions.url," + str(id)
            self._remove_ir_values(cr, url, value, "ir.actions.url")
开发者ID:hifly,项目名称:enapps-openerp-server,代码行数:41,代码来源:convert.py

示例15: process_act_window

    def process_act_window(self, node):
        assert getattr(node, "id"), "Attribute %s of act_window is empty !" % ("id",)
        assert getattr(node, "name"), "Attribute %s of act_window is empty !" % ("name",)
        assert getattr(node, "res_model"), "Attribute %s of act_window is empty !" % ("res_model",)
        self.validate_xml_id(node.id)
        view_id = False
        if node.view:
            view_id = self.get_id(node.view)
        if not node.context:
            node.context = {}
        context = eval(str(node.context), self.eval_context)
        values = {
            "name": node.name,
            "type": node.type or "ir.actions.act_window",
            "view_id": view_id,
            "domain": node.domain,
            "context": context,
            "res_model": node.res_model,
            "src_model": node.src_model,
            "view_type": node.view_type or "form",
            "view_mode": node.view_mode or "tree,form",
            "usage": node.usage,
            "limit": node.limit,
            "auto_refresh": node.auto_refresh,
            "multi": getattr(node, "multi", False),
        }

        self._set_group_values(node, values)

        if node.target:
            values["target"] = node.target
        id = self.pool["ir.model.data"]._update(
            self.cr, SUPERUSER_ID, "ir.actions.act_window", self.module, values, node.id, mode=self.mode
        )
        self.id_map[node.id] = int(id)

        if node.src_model:
            keyword = "client_action_relate"
            value = "ir.actions.act_window,%s" % id
            replace = node.replace or True
            self.pool["ir.model.data"].ir_set(
                self.cr,
                SUPERUSER_ID,
                "action",
                keyword,
                node.id,
                [node.src_model],
                value,
                replace=replace,
                noupdate=self.isnoupdate(node),
                isobject=True,
                xml_id=node.id,
            )
开发者ID:tomisweet,项目名称:odoo,代码行数:53,代码来源:yaml_import.py


注:本文中的safe_eval.eval函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。