Python io.StringIO.write() Examples
The following are 30
code examples of io.StringIO.write().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
io.StringIO
, or try the search function
.
Example #1
Source File: capture.py From python-netsurv with MIT License | 6 votes |
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()
Example #2
Source File: make.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
def use_browser(cls, browser): if browser not in ("chrome", "firefox", "safari"): _CommonTargets.exit("No valid webdriver specified! Choose between 'chrome', 'firefox' and 'safari'.", 1) # write the config file config_text = ("# This file is automatically generated by the Makefile.\n" "# Do not manually edit it!\n" "\n" "WEBDRIVER = \"{webdriver}\"\n".format(webdriver=browser)) with open(WEBDRIVER_CONF_FILE, 'w') as f: f.write(config_text) # install the selenium driver for chrome and firefox if browser == "chrome": cls.__install_chromedriver() elif browser == "firefox": cls.__install_geckodriver()
Example #3
Source File: capture.py From py with MIT License | 6 votes |
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()
Example #4
Source File: capture.py From scylla with Apache License 2.0 | 6 votes |
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()
Example #5
Source File: capture.py From python-netsurv with MIT License | 6 votes |
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()
Example #6
Source File: capture.py From scylla with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: pykms_Format.py From py-kms with The Unlicense | 5 votes |
def write(self, s): StringIO.write(self, s)
Example #8
Source File: pykms_Format.py From py-kms with The Unlicense | 5 votes |
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
Example #9
Source File: pykms_Format.py From py-kms with The Unlicense | 5 votes |
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)
Example #10
Source File: capture.py From scylla with Apache License 2.0 | 5 votes |
def write(self, data): if not isinstance(data, unicode): data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace') StringIO.write(self, data)
Example #11
Source File: capture.py From scylla with Apache License 2.0 | 5 votes |
def write(self, data): if isinstance(data, unicode): raise TypeError("not a byte value: %r" %(data,)) StringIO.write(self, data)
Example #12
Source File: capture.py From scylla with Apache License 2.0 | 5 votes |
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()
Example #13
Source File: decorators.py From sumatra with BSD 2-Clause "Simplified" License | 5 votes |
def write(self, object): StringIO.write(self, str(object))
Example #14
Source File: capture.py From scylla with Apache License 2.0 | 5 votes |
def writelines(self, linelist): data = ''.join(linelist) self.write(data)
Example #15
Source File: make.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def write(self, *args, **kwargs): # only write output, that does not contain 'virtualenv' write = False if isinstance(args, tuple): for arg in args: if "virtualenv" not in arg: write = True elif "virtualenv" not in args: write = True if write: self.__stdout.write(*args, **kwargs) StringIO.write(self, *args, **kwargs)
Example #16
Source File: make.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def read(self, *args, **kwargs): self.seek(0) self.__stdout.write(StringIO.read(self, *args, **kwargs))
Example #17
Source File: make.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def execute_target(cls, unused1, argument_values, unused2): # write the production settings _CommonTargets.save_make_settings(development=argument_values.get("development", False)) # initialize the rest of the settings _CommonTargets.initialize_settings()
Example #18
Source File: capture.py From py with MIT License | 5 votes |
def write(self, data): if not isinstance(data, unicode): data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace') return StringIO.write(self, data)
Example #19
Source File: stream.py From hwk-mirror with GNU General Public License v3.0 | 5 votes |
def write(self, content, replace=0): self['state'] = tk.NORMAL if replace: self.delete(tk.END + f"-{replace}c", tk.END) self.insert(tk.END , content) self['state'] = tk.DISABLED self.see(tk.END) return StringIO.write(self.stream, content)
Example #20
Source File: capture.py From python-netsurv with MIT License | 5 votes |
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
Example #21
Source File: capture.py From python-netsurv with MIT License | 5 votes |
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)
Example #22
Source File: capture.py From python-netsurv with MIT License | 5 votes |
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()
Example #23
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def write(self, data): if isinstance(data, unicode): raise TypeError("not a byte value: %r" %(data,)) StringIO.write(self, data)
Example #24
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def write(self, data): if not isinstance(data, unicode): data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace') StringIO.write(self, data)
Example #25
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def writelines(self, linelist): data = ''.join(linelist) self.write(data)
Example #26
Source File: capture.py From python-netsurv with MIT License | 5 votes |
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)
Example #27
Source File: capture.py From python-netsurv with MIT License | 5 votes |
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()
Example #28
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def write(self, data): if isinstance(data, unicode): raise TypeError("not a byte value: %r" %(data,)) StringIO.write(self, data)
Example #29
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def write(self, data): if not isinstance(data, unicode): data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace') StringIO.write(self, data)
Example #30
Source File: capture.py From py with MIT License | 5 votes |
def writelines(self, linelist): data = ''.join(linelist) self.write(data)