onlineinclude.py 文件源码

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

项目:SuperOcto 作者: mcecchi 项目源码 文件源码
def read_with_encoding(self, filename, document, codec_info, encoding):
        global cache

        f = None
        try:
            if not self.arguments[0] in cache:
                f = codecs.StreamReaderWriter(urllib2.urlopen(self.arguments[0]), codec_info[2],
                                              codec_info[3], 'strict')
                lines = f.readlines()
                cache[self.arguments[0]] = lines
            else:
                lines = cache[self.arguments[0]]

            lines = dedent_lines(lines, self.options.get('dedent'))
            return lines
        except (IOError, OSError, urllib2.URLError):
            return [document.reporter.warning(
                'Include file %r not found or reading it failed' % self.arguments[0],
                line=self.lineno)]
        except UnicodeError:
            return [document.reporter.warning(
                'Encoding %r used for reading included file %r seems to '
                'be wrong, try giving an :encoding: option' %
                (encoding, self.arguments[0]))]
        finally:
            if f is not None:
                f.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号