本文整理汇总了Python中misc.ustr函数的典型用法代码示例。如果您正苦于以下问题:Python ustr函数的具体用法?Python ustr怎么用?Python ustr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ustr函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_csv_import
def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode="init", noupdate=False):
"""Import csv file :
quote: "
delimiter: ,
encoding: utf-8"""
if not idref:
idref = {}
model = (".".join(fname.split(".")[:-1]).split("-"))[0]
# remove folder path from model
head, model = os.path.split(model)
pool = pooler.get_pool(cr.dbname)
input = cStringIO.StringIO(csvcontent) # FIXME
reader = csv.reader(input, quotechar='"', delimiter=",")
fields = reader.next()
fname_partial = ""
if config.get("import_partial"):
fname_partial = module + "/" + fname
if not os.path.isfile(config.get("import_partial")):
pickle.dump({}, file(config.get("import_partial"), "w+"))
else:
data = pickle.load(file(config.get("import_partial")))
if fname_partial in data:
if not data[fname_partial]:
return
else:
for i in range(data[fname_partial]):
reader.next()
if not (mode == "init" or "id" in fields):
_logger.error("Import specification does not contain 'id' and we are in init mode, Cannot continue.")
return
uid = 1
datas = []
for line in reader:
if (not line) or not reduce(lambda x, y: x or y, line):
continue
try:
datas.append(map(lambda x: misc.ustr(x), line))
except:
_logger.error("Cannot import the line: %s", line)
result, rows, warning_msg, dummy = pool.get(model).import_data(
cr, uid, fields, datas, mode, module, noupdate, filename=fname_partial
)
if result < 0:
# Report failed import and abort module install
raise Exception(
_("Module loading failed: file %s/%s could not be processed:\n %s") % (module, fname, warning_msg)
)
if config.get("import_partial"):
data = pickle.load(file(config.get("import_partial")))
data[fname_partial] = 0
pickle.dump(data, file(config.get("import_partial"), "wb"))
cr.commit()
示例2: convert_csv_import
def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
noupdate=False):
'''Import csv file :
quote: "
delimiter: ,
encoding: utf-8'''
if not idref:
idref={}
model = ('.'.join(fname.split('.')[:-1]).split('-'))[0]
#remove folder path from model
head, model = os.path.split(model)
pool = pooler.get_pool(cr.dbname)
input = cStringIO.StringIO(csvcontent)
reader = csv.reader(input, quotechar='"', delimiter=',')
fields = reader.next()
fname_partial = ""
if config.get('import_partial'):
fname_partial = module + '/'+ fname
if not os.path.isfile(config.get('import_partial')):
pickle.dump({}, file(config.get('import_partial'),'w+'))
else:
data = pickle.load(file(config.get('import_partial')))
if fname_partial in data:
if not data[fname_partial]:
return
else:
for i in range(data[fname_partial]):
reader.next()
if not (mode == 'init' or 'id' in fields):
logger = netsvc.Logger()
logger.notifyChannel("init", netsvc.LOG_ERROR,
"Import specification does not contain 'id' and we are in init mode, Cannot continue.")
return
uid = 1
datas = []
for line in reader:
if (not line) or not reduce(lambda x,y: x or y, line) :
continue
try:
datas.append(map(lambda x: misc.ustr(x), line))
except:
logger = netsvc.Logger()
logger.notifyChannel("init", netsvc.LOG_ERROR, "Cannot import the line: %s" % line)
pool.get(model).import_data(cr, uid, fields, datas,mode, module, noupdate, filename=fname_partial)
if config.get('import_partial'):
data = pickle.load(file(config.get('import_partial')))
data[fname_partial] = 0
pickle.dump(data, file(config.get('import_partial'),'wb'))
cr.commit()
示例3: parse
def parse(self, de):
if de.tag != 'openerp':
raise Exception("Mismatch xml format: root tag must be `openerp`.")
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)
except Exception, e:
self.cr.rollback()
exc_info = sys.exc_info()
raise ParseError, (misc.ustr(e), etree.tostring(rec).rstrip(), rec.getroottree().docinfo.URL, rec.sourceline), exc_info[2]
示例4: parse
def parse(self, de, mode=None):
roots = ['openerp','data','odoo']
if de.tag not in roots:
raise Exception("Root xml tag must be <openerp>, <odoo> or <data>.")
for rec in de:
if rec.tag in roots:
self.parse(rec, mode)
elif rec.tag in self._tags:
try:
self._tags[rec.tag](self.cr, rec, de, mode=mode)
except Exception, e:
self.cr.rollback()
exc_info = sys.exc_info()
raise ParseError, (misc.ustr(e), etree.tostring(rec).rstrip(), rec.getroottree().docinfo.URL, rec.sourceline), exc_info[2]
示例5: convert_xml_import
def convert_xml_import(cr, module, xmlfile, idref=None, mode="init", noupdate=False, report=None):
doc = etree.parse(xmlfile)
relaxng = etree.RelaxNG(etree.parse(os.path.join(config["root_path"], "import_xml.rng")))
try:
relaxng.assert_(doc)
except Exception:
_logger.error("The XML file does not fit the required schema !")
_logger.error(misc.ustr(relaxng.error_log.last_error))
raise
if idref is None:
idref = {}
obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate)
obj.parse(doc.getroot())
return True
示例6: convert_xml_import
def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None):
doc = etree.parse(xmlfile)
relaxng = etree.RelaxNG(
etree.parse(os.path.join(config['root_path'],'import_xml.rng' )))
try:
relaxng.assert_(doc)
except Exception:
_logger.info('The XML file does not fit the required schema !', exc_info=True)
_logger.info(misc.ustr(relaxng.error_log.last_error))
raise
if idref is None:
idref={}
if isinstance(xmlfile, file):
xml_filename = xmlfile.name
else:
xml_filename = xmlfile
obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate, xml_filename=xml_filename)
obj.parse(doc.getroot(), mode=mode)
return True