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


Python cStringIO.getvalue方法代码示例

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


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

示例1: test_find_replace_enable

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_find_replace_enable(self):
     db_file = os.path.join(self.testdir, 'hash.db')
     broker = ContainerBroker(db_file)
     broker.account = 'a'
     broker.container = 'c'
     broker.initialize()
     ts = utils.Timestamp.now()
     broker.merge_items([
         {'name': 'obj%02d' % i, 'created_at': ts.internal, 'size': 0,
          'content_type': 'application/octet-stream', 'etag': 'not-really',
          'deleted': 0, 'storage_policy_index': 0,
          'ctype_timestamp': ts.internal, 'meta_timestamp': ts.internal}
         for i in range(100)])
     out = StringIO()
     err = StringIO()
     with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err):
         with mock_timestamp_now() as now:
             main([broker.db_file, 'find_and_replace', '10', '--enable'])
     expected = [
         'No shard ranges found to delete.',
         'Injected 10 shard ranges.',
         'Run container-replicator to replicate them to other nodes.',
         "Container moved to state 'sharding' with epoch %s." %
         now.internal,
         'Run container-sharder on all nodes to shard the container.']
     self.assertEqual(expected, out.getvalue().splitlines())
     self.assertEqual(['Loaded db broker for a/c.'],
                      err.getvalue().splitlines())
     self._assert_enabled(broker, now)
     self.assertEqual(
         [(data['lower'], data['upper']) for data in self.shard_data],
         [(sr.lower_str, sr.upper_str) for sr in broker.get_shard_ranges()])
开发者ID:jgmerritt,项目名称:swift,代码行数:34,代码来源:test_manage_shard_ranges.py

示例2: test_fail

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
    def test_fail(self):
        self.basedir = basedir = os.path.join("backupdb", "fail")
        fileutil.make_dirs(basedir)

        # put a non-DB file in the way
        not_a_db = ("I do not look like a sqlite database\n" +
                    "I'M NOT" * 1000) # OS-X sqlite-2.3.2 takes some convincing
        self.writeto("not-a-database", not_a_db)
        stderr_f = StringIO()
        bdb = backupdb.get_backupdb(os.path.join(basedir, "not-a-database"),
                                    stderr_f)
        self.failUnlessEqual(bdb, None)
        stderr = stderr_f.getvalue()
        self.failUnlessIn("backupdb file is unusable", stderr)
        # sqlite-3.19.3 says "file is encrypted or is not a database"
        # sqlite-3.20.0 says "file is not a database"
        self.failUnlessIn("is not a database", stderr)

        # put a directory in the way, to exercise a different error path
        where = os.path.join(basedir, "roadblock-dir")
        fileutil.make_dirs(where)
        stderr_f = StringIO()
        bdb = backupdb.get_backupdb(where, stderr_f)
        self.failUnlessEqual(bdb, None)
        stderr = stderr_f.getvalue()
        self.failUnlessIn("Unable to create/open backupdb file %s" % (where,), stderr)
        self.failUnlessIn("unable to open database file", stderr)
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:29,代码来源:test_backupdb.py

示例3: IncludedResponse

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
class IncludedResponse(object):

    def __init__(self):
        self.headers = None
        self.status = None
        self.output = StringIO()
        self.str = None

    def close(self):
        self.str = self.output.getvalue()
        self.output.close()
        self.output = None

    def write(self, s):
        assert self.output is not None, (
            "This response has already been closed and no further data "
            "can be written.")
        self.output.write(s)

    def __str__(self):
        return self.body

    def body__get(self):
        if self.str is None:
            return self.output.getvalue()
        else:
            return self.str
    body = property(body__get)
开发者ID:10sr,项目名称:hue,代码行数:30,代码来源:recursive.py

示例4: test_push

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
def test_push(empty_db,newstatus):
    db = empty_db
    input = remove_email(inv_pre) if db.member_class else inv_pre
    db.import_invitations(input,allfields=True,format='json')
    input = copy.deepcopy(inv_down)
    input['data'] = input['data'][2:]
    input = StringIO(json.dumps(input))
    output = StringIO()
    # ignore registering
    msg = dict(format='member',version=(1,0),status='',uuid='uid06')
    for status in ('registering','new'):
        msg['status'] = status
        assert not InvitationDatabase.process_update(db,msg,input,output)
        assert not output.getvalue()
    # registered leads to sync
    msg['status'] = newstatus
    assert InvitationDatabase.process_update(db,msg,input,output)
    output = json.loads(output.getvalue())
    assert output
    up = copy.deepcopy(inv_up)
    up['data'] = up['data'][2:6]
    output['data'] = sort_by_uuid(output['data'])
    assert output == up
    # not again
    assert not db.process_update(msg,input,output)
开发者ID:edemocracy,项目名称:ekklesia,代码行数:27,代码来源:test_invitations.py

示例5: _parse_operator

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
def _parse_operator(segment, iterator):
    """Parses the operator (eg. '==' or '<')."""
    stream = StringIO()
    for character in iterator:
        if character == constants.NEGATION[1]:
            if stream.tell():
                # Negation can only occur at the start of an operator.
                raise ValueError('Unexpected negation.')

            # We've been negated.
            segment.negated = not segment.negated
            continue

        if (stream.getvalue() + character not in OPERATOR_SYMBOL_MAP and
                stream.getvalue() + character not in OPERATOR_BEGIN_CHARS):
            # We're no longer an operator.
            break

        # Expand the operator
        stream.write(character)

    # Check for existance.
    text = stream.getvalue()
    if text not in OPERATOR_SYMBOL_MAP:
        # Doesn't exist because of a mis-placed negation in the middle
        # of the path.
        raise ValueError('Unexpected negation.')

    # Set the found operator.
    segment.operator = OPERATOR_SYMBOL_MAP[text]

    # Return the remaining characters.
    return chain(character, iterator)
开发者ID:Pholey,项目名称:python-armet,代码行数:35,代码来源:parser.py

示例6: test_export

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
def test_export(member_db):
    memfile = StringIO()
    depfile = StringIO()
    member_db.export_members([memfile,depfile],allfields=True,format='csv')
    members = memfile.getvalue().replace('r2sub;sub2','sub2;r2sub') # normalize order
    assert members==members_export
    assert depfile.getvalue()==deps_export
开发者ID:edemocracy,项目名称:ekklesia,代码行数:9,代码来源:test_members.py

示例7: test_print_obj_valid

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_print_obj_valid(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         print_obj(self.datafile, swift_dir=self.testdir)
     etag_msg = 'ETag: Not found in metadata'
     length_msg = 'Content-Length: Not found in metadata'
     self.assertTrue(etag_msg in out.getvalue())
     self.assertTrue(length_msg in out.getvalue())
开发者ID:aureliengoulon,项目名称:swift,代码行数:10,代码来源:test_info.py

示例8: test_simple

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_simple(self):
     t = termlog.TermLog()
     sio = StringIO()
     t.configure(dump.Options(tfile = sio, verbosity = 2), set([]))
     t.log(controller.LogEntry("one", "info"))
     assert "one" in sio.getvalue()
     t.log(controller.LogEntry("two", "debug"))
     assert "two" not in sio.getvalue()
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:10,代码来源:test_termlog.py

示例9: test_print_obj_no_ring

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
    def test_print_obj_no_ring(self):
        no_rings_dir = os.path.join(self.testdir, 'no_rings_here')
        os.mkdir(no_rings_dir)

        out = StringIO()
        with mock.patch('sys.stdout', out):
            print_obj(self.datafile, swift_dir=no_rings_dir)
        self.assertTrue('d41d8cd98f00b204e9800998ecf8427e' in out.getvalue())
        self.assertTrue('Partition' not in out.getvalue())
开发者ID:aureliengoulon,项目名称:swift,代码行数:11,代码来源:test_info.py

示例10: test_print_item_locations_ring_policy_mismatch_no_target

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_print_item_locations_ring_policy_mismatch_no_target(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         objring = ring.Ring(self.testdir, ring_name='object')
         # Test mismatch of ring and policy name (valid policy)
         self.assertRaises(InfoSystemExit, print_item_locations,
                           objring, policy_name='zero')
     self.assertTrue('Warning: mismatch between ring and policy name!'
                     in out.getvalue())
     self.assertTrue('No target specified' in out.getvalue())
开发者ID:aureliengoulon,项目名称:swift,代码行数:12,代码来源:test_info.py

示例11: test_print_ring_locations_account

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_print_ring_locations_account(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         acctring = ring.Ring(self.testdir, ring_name='account')
         print_ring_locations(acctring, 'dir', 'acct')
     exp_db = os.path.join('${DEVICE:-/srv/node*}', 'sdb1', 'dir', '3',
                           'b47', 'dc5be2aa4347a22a0fee6bc7de505b47')
     self.assertTrue(exp_db in out.getvalue())
     self.assertTrue('127.0.0.1' in out.getvalue())
     self.assertTrue('127.0.0.2' in out.getvalue())
开发者ID:aureliengoulon,项目名称:swift,代码行数:12,代码来源:test_info.py

示例12: test_print_item_locations_invalid_policy_no_target

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_print_item_locations_invalid_policy_no_target(self):
     out = StringIO()
     policy_name = 'nineteen'
     with mock.patch('sys.stdout', out):
         objring = ring.Ring(self.testdir, ring_name='object')
         self.assertRaises(InfoSystemExit, print_item_locations,
                           objring, policy_name=policy_name)
     exp_msg = 'Warning: Policy %s is not valid' % policy_name
     self.assertTrue(exp_msg in out.getvalue())
     self.assertTrue('No target specified' in out.getvalue())
开发者ID:aureliengoulon,项目名称:swift,代码行数:12,代码来源:test_info.py

示例13: test_print_obj_with_policy

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
 def test_print_obj_with_policy(self):
     out = StringIO()
     with mock.patch('sys.stdout', out):
         print_obj(self.datafile, swift_dir=self.testdir, policy_name='one')
     etag_msg = 'ETag: Not found in metadata'
     length_msg = 'Content-Length: Not found in metadata'
     ring_loc_msg = 'ls -lah'
     self.assertTrue(etag_msg in out.getvalue())
     self.assertTrue(length_msg in out.getvalue())
     self.assertTrue(ring_loc_msg in out.getvalue())
开发者ID:aureliengoulon,项目名称:swift,代码行数:12,代码来源:test_info.py

示例14: test_write_values

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
def test_write_values():
    tst = "foobarvoing"
    s = StringIO()
    writer.write_values(s, [tst], [])
    assert s.getvalue() == tst

    for bs in range(1, len(tst) + 2):
        for off in range(len(tst)):
            s = StringIO()
            writer.write_values(s, [tst], [(off, "disconnect")], blocksize=bs)
            assert s.getvalue() == tst[:off]
开发者ID:ganguera,项目名称:mitmproxy,代码行数:13,代码来源:test_language_writer.py

示例15: test_send_chunk

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import getvalue [as 别名]
def test_send_chunk():
    v = "foobarfoobar"
    for bs in range(1, len(v) + 2):
        s = StringIO()
        writer.send_chunk(s, v, bs, 0, len(v))
        assert s.getvalue() == v
        for start in range(len(v)):
            for end in range(len(v)):
                s = StringIO()
                writer.send_chunk(s, v, bs, start, end)
                assert s.getvalue() == v[start:end]
开发者ID:ganguera,项目名称:mitmproxy,代码行数:13,代码来源:test_language_writer.py


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