本文整理汇总了Python中StringIO.StringIO.write方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.write方法的具体用法?Python StringIO.write怎么用?Python StringIO.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringIO.StringIO
的用法示例。
在下文中一共展示了StringIO.write方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def __init__(self, out=True, err=True, in_=True, mixed=False, now=True):
self._oldout = sys.stdout
self._olderr = sys.stderr
self._oldin = sys.stdin
if out and not hasattr(out, 'file'):
out = TextIO()
self.out = out
if err:
if mixed:
err = out
elif not hasattr(err, 'write'):
err = TextIO()
self.err = err
self.in_ = in_
if now:
self.startall()
示例2: write_xml
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def write_xml(self):
if not self.module_name:
# No tests ran, nothing to write
return
took = time.time() - self.start
stdout = self.stdout.getvalue()
stderr = self.stderr.getvalue()
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
ensure_dir(self.xml_dir)
filename = os.path.join(self.xml_dir, 'TEST-%s.xml' % self.module_name)
stream = open(filename, 'w')
write_testsuite_xml(stream, len(self.tests), len(self.errors),
len(self.failures), 0, self.module_name, took)
for info in self.tests:
info.write_xml(stream)
write_stdouterr_xml(stream, stdout, stderr)
stream.write('</testsuite>')
stream.close()
示例3: inject_main_logfile
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def inject_main_logfile():
# the main log file. log every kind of message, format properly,
# rotate the log. someday - SocketHandler
mainlog = logging.handlers.RotatingFileHandler(filename=logpath,
mode='a', maxBytes=2**20, backupCount=1)
mainlog.setFormatter(bt_log_fmt)
mainlog.setLevel(logging.DEBUG)
logger = logging.getLogger('')
logging.getLogger('').addHandler(mainlog)
logging.getLogger('').removeHandler(console)
atexit_threads.register(lambda : logging.getLogger('').removeHandler(mainlog))
global stderr_console
if not is_frozen_exe:
# write all stderr messages to stderr (unformatted)
# as well as the main log (formatted)
stderr_console = logging.StreamHandler(old_stderr)
stderr_console.setLevel(STDERR)
stderr_console.setFormatter(logging.Formatter(u'%(message)s'))
logging.getLogger('').addHandler(stderr_console)
示例4: write
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def write(self, data):
if not isinstance(data, unicode):
data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
return StringIO.write(self, data)
示例5: writeorg
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def writeorg(self, data):
""" write a string to the original file descriptor
"""
tempfp = tempfile.TemporaryFile()
try:
os.dup2(self._savefd, tempfp.fileno())
tempfp.write(data)
finally:
tempfp.close()
示例6: writelines
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def writelines(self, linelist):
data = ''.join(linelist)
self.write(data)
示例7: write
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def write(self, data):
if not isinstance(data, unicode):
data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
StringIO.write(self, data)
示例8: _save
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def _save(self):
in_ = self._options['in_']
out = self._options['out']
err = self._options['err']
mixed = self._options['mixed']
patchsys = self._options['patchsys']
if in_:
try:
self.in_ = FDCapture(0, tmpfile=None, now=False,
patchsys=patchsys)
except OSError:
pass
if out:
tmpfile = None
if hasattr(out, 'write'):
tmpfile = out
try:
self.out = FDCapture(1, tmpfile=tmpfile,
now=False, patchsys=patchsys)
self._options['out'] = self.out.tmpfile
except OSError:
pass
if err:
if out and mixed:
tmpfile = self.out.tmpfile
elif hasattr(err, 'write'):
tmpfile = err
else:
tmpfile = None
try:
self.err = FDCapture(2, tmpfile=tmpfile,
now=False, patchsys=patchsys)
self._options['err'] = self.err.tmpfile
except OSError:
pass
示例9: write
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def write(self, s):
StringIO.write(self, s)
示例10: newlines_file
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def newlines_file(self, mode, *args):
try:
with open(self.path_nl, mode) as file:
if mode in ['w', 'a']:
file.write(args[0])
elif mode == 'r':
data = [int(i) for i in [line.rstrip('\n') for line in file.readlines()]]
self.newlines, ShellMessage.remain = data[0], sum(data[1:])
except:
with open(self.path_nl, 'w') as file:
pass
示例11: newlines_clean
# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def newlines_clean(self, num):
if num == 0:
with open(self.path_clean_nl, 'w') as file:
file.write('clean newlines')
try:
with open(self.path_clean_nl, 'r') as file:
some = file.read()
if num == 21:
ShellMessage.count, ShellMessage.remain, ShellMessage.numlist = (0, 0, [])
os.remove(self.path_nl)
os.remove(self.path_clean_nl)
except:
if num == 19:
ShellMessage.count, ShellMessage.remain, ShellMessage.numlist = (0, 0, [])
os.remove(self.path_nl)