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


Python StringIO.write方法代码示例

本文整理汇总了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() 
开发者ID:pytest-dev,项目名称:py,代码行数:18,代码来源:capture.py

示例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() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:27,代码来源:junit_xml.py

示例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) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:23,代码来源:__init__.py

示例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) 
开发者ID:pytest-dev,项目名称:py,代码行数:6,代码来源:capture.py

示例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() 
开发者ID:pytest-dev,项目名称:py,代码行数:11,代码来源:capture.py

示例6: writelines

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def writelines(self, linelist):
        data = ''.join(linelist)
        self.write(data) 
开发者ID:pytest-dev,项目名称:py,代码行数:5,代码来源:capture.py

示例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) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:6,代码来源:capture.py

示例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 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:37,代码来源:capture.py

示例9: write

# 需要导入模块: from StringIO import StringIO [as 别名]
# 或者: from StringIO.StringIO import write [as 别名]
def write(self, s):
            StringIO.write(self, s) 
开发者ID:SystemRage,项目名称:py-kms,代码行数:4,代码来源:pykms_Format.py

示例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 
开发者ID:SystemRage,项目名称:py-kms,代码行数:13,代码来源:pykms_Format.py

示例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) 
开发者ID:SystemRage,项目名称:py-kms,代码行数:17,代码来源:pykms_Format.py


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