當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。