• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python misc.ustr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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()
开发者ID:ovnicraft,项目名称:openerp-server,代码行数:56,代码来源:convert.py


示例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()
开发者ID:Buyanbat,项目名称:XacCRM,代码行数:53,代码来源:convert.py


示例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]
开发者ID:Alan1590,项目名称:odoo-1,代码行数:13,代码来源:convert.py


示例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]
开发者ID:Ben17000,项目名称:odoo,代码行数:14,代码来源:convert.py


示例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
开发者ID:ovnicraft,项目名称:openerp-server,代码行数:15,代码来源:convert.py


示例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
开发者ID:Ben17000,项目名称:odoo,代码行数:20,代码来源:convert.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python misc.wxstr函数代码示例发布时间:2022-05-27
下一篇:
Python misc.test_setup函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap