本文整理汇总了Python中six.moves.cStringIO.seek方法的典型用法代码示例。如果您正苦于以下问题:Python cStringIO.seek方法的具体用法?Python cStringIO.seek怎么用?Python cStringIO.seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.cStringIO
的用法示例。
在下文中一共展示了cStringIO.seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_migration_status
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def get_migration_status(**options):
# type: (**Any) -> str
verbosity = options.get('verbosity', 1)
for app_config in apps.get_app_configs():
if module_has_submodule(app_config.module, "management"):
import_module('.management', app_config.name)
app_labels = [options['app_label']] if options.get('app_label') else None
db = options.get('database', DEFAULT_DB_ALIAS)
out = StringIO()
call_command(
'showmigrations',
'--list',
app_labels=app_labels,
database=db,
no_color=options.get('no_color', False),
settings=options.get('settings', os.environ['DJANGO_SETTINGS_MODULE']),
stdout=out,
traceback=options.get('traceback', True),
verbosity=verbosity,
)
connections.close_all()
out.seek(0)
output = out.read()
return re.sub('\x1b\[(1|0)m', '', output)
示例2: _decompress_xz
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def _decompress_xz(filename):
"""Eumlates an option function in read mode for xz.
See the comment in _compress_xz for more information.
This function tries to emulate the lzma module as much as
possible
"""
if not filename.endswith('.xz'):
filename = '{}.xz'.format(filename)
try:
with open(os.devnull, 'w') as null:
string = subprocess.check_output(
['xz', '--decompress', '--stdout', filename],
stderr=null)
except OSError as e:
if e.errno == errno.ENOENT:
raise exceptions.PiglitFatalError(
'No xz binary available')
raise
# We need a file-like object, so the contents must be placed in
# a StringIO object.
io = StringIO()
io.write(string)
io.seek(0)
yield io
io.close()
示例3: export_info
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def export_info(self, context, info):
data = StringIO()
out = zipfile.ZipFile(data, 'w')
for d in info:
path = d.get('path', d.get('id'))
filename = os.path.basename(path)
dir_path = os.path.dirname(path)
# Write data
_d = d.get('data', '')
fpath = os.path.join(dir_path, filename)
out.writestr(fpath, _d)
metadata = d.copy()
for name in ('data', 'path'):
if name in metadata:
del metadata[name]
# Write metadata
metadata_path = os.path.join(dir_path, '.metadata')
fpath = os.path.join(metadata_path, filename)
_d = str(self.atxml_template(info=metadata))
out.writestr(fpath, _d)
out.close()
data.seek(0)
return data
示例4: test_num_failures_by_type
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_num_failures_by_type(capfd):
# Test that the number of failures by status type is correctly calculated.
# Set up the handler.
output = StringIO()
logger = structuredlog.StructuredLogger("test_a")
logger.add_handler(handlers.StreamHandler(output, ChromiumFormatter()))
# Run some tests with different statuses: 3 passes, 1 timeout
logger.suite_start(["t1", "t2", "t3", "t4"], run_info={}, time=123)
logger.test_start("t1")
logger.test_end("t1", status="PASS", expected="PASS")
logger.test_start("t2")
logger.test_end("t2", status="PASS", expected="PASS")
logger.test_start("t3")
logger.test_end("t3", status="PASS", expected="FAIL")
logger.test_start("t4")
logger.test_end("t4", status="TIMEOUT", expected="CRASH")
logger.suite_end()
# check nothing got output to stdout/stderr
# (note that mozlog outputs exceptions during handling to stderr!)
captured = capfd.readouterr()
assert captured.out == ""
assert captured.err == ""
# check the actual output of the formatter
output.seek(0)
num_failures_by_type = json.load(output)["num_failures_by_type"]
# We expect 3 passes and 1 timeout, nothing else.
assert sorted(num_failures_by_type.keys()) == ["PASS", "TIMEOUT"]
assert num_failures_by_type["PASS"] == 3
assert num_failures_by_type["TIMEOUT"] == 1
示例5: test_chromium_required_fields
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_chromium_required_fields(capfd):
# Test that the test results contain a handful of required fields.
# Set up the handler.
output = StringIO()
logger = structuredlog.StructuredLogger("test_a")
logger.add_handler(handlers.StreamHandler(output, ChromiumFormatter()))
# output a bunch of stuff
logger.suite_start(["test-id-1"], run_info={}, time=123)
logger.test_start("test-id-1")
logger.test_end("test-id-1", status="PASS", expected="PASS")
logger.suite_end()
# check nothing got output to stdout/stderr
# (note that mozlog outputs exceptions during handling to stderr!)
captured = capfd.readouterr()
assert captured.out == ""
assert captured.err == ""
# check the actual output of the formatter
output.seek(0)
output_obj = json.load(output)
# Check for existence of required fields
assert "interrupted" in output_obj
assert "path_delimiter" in output_obj
assert "version" in output_obj
assert "num_failures_by_type" in output_obj
assert "tests" in output_obj
test_obj = output_obj["tests"]["test-id-1"]
assert "actual" in test_obj
assert "expected" in test_obj
示例6: test_error
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_error(self):
sio = StringIO()
sio.write("bogus")
sio.seek(0)
r = flow.FlowReader(sio)
tutils.raises(FlowReadException, list, r.stream())
f = FlowReadException("foo")
assert str(f) == "foo"
示例7: colorize
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def colorize(source):
"""
write colorized version to "[filename].py.html"
"""
html = StringIO()
Parser(source, html).format(None, None)
html.flush()
html.seek(0)
return html.read()
示例8: test_error
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_error(self):
sio = StringIO()
sio.write("bogus")
sio.seek(0)
r = flow.FlowReader(sio)
tutils.raises(flow.FlowReadError, list, r.stream())
f = flow.FlowReadError("foo")
assert f.strerror == "foo"
示例9: test_versioncheck
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_versioncheck(self):
f = tutils.tflow()
d = f.get_state()
d["version"] = (0, 0)
sio = StringIO()
tnetstring.dump(d, sio)
sio.seek(0)
r = flow.FlowReader(sio)
tutils.raises("version", list, r.stream())
示例10: test_copy_from_cols
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_copy_from_cols(self):
curs = self.conn.cursor()
f = StringIO()
for i in xrange(10):
f.write("%s\n" % (i,))
f.seek(0)
curs.copy_from(MinimalRead(f), "tcopy", columns=['id'])
curs.execute("select * from tcopy order by id")
self.assertEqual([(i, None) for i in range(10)], curs.fetchall())
示例11: _treader
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def _treader(self):
sio = StringIO()
w = flow.FlowWriter(sio)
for i in range(3):
f = tutils.tflow(resp=True)
w.add(f)
for i in range(3):
f = tutils.tflow(err=True)
w.add(f)
sio.seek(0)
return flow.FlowReader(sio)
示例12: read
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def read(self, html=None, code='@'):
'''Get the content of the clipboard.
html: BOOL. Whether to get the raw HTML code of the fomatted text on clipboard.
code: coding of the text on clipboard.'''
if (not html) and (not code):
return super().read()
else:
stream = StringIO()
clipb.clipboard_to_stream(stream, mode=None, code=code, null=None, html=html)
stream.seek(0)
return stream.read()
示例13: _copy_to
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def _copy_to(self, curs, srec):
f = StringIO()
curs.copy_to(MinimalWrite(f), "tcopy")
f.seek(0)
ntests = 0
for line in f:
n, s = line.split()
if int(n) < len(string.ascii_letters):
self.assertEqual(s, string.ascii_letters[int(n)] * srec)
ntests += 1
self.assertEqual(ntests, len(string.ascii_letters))
示例14: test_copy_from_cols_err
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_copy_from_cols_err(self):
curs = self.conn.cursor()
f = StringIO()
for i in xrange(10):
f.write("%s\n" % (i,))
f.seek(0)
def cols():
raise ZeroDivisionError()
yield 'id'
self.assertRaises(ZeroDivisionError,
curs.copy_from, MinimalRead(f), "tcopy", columns=cols())
示例15: test_roundtrip
# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import seek [as 别名]
def test_roundtrip(self):
sio = StringIO()
f = tutils.tflow()
f.request.content = "".join(chr(i) for i in range(255))
w = flow.FlowWriter(sio)
w.add(f)
sio.seek(0)
r = flow.FlowReader(sio)
l = list(r.stream())
assert len(l) == 1
f2 = l[0]
assert f2.get_state() == f.get_state()
assert f2.request == f.request