当前位置: 首页>>代码示例>>Python>>正文


Python cStringIO.readlines方法代码示例

本文整理汇总了Python中six.moves.cStringIO.readlines方法的典型用法代码示例。如果您正苦于以下问题:Python cStringIO.readlines方法的具体用法?Python cStringIO.readlines怎么用?Python cStringIO.readlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.cStringIO的用法示例。


在下文中一共展示了cStringIO.readlines方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import readlines [as 别名]
 def parse(klass, buf):
     if hasattr(buf, 'readlines'):
         fest = buf
     else:
         fest = StringIO(force_bytes(buf).decode('utf-8'))
     kwargs = {}
     items = []
     item = {}
     header = ''  # persistent and used for accreting continuations
     lineno = 0
     # JAR spec requires two newlines at the end of a buffer to be parsed
     # and states that they should be appended if necessary.  Just throw
     # two newlines on every time because it won't hurt anything.
     for line in itertools.chain(fest.readlines(), "\n" * 2):
         lineno += 1
         line = line.rstrip()
         if len(line) > 72:
             raise ParsingError("Manifest parsing error: line too long "
                                "(%d)" % lineno)
         # End of section
         if not line:
             if item:
                 algos = item.pop('algos')
                 found_algos = set(item['digests'].keys())
                 if algos is not None and set(algos) != found_algos:
                     error_msg = (
                         "Manifest parsing error: saw algos {} despite "
                         "only listing {} (line {})").format(
                             found_algos, set(algos), lineno)
                     raise ParsingError(error_msg)
                 items.append(Section(item.pop('name'), **item))
                 item = {}
             header = ''
             continue
         # continuation?
         continued = continuation_re.match(line)
         if continued:
             if not header:
                 raise ParsingError("Manifest parsing error: continued line"
                                    " without previous header! Line number"
                                    " %d" % lineno)
             item[header] += continued.group(1)
             continue
         match = headers_re.match(line)
         if not match:
             raise ParsingError("Unrecognized line format: \"%s\"" % line)
         header = match.group(1).lower()
         value = match.group(2)
         if '-version' == header[-8:]:
             # Not doing anything with these at the moment
             pass
         elif '-digest-manifest' == header[-16:]:
             if 'digest_manifests' not in kwargs:
                 kwargs['digest_manifests'] = {}
             kwargs['digest_manifests'][header[:-16]] = b64decode(value)
         elif 'name' == header:
             if directory_re.search(value):
                 continue
             item['name'] = value
             continue
         elif 'digest-algorithms' == header:
             item['algos'] = tuple(re.split('\s+', value.lower()))
             continue
         elif '-digest' == header[-7:]:
             if 'digests' not in item:
                 item['digests'] = {}
             item['digests'][header[:-7]] = b64decode(value)
             continue
     if len(kwargs):
         return klass(items, **kwargs)
     return klass(items)
开发者ID:mozilla,项目名称:signing-clients,代码行数:73,代码来源:apps.py


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