diff --git a/bin/osv/orm.py b/bin/osv/orm.py index c8469c1ccc5..35edfe5b654 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1218,7 +1218,7 @@ class orm_template(object): if pos == 'replace': parent = node.getparent() if parent is None: - src = copy.deepcopy(node2.getchildren()[0]) + src = copy.deepcopy(node2[0]) else: for child in node2: node.addprevious(child) @@ -3074,4 +3074,4 @@ class orm(orm_template): return False return True -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/report/printscreen/ps_list.py b/bin/report/printscreen/ps_list.py index 744c2d21709..37a9adda880 100644 --- a/bin/report/printscreen/ps_list.py +++ b/bin/report/printscreen/ps_list.py @@ -36,14 +36,9 @@ class report_printscreen_list(report_int): def _parse_node(self, root_node): result = [] - for node in root_node.getchildren(): + for node in root_node: if node.tag == 'field': - attrsa = node.attrib - attrs = {} - if not attrsa is None: - for key,val in attrsa.items(): - attrs[key] = val - result.append(attrs['name']) + result.append(node.get('name')) else: result.extend(self._parse_node(node)) return result diff --git a/bin/report/render/html2html/html2html.py b/bin/report/render/html2html/html2html.py index fa07e9b4726..9f81e26d4f2 100644 --- a/bin/report/render/html2html/html2html.py +++ b/bin/report/render/html2html/html2html.py @@ -75,7 +75,7 @@ class html2html(object): return self._node def url_modify(self,root): - for n in root.getchildren(): + for n in root: if (n.text.find('=0 or n.text.find('<a')>=0) and n.text.find('href')>=0 and n.text.find('style')<=0 : node = (n.tag=='span' and n.getparent().tag=='u') and n.getparent().getparent() or ((n.tag=='span') and n.getparent()) or n style = node.get('color') and "style='color:%s; text-decoration: none;'"%node.get('color') or '' diff --git a/bin/report/render/rml2html/rml2html.py b/bin/report/render/rml2html/rml2html.py index ea2a5583250..a3a14fc8aee 100644 --- a/bin/report/render/rml2html/rml2html.py +++ b/bin/report/render/rml2html/rml2html.py @@ -296,7 +296,7 @@ class _rml_template(object): posx = int(utils.unit_get(tmpl.get('x1'))) frames[(posy,posx,tmpl.get('id'))] = _rml_tmpl_frame(posx, utils.unit_get(tmpl.get('width'))) for tmpl in pt.findall('pageGraphics'): - for n in tmpl.getchildren(): + for n in tmpl: if n.tag == 'image': self.data = rc + utils._process_text(self, n.text) if n.tag in self._tags: diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index b3585254eb3..b7db9724781 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -88,7 +88,7 @@ class _rml_styles(object,): def _table_style_get(self, style_node): styles = [] - for node in style_node.getchildren(): + for node in style_node: start = utils.tuple_int_get(node, 'start', (0,0) ) stop = utils.tuple_int_get(node, 'stop', (-1,-1) ) if node.tag=='blockValign': @@ -166,7 +166,7 @@ class _rml_doc(object): def _textual_image(self, node): rc = '' - for n in node.getchildren(): + for n in node: rc +=( etree.tostring(n) or '') + n.tail return base64.decodestring(node.tostring()) @@ -749,7 +749,8 @@ class _rml_template(object): frame.lastFrame = True frames.append( frame ) try : - gr = pt.findall('pageGraphics') or pt.getchildren()[1].findall('pageGraphics') + gr = pt.findall('pageGraphics')\ + or pt[1].findall('pageGraphics') except : gr='' if len(gr): diff --git a/bin/report/render/rml2pdf/utils.py b/bin/report/render/rml2pdf/utils.py index abc421a0f2f..bbccd23bb28 100644 --- a/bin/report/render/rml2pdf/utils.py +++ b/bin/report/render/rml2pdf/utils.py @@ -56,7 +56,7 @@ def xml2str(s): def _child_get(node, self=None, tagname=None): for n in node: - if self and self.localcontext and n.get('rml_loop', False): + if self and self.localcontext and n.get('rml_loop'): oldctx = self.localcontext for ctx in eval(n.get('rml_loop'),{}, self.localcontext): @@ -80,12 +80,12 @@ def _child_get(node, self=None, tagname=None): yield n self.localcontext = oldctx continue - if self and self.localcontext and n.get('rml_except', False): + if self and self.localcontext and n.get('rml_except'): try: eval(n.get('rml_except'), {}, self.localcontext) except: continue - if self and self.localcontext and n.get('rml_tag', False): + if self and self.localcontext and n.get('rml_tag'): try: (tag,attr) = eval(n.get('rml_tag'),{}, self.localcontext) n2 = copy.deepcopy(n) @@ -125,10 +125,7 @@ def _process_text(self, txt): return result def text_get(node): - rc = '' - for node in node.getchildren(): - rc = rc + tools.ustr(node.text) - return rc + return ''.join([tools.ustr(n.text) for n in node]) units = [ (re.compile('^(-?[0-9\.]+)\s*in$'), reportlab.lib.units.inch), @@ -158,8 +155,7 @@ def unit_get(size): def tuple_int_get(node, attr_name, default=None): if not node.get(attr_name): return default - res = [int(x) for x in node.get(attr_name).split(',')] - return res + return map(int, node.get(attr_name).split(',')) def bool_get(value): return (str(value)=="1") or (value.lower()=='yes') diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index 1adca0b8176..0364511da13 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -303,7 +303,7 @@ class rml_parse(object): rml_head = rml_head.replace('','') head_dom = etree.XML(rml_head) - for tag in head_dom.getchildren(): + for tag in head_dom: found = rml_dom.find('.//'+tag.tag) if found is not None and len(found): if tag.get('position'): @@ -462,13 +462,14 @@ class report_sxw(report_rml, preprocess.report): for pe in elements: if pe.get(rml_parser.localcontext['name_space']["meta"]+"name"): if pe.get(rml_parser.localcontext['name_space']["meta"]+"name") == "Info 3": - pe.getchildren()[0].text=data['id'] + pe[0].text=data['id'] if pe.get(rml_parser.localcontext['name_space']["meta"]+"name") == "Info 4": - pe.getchildren()[0].text=data['model'] - meta = etree.tostring(rml_dom_meta) + pe[0].text=data['model'] + meta = etree.tostring(rml_dom_meta, encoding='utf-8', + xml_declaration=True) rml_dom = etree.XML(rml) - body = rml_dom.getchildren()[-1] + body = rml_dom[-1] elements = [] key1 = rml_parser.localcontext['name_space']["text"]+"p" key2 = rml_parser.localcontext['name_space']["text"]+"drop-down" @@ -482,7 +483,7 @@ class report_sxw(report_rml, preprocess.report): pp=de.getparent() if de.text or de.tail: pe.text = de.text or de.tail - for cnd in de.getchildren(): + for cnd in de: if cnd.text or cnd.tail: if pe.text: pe.text += cnd.text or cnd.tail @@ -508,12 +509,11 @@ class report_sxw(report_rml, preprocess.report): rml_dom = self.preprocess_rml(rml_dom,report_type) create_doc = self.generators[report_type] - odt = etree.tostring(create_doc(rml_dom, rml_parser.localcontext)) + odt = etree.tostring(create_doc(rml_dom, rml_parser.localcontext), + encoding='utf-8', xml_declaration=True) sxw_z = zipfile.ZipFile(sxw_io, mode='a') - sxw_z.writestr('content.xml', "" + \ - odt) - sxw_z.writestr('meta.xml', "" + \ - meta) + sxw_z.writestr('content.xml', odt) + sxw_z.writestr('meta.xml', meta) if report_xml.header: #Add corporate header/footer @@ -528,9 +528,9 @@ class report_sxw(report_rml, preprocess.report): odt = create_doc(rml_dom,rml_parser.localcontext) if report_xml.header: rml_parser._add_header(odt) - odt = etree.tostring(odt) - sxw_z.writestr('styles.xml',"" + \ - odt) + odt = etree.tostring(odt, encoding='utf-8', + xml_declaration=True) + sxw_z.writestr('styles.xml', odt) sxw_z.close() final_op = sxw_io.getvalue() sxw_io.close() diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 749867c3862..f48cb8e4817 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -57,17 +57,16 @@ def _eval_xml(self,node, pool, cr, uid, idref, context=None): if context is None: context = {} if node.tag in ('field','value'): - t = node.get('type','') or 'char' - f_model = node.get("model", '').encode('ascii') - if len(node.get('search','')): + t = node.get('type','char') + f_model = node.get('model', '').encode('ascii') + if node.get('search'): f_search = node.get("search",'').encode('utf-8') - f_use = node.get("use",'').encode('ascii') + f_use = node.get("use",'id').encode('ascii') f_name = node.get("name",'').encode('utf-8') - if len(f_use)==0: - f_use = "id" + q = eval(f_search, idref) ids = pool.get(f_model).search(cr, uid, q) - if f_use<>'id': + if f_use != 'id': ids = map(lambda x: x[f_use], pool.get(f_model).read(cr, uid, ids, [f_use])) _cols = pool.get(f_model)._columns if (f_name in _cols) and _cols[f_name]._type=='many2many': @@ -79,7 +78,7 @@ def _eval_xml(self,node, pool, cr, uid, idref, context=None): f_val = f_val[0] return f_val a_eval = node.get('eval','') - if len(a_eval): + if a_eval: import time from mx import DateTime idref2 = idref.copy() @@ -107,54 +106,53 @@ def _eval_xml(self,node, pool, cr, uid, idref, context=None): if not id in idref: idref[id]=self.id_get(cr, False, id) return s % idref - txt = '\n'+_process("".join([etree.tostring(i).encode("utf8") for i in node.getchildren()]), idref) - return txt + return '\n'\ + +_process("".join([etree.tostring(n, encoding='utf-8') + for n in node]), + idref) if t in ('char', 'int', 'float'): - d = "" d = node.text if t == 'int': d = d.strip() - if d=='None': + if d == 'None': return None else: - d=int(d.strip()) - elif t=='float': - d=float(d.strip()) + return int(d.strip()) + elif t == 'float': + return float(d.strip()) return d elif t in ('list','tuple'): res=[] - for n in [i for i in node.getchildren() if (i.tag=='value')]: + for n in node.findall('./value'): res.append(_eval_xml(self,n,pool,cr,uid,idref)) if t=='tuple': return tuple(res) return res elif node.tag == "getitem": - for n in [i for i in node.getchildren()]: + for n in node: res=_eval_xml(self,n,pool,cr,uid,idref) if not res: raise LookupError - elif node.get('type','') in ("int", "list"): - return res[int(node.get('index',''))] + elif node.get('type') in ("int", "list"): + return res[int(node.get('index'))] else: return res[node.get('index','').encode("utf8")] elif node.tag == "function": args = [] a_eval = node.get('eval','') - if len(a_eval): + if a_eval: idref['ref'] = lambda x: self.id_get(cr, False, x) args = eval(a_eval, idref) - for n in [i for i in node.getchildren()]: + for n in node: return_val = _eval_xml(self,n, pool, cr, uid, idref, context) - if return_val != None: + if return_val is not None: args.append(return_val) model = pool.get(node.get('model','')) method = node.get('name','') res = getattr(model, method)(cr, uid, *args) return res elif node.tag == "test": - d = node.text - return d - + return node.text escape_re = re.compile(r'(? 0,\ + 'You must define a child node if you dont give a ref' + assert number_children == 1,\ + 'Only one child node is accepted (%d given)' % number_children + id = _eval_xml(self, rec[0], self.pool, cr, self.uid, self.idref) uid = self.get_uid(cr, self.uid, data_node, rec) wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, model, id, str(rec.get('action','')), cr) - return False # # Support two types of notation: @@ -496,7 +490,7 @@ form: module.record_id""" % (xml_id,) menu_parent_id = self.id_get(cr, 'ir.ui.menu', rec.get('parent','')) values = {'parent_id': menu_parent_id} if rec.get('name'): - values['name'] = rec.get('name','') + values['name'] = rec.get('name') try: res = [ self.id_get(cr, 'ir.ui.menu', rec.get('id','')) ] except: @@ -544,9 +538,9 @@ form: module.record_id""" % (xml_id,) if (not values.get('name', False)) and resw: values['name'] = resw[0] if rec.get('sequence'): - values['sequence'] = int(rec.get('sequence','')) + values['sequence'] = int(rec.get('sequence')) if rec.get('icon'): - values['icon'] = str(rec.get('icon','')) + values['icon'] = str(rec.get('icon')) if rec.get('groups'): g_names = rec.get('groups','').split(',') @@ -569,7 +563,7 @@ form: module.record_id""" % (xml_id,) self.idref[rec_id] = int(pid) if rec.get('action') and pid: - a_action = rec.get('action','').encode('utf8') + a_action = rec.get('action').encode('utf8') a_type = rec.get('type','').encode('utf8') or 'act_window' a_id = self.id_get(cr, 'ir.actions.%s' % a_type, a_action) action = "ir.actions.%s,%d" % (a_type, a_id) @@ -589,7 +583,7 @@ form: module.record_id""" % (xml_id,) rec_id = rec.get("id",'').encode('ascii') self._test_xml_id(rec_id) rec_src = rec.get("search",'').encode('utf8') - rec_src_count = rec.get("count",'') + rec_src_count = rec.get("count") severity = rec.get("severity",'').encode('ascii') or netsvc.LOG_ERROR @@ -599,12 +593,12 @@ form: module.record_id""" % (xml_id,) eval_dict = {'ref': _ref(self, cr)} context = self.get_context(data_node, rec, eval_dict) uid = self.get_uid(cr, self.uid, data_node, rec) - if len(rec_id): + if rec_id: ids = [self.id_get(cr, rec_model, rec_id)] - elif len(rec_src): + elif rec_src: q = eval(rec_src, eval_dict) ids = self.pool.get(rec_model).search(cr, uid, q, context=context) - if len(rec_src_count): + if rec_src_count: count = int(rec_src_count) if len(ids) != count: self.assert_report.record_assertion(False, severity) @@ -620,8 +614,8 @@ form: module.record_id""" % (xml_id,) raise Exception('Severe assertion failure') return - assert ids != None, 'You must give either an id or a search criteria' - + assert ids is not None,\ + 'You must give either an id or a search criteria' ref = _ref(self, cr) for id in ids: brrec = model.browse(cr, uid, id, context) @@ -634,7 +628,7 @@ form: module.record_id""" % (xml_id,) globals['floatEqual'] = self._assert_equals globals['ref'] = ref globals['_ref'] = ref - for test in [i for i in rec.getchildren() if (i.tag=="test")]: + for test in rec.findall('./test'): f_expr = test.get("expr",'').encode('utf-8') expected_value = _eval_xml(self, test, self.pool, cr, uid, self.idref, context=context) or True expression_value = eval(f_expr, globals) @@ -686,7 +680,7 @@ form: module.record_id""" % (xml_id,) # otherwise it is skipped return None res = {} - for field in [i for i in rec.getchildren() if (i.tag == "field")]: + for field in rec.findall('./field'): #TODO: most of this code is duplicated above (in _eval_xml)... f_name = field.get("name",'').encode('utf-8') f_ref = field.get("ref",'').encode('ascii') @@ -697,7 +691,7 @@ form: module.record_id""" % (xml_id,) f_use = field.get("use",'').encode('ascii') or 'id' f_val = False - if len(f_search): + if f_search: q = eval(f_search, self.idref) field = [] assert f_model, 'Define an attribute model="..." in your .XML file !' @@ -713,7 +707,7 @@ form: module.record_id""" % (xml_id,) # otherwise (we are probably in a many2one field), # take the first element of the search f_val = s[0][f_use] - elif len(f_ref): + elif f_ref: if f_ref=="null": f_val = False else: @@ -741,9 +735,7 @@ form: module.record_id""" % (xml_id,) result = self.pool.get('ir.model.data')._get_id(cr, self.uid, mod, id_str) return int(self.pool.get('ir.model.data').read(cr, self.uid, [result], ['res_id'])[0]['res_id']) - def parse(self, xmlstr): - de = etree.XML(xmlstr) - + def parse(self, de): if not de.tag in ['terp', 'openerp']: self.logger.notifyChannel("init", netsvc.LOG_ERROR, "Mismatch xml format" ) raise Exception( "Mismatch xml format: only terp or openerp as root tag" ) @@ -751,8 +743,8 @@ form: module.record_id""" % (xml_id,) if de.tag == 'terp': self.logger.notifyChannel("init", netsvc.LOG_WARNING, "The tag is deprecated, use ") - for n in [i for i in de.getchildren() if (i.tag=="data")]: - for rec in n.getchildren(): + for n in de.findall('./data'): + for rec in n: if rec.tag in self._tags: try: self._tags[rec.tag](self.cr, rec, n) @@ -844,12 +836,9 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', # xml import/export # def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None): - xmlstr = xmlfile.read() - xmlfile.seek(0) - relaxng_doc = etree.parse(file(os.path.join( config['root_path'], 'import_xml.rng' ))) - relaxng = etree.RelaxNG(relaxng_doc) - doc = etree.parse(xmlfile) + relaxng = etree.RelaxNG( + etree.parse(os.path.join(config['root_path'],'import_xml.rng' ))) try: relaxng.assert_(doc) except Exception, e: @@ -861,8 +850,7 @@ def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=Fa if idref is None: idref={} obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate) - obj.parse(xmlstr) - del obj + obj.parse(doc.getroot()) return True def convert_xml_export(res): diff --git a/bin/tools/translate.py b/bin/tools/translate.py index ca833dfee6e..1080b10eca3 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -343,9 +343,9 @@ def trans_export(lang, modules, buffer, format, dbname=None): def trans_parse_xsl(de): res = [] - for n in [i for i in de.getchildren()]: + for n in de: if n.get("t"): - for m in [j for j in n.getchildren() if j.text]: + for m in [j for j in n if j.text]: l = m.text.strip().replace('\n',' ') if len(l): res.append(l.encode("utf8")) @@ -354,8 +354,8 @@ def trans_parse_xsl(de): def trans_parse_rml(de): res = [] - for n in [i for i in de.getchildren()]: - for m in [j for j in n.getchildren() if j.text]: + for n in de: + for m in [j for j in n if j.text]: string_list = [s.replace('\n', ' ').strip() for s in re.split('\[\[.+?\]\]', m.text)] for s in string_list: if s: @@ -366,14 +366,10 @@ def trans_parse_rml(de): def trans_parse_view(de): res = [] if de.get("string"): - s = de.get('string') - if s: - res.append(s.encode("utf8")) + res.append(de.get('string').encode("utf8")) if de.get("sum"): - s = de.get('sum') - if s: - res.append(s.encode("utf8")) - for n in [i for i in de.getchildren()]: + res.append(de.get('sum').encode("utf8")) + for n in de: res.extend(trans_parse_view(n)) return res diff --git a/bin/wizard/__init__.py b/bin/wizard/__init__.py index 378f9ac4563..428a85537db 100644 --- a/bin/wizard/__init__.py +++ b/bin/wizard/__init__.py @@ -54,7 +54,7 @@ class interface(netsvc.Service): trans = translate(cr, self.wiz_name+','+state, 'wizard_view', lang, node.get('string').encode('utf8')) if trans: node.set('string', trans) - for n in node.getchildren(): + for n in node: self.translate_view(cr, n, state, lang) def execute_cr(self, cr, uid, data, state='init', context=None):