Python StringIO.StringIO 模块,write() 实例源码

我们从Python开源项目中,提取了以下43个代码示例,用于说明如何使用StringIO.StringIO.write()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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()
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
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()
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
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()
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
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()
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
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()
项目:py    作者:pytest-dev    | 项目源码 | 文件源码
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()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def writelines(self, linelist):
        data = ''.join(linelist)
        self.write(data)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def writelines(self, linelist):
        data = ''.join(linelist)
        self.write(data)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
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()
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def writelines(self, linelist):
        data = ''.join(linelist)
        self.write(data)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
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()
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:godot-python    作者:touilleMan    | 项目源码 | 文件源码
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
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
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()
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def writelines(self, linelist):
        data = ''.join(linelist)
        self.write(data)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
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()
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
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
项目:py    作者:pytest-dev    | 项目源码 | 文件源码
def write(self, data):
            if not isinstance(data, unicode):
                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
            StringIO.write(self, data)
项目:py    作者:pytest-dev    | 项目源码 | 文件源码
def write(self, data):
            if isinstance(data, unicode):
                raise TypeError("not a byte value: %r" %(data,))
            StringIO.write(self, data)
项目:py    作者:pytest-dev    | 项目源码 | 文件源码
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()
项目:py    作者:pytest-dev    | 项目源码 | 文件源码
def write(self, obj):
        if isinstance(obj, unicode):
            obj = obj.encode(self.encoding)
        elif isinstance(obj, str):
            pass
        else:
            obj = str(obj)
        self._stream.write(obj)
项目:py    作者:pytest-dev    | 项目源码 | 文件源码
def writelines(self, linelist):
        data = ''.join(linelist)
        self.write(data)
项目:chaquopy    作者:chaquo    | 项目源码 | 文件源码
def write(self, s):
        StringIO.write(self, s)
        self.func(self.getvalue())
        self.seek(0)
        self.truncate(0)