sendmsg.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:python-driver 作者: bblfsh 项目源码 文件源码
def main():
    filesidx = 1
    outbuffer = sys.stdout

    files = sys.argv[filesidx:]

    d = {
        'action': 'ParseAST',
        'filepath': '',
        'content': '',
        'language': 'python',
    }

    for f in files:
        content = ''
        logging.info(f)
        for encoding in ('utf_8', 'iso8859_15', 'iso8859_15', 'gb2313',
                         'cp1251', 'cp1252', 'cp1250', 'shift-jis', 'gbk', 'cp1256',
                         'iso8859-2', 'euc_jp', 'big5', 'cp874', 'euc_kr', 'iso8859_7',
                         'cp1255'):
            with open(f, encoding=encoding) as infile:
                try:
                    content = infile.read()
                    break
                except UnicodeDecodeError:
                    continue

        d.update({
            'filepath': f,
            'content': content,
        })

        json.dump(d, sys.stdout, ensure_ascii=False)
        outbuffer.write('\n')
    outbuffer.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号