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


Python StringIO.readlines方法代码示例

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


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

示例1: test_subchapoverview

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def test_subchapoverview(self):
        auth.login_user(db.auth_user(11))
        session.auth = auth
        request.vars.tablekind = 'sccount'

        res = subchapoverview()
        self.assertIsNotNone(res)
        soup = BeautifulSoup(res['summary'])
        thlist = soup.select('th')
        self.assertEqual(thlist[11].text, 'user_1671')
        rl = soup.select('tr')
        cl = rl[10].select('td')
        self.assertEqual(cl[5].text, '4.0')
        self.assertEqual(cl[17].text, '6.0')
        request.vars.action = 'tocsv'
        request.vars.tablekind = 'dividmin'
        res = subchapoverview()
        csvf = StringIO(res)
        rows = csvf.readlines()
        cols = rows[18].split(',')
        print(cols)
        self.assertEqual(cols[0], ' ')
        self.assertEqual(cols[2], 'ch12_dict11')
        self.assertEqual(cols[-3].strip(), '2017-10-26 22:25:38')
        self.assertEqual(cols[-1].strip(), 'Aliasingandcopying')
        cols = rows[122].split(',')
        print(cols)
        self.assertEqual(cols[0], ' ')
        self.assertEqual(cols[3], '2017-08-30 22:29:30')
开发者ID:RunestoneInteractive,项目名称:RunestoneServer,代码行数:31,代码来源:test_dashboard.py

示例2: _call_git_command

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def _call_git_command(self, command, input_file=None, output_file=None):

        """
        Class calls git command
        :param command: git command which is executed
        :param directory: git directory
        :param input_file: input file for git operations
        :return: ret_code and output of git command
        """
        cmd = []
        cmd.append(self.GIT)
        cmd.extend(command)
        self.output_data = []
        if not output_file:
            output = StringIO()
        else:
            output = output_file
        ret_code = ProcessHelper.run_subprocess_cwd(cmd,
                                                    cwd=self.git_directory,
                                                    input=input_file,
                                                    output=output)
        if not output_file:
            out = output.readlines()
            for o in out:
                self.output_data.append(o.strip().encode(defenc))
        return ret_code
开发者ID:hhorak,项目名称:rebase-helper,代码行数:28,代码来源:utils.py

示例3: fold_cell

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def fold_cell(self, cell, folded):
        """
        Remove folded lines and add a '<->' at the parent line
        """
        f = StringIO(cell)
        lines = f.readlines()

        if folded[0] == 0 and (lines[0][0] == '#' or lines[0][0] == '%') :
            # fold whole cell when first line is a comment or magic
            return lines[0].rstrip('\n') + '↔\n'
        fold_indent = 0
        fold = False
        fcell = ""
        for i, l in enumerate(lines):
            # fold indent level
            indent = len(l)-len(l.lstrip(' '))
            if indent <= fold_indent:
                fold = False
                fold_indent = 0
            if i in folded:
                fold = True
                fold_indent = indent
                fcell += l.rstrip('\n') + '↔\n'
            if fold is False:
                fcell += l
        return fcell
开发者ID:dhpizza,项目名称:IPython-notebook-extensions,代码行数:28,代码来源:pre_codefolding.py

示例4: test_api_key_should_be_revoked

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def test_api_key_should_be_revoked(self):
        user = user_factory(id=67890)
        # The test csv contains an entry with this user and the "right" secret.
        right_secret = (
            'ab2228544a061cb2af21af97f637cc58e1f8340196f1ddc3de329b5974694b26')
        apikey = APIKey.objects.create(
            key='user:{}:{}'.format(user.pk, '333'), secret=right_secret,
            user=user, is_active=True)
        stdout = StringIO()
        call_command('revoke_api_keys', self.csv_path, stdout=stdout)
        stdout.seek(0)
        output = stdout.readlines()
        assert output[0] == (
            'Ignoring APIKey user:12345:666, it does not exist.\n')
        assert output[1] == (
            'Revoked APIKey user:67890:333.\n')
        assert output[2] == (
            'Ignoring APIKey garbage, it does not exist.\n')
        assert output[3] == (
            'Done. Revoked 1 keys out of 3 entries.\n')

        # API key is now inactive, secret hasn't changed, the other user api
        # key is still there, there are no additional APIKeys.
        apikey.reload()
        assert apikey.secret == right_secret
        assert apikey.is_active is None
        assert APIKey.objects.filter(user=user).count() == 2
        assert APIKey.objects.filter(user=user, is_active=True).count() == 1
开发者ID:diox,项目名称:olympia,代码行数:30,代码来源:test_commands.py

示例5: GbpLogTester

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
class GbpLogTester(object):
    """
    Helper class for tests that need to capture logging output
    """
    def __init__(self):
        """Object initialization"""
        self._log = None
        self._loghandler = None

    def _capture_log(self, capture=True):
        """ Capture log"""
        if capture:
            assert self._log is None, "Log capture already started"
            self._log = StringIO()
            self._loghandler = gbp.log.GbpStreamHandler(self._log, False)
            self._loghandler.addFilter(gbp.log.GbpFilter([gbp.log.WARNING,
                                                          gbp.log.ERROR]))
            handlers = list(gbp.log.LOGGER.handlers)
            for hdl in handlers:
                gbp.log.LOGGER.removeHandler(hdl)
            gbp.log.LOGGER.addHandler(self._loghandler)
        else:
            assert self._log is not None, "Log capture not started"
            gbp.log.LOGGER.removeHandler(self._loghandler)
            self._loghandler.close()
            self._loghandler = None
            self._log.close()
            self._log = None

    def _get_log(self):
        """Get the captured log output"""
        self._log.seek(0)
        return self._log.readlines()

    def _check_log_empty(self):
        """Check that nothig was logged"""
        output = self._get_log()
        ok_(output == [], "Log is not empty: %s" % output)

    def _check_log(self, linenum, regex):
        """Check that the specified line on log matches expectations"""
        if self._log is None:
            raise Exception("BUG in unittests: no log captured!")
        log = self._get_log()
        assert_less(linenum, len(log),
                    "Not enough log lines: %d" % len(log))
        output = self._get_log()[linenum].strip()
        ok_(re.match(regex, output),
            "Log entry '%s' doesn't match '%s'" % (output, regex))

    def _clear_log(self):
        """Clear the mock strerr"""
        if self._log is not None:
            self._log.seek(0)
            self._log.truncate()
开发者ID:andrewlukoshko,项目名称:git-buildpackage,代码行数:57,代码来源:gbplogtester.py

示例6: test_api_key_does_not_exist

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def test_api_key_does_not_exist(self):
        user = user_factory()
        # The test csv does not contain an entry for this user.
        apikey = APIKey.new_jwt_credentials(user=user)
        old_secret = apikey.secret
        stdout = StringIO()
        call_command('revoke_api_keys', self.csv_path, stdout=stdout)
        stdout.seek(0)
        output = stdout.readlines()
        assert output[0] == (
            'Ignoring APIKey user:12345:666, it does not exist.\n')
        assert output[1] == (
            'Ignoring APIKey user:67890:333, it does not exist.\n')

        # APIKey is still active, secret hasn't changed, there are no
        # additional APIKeys.
        apikey.reload()
        assert apikey.secret == old_secret
        assert apikey.is_active
        assert APIKey.objects.filter(user=user).count() == 1
开发者ID:diox,项目名称:olympia,代码行数:22,代码来源:test_commands.py

示例7: test_api_key_has_wrong_secret

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def test_api_key_has_wrong_secret(self):
        user = user_factory(id=12345)
        # The test csv contains an entry with this user and the "wrong" secret.
        right_secret = (
            'ab2228544a061cb2af21af97f637cc58e1f8340196f1ddc3de329b5974694b26')
        apikey = APIKey.objects.create(
            key='user:{}:{}'.format(user.pk, '666'), secret=right_secret,
            user=user, is_active=True)
        stdout = StringIO()
        call_command('revoke_api_keys', self.csv_path, stdout=stdout)
        stdout.seek(0)
        output = stdout.readlines()
        assert output[0] == (
            'Ignoring APIKey user:12345:666, secret differs.\n')
        assert output[1] == (
            'Ignoring APIKey user:67890:333, it does not exist.\n')

        # API key is still active, secret hasn't changed, there are no
        # additional APIKeys.
        apikey.reload()
        assert apikey.secret == right_secret
        assert apikey.is_active
        assert APIKey.objects.filter(user=user).count() == 1
开发者ID:diox,项目名称:olympia,代码行数:25,代码来源:test_commands.py

示例8: FormatterTest

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
class FormatterTest(unittest.TestCase):

    def setUp(self):
        self.position = 0
        self.logger = structuredlog.StructuredLogger(
            "test_%s" % type(self).__name__)
        self.output_file = StringIO()
        self.handler = handlers.StreamHandler(
            self.output_file, self.get_formatter())
        self.logger.add_handler(self.handler)

    def set_position(self, pos=None):
        if pos is None:
            pos = self.output_file.tell()
        self.position = pos

    def get_formatter(self):
        raise NotImplementedError(
            "FormatterTest subclasses must implement get_formatter")

    @property
    def loglines(self):
        self.output_file.seek(self.position)
        return [line.rstrip() for line in self.output_file.readlines()]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:26,代码来源:test_structured.py

示例9: NormalHTTPFile

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
class NormalHTTPFile(HTTPFile):
  def __init__(self,
               path,
               devid,
               backup_dests=None,
               mg=None,
               fid=None,
               cls=None,
               key=None,
               create_close_arg=None,
               **kwds):

    super(NormalHTTPFile, self).__init__(mg, fid, key, cls, create_close_arg)

    if backup_dests is None:
      backup_dests = []
    self._fp = StringIO()
    self._paths = [(devid, path)] + list(backup_dests)
    self._is_closed = 0

  def paths(self):
    return self._paths

  def read(self, n= -1):
    return self._fp.read(n)

  def readline(self, *args, **kwds):
    return self._fp.readline(*args, **kwds)

  def readlines(self, *args, **kwds):
    return self._fp.readlines(*args, **kwds)

  def write(self, content):
    self._fp.write(content)

  def close(self):
    if not self._is_closed:
      self._is_closed = True

#      content = self._fp.getvalue()
#      self._fp.close()

      for tried_devid, tried_path in self._paths:
        try:
#          self._request(tried_path, "PUT", content)
          self._fp.seek(0)
          put.putfile(self._fp, tried_path)
          devid = tried_devid
          path = tried_path
          break
        except HTTPError as e:
          continue
      else:
        devid = None
        path = None

      self._fp.seek(0, 2)
      size = self._fp.tell()
      self._fp.close()
      if devid:
        params = {
                   'fid'   : self.fid,
                   'domain': self.mg.domain,
                   'key'   : self.key,
                   'path'  : path,
                   'devid' : devid,
                   'size'  : size
                 }
        if self.create_close_arg:
          params.update(self.create_close_arg)
        try:
          self.mg.backend.do_request('create_close', params)
        except MogileFSError as e:
          if e.err != 'empty_file':
            raise

  def seek(self, pos, mode=0):
    return self._fp.seek(pos, mode)

  def tell(self):
    return self._fp.tell()
开发者ID:middagj,项目名称:pymogile,代码行数:83,代码来源:file.py

示例10: test_readlines

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
def test_readlines(d, val):
    buf = StringIO(val)

    assert buf.readlines() == d.readlines()
开发者ID:Grimmick,项目名称:data,代码行数:6,代码来源:test_inputdata.py

示例11: test_readline

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
def test_readline(d, val):
    buf = StringIO(val)

    for line in buf.readlines():
        assert line == d.readline()
开发者ID:Grimmick,项目名称:data,代码行数:7,代码来源:test_inputdata.py

示例12: parse

# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import readlines [as 别名]
    def parse(self, name, base_mark, io):
        if not hasattr(io, 'readlines'):
            io = StringIO(io)

        def mark(line, column=0):
            return base_mark.merge(Mark('', line, column))

        errors = []
        current_section_name = ConfigSectionName(mark(0), mark(0), '')
        current_param_name = None
        current_param_value = None
        current_param_delimiter = None
        sections = []
        parameters = []

        line_number = -1
        for line in io.readlines():
            line = line.rstrip()

            line_number += 1

            if current_param_name \
                and (current_param_value.quotechar
                     or (line == '' or not line[0].isspace())):
                param = ConfigParameter(
                    current_param_name.start_mark,
                    current_param_value.end_mark,
                    current_param_name,
                    current_param_value,
                    current_param_delimiter)
                parameters.append(param)

                current_param_name = None
                current_param_value = None
                current_param_delimiter = None

            if line == '':
                continue

            if line[0] in '#;':
                continue

            if line[0].isspace():
                if current_param_name:
                    current_param_value.end_mark = mark(line_number, len(line))
                    current_param_value.text += line.lstrip()
                    continue
                else:
                    errors.append(
                        ParseError('Unexpected multiline value continuation',
                                   mark(line_number)))
                    continue

            if line[0] == '[':
                end_index = line.find(']')
                if end_index == -1:
                    errors.append(
                        ParseError('Unclosed section', mark(line_number,
                                                            len(line))))

                    end_index = len(line)
                    while line[end_index - 1].isspace():
                        end_index -= 1
                    if end_index <= 1:
                        errors.append(
                            ParseError('Missing section name',
                                       mark(line_number)))
                        continue
                else:
                    i = end_index + 1
                    while i < len(line):
                        if not line[i].isspace():
                            errors.append(
                                ParseError('Extra chars after section name',
                                           mark(line_number, i)))
                            break
                        i += 1

                if current_section_name.text != '' or len(parameters) > 0:
                    section = ConfigSection(
                        current_section_name.start_mark,
                        mark(line_number),
                        current_section_name,
                        parameters)
                    sections.append(section)
                    parameters = []

                current_section_name = ConfigSectionName(
                    mark(line_number, 0),
                    mark(line_number, end_index),
                    line[1:end_index]
                )
            else:
                m = self.key_value_re.match(line)
                if m:
                    current_param_name = ConfigParameterName(
                        mark(line_number, m.start(1)),
                        mark(line_number, m.end(1)),
                        m.group(1)
                    )
#.........这里部分代码省略.........
开发者ID:akshatknsl,项目名称:rubick,代码行数:103,代码来源:ini.py


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