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


Python os.write方法代码示例

本文整理汇总了Python中os.write方法的典型用法代码示例。如果您正苦于以下问题:Python os.write方法的具体用法?Python os.write怎么用?Python os.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _symbolize

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def _symbolize(target, output, tool, exp_opt):
    fd, tmp_log = tempfile.mkstemp(prefix="%s_log" % tool, suffix=".txt", dir=".")
    try:
        os.write(fd, output)
    finally:
        os.close(fd)
    try:
        result = _common.run([TOOL_GDB, "-batch", "-nx",
                                        "-ex", "set python print-stack full",
                                        "-ex", "py import exploitable",
                                        "-ex", "exploitable -m %s %s" % (exp_opt, tmp_log),
                                        "-ex", "quit", target], timeout=180)
    finally:
        _common.delete(tmp_log)
    if result.classification == _common.TIMEOUT:
        raise RuntimeError("Timed out while processing %s output:\n%s" % (tool, output))
    result.backtrace, result.classification = _process_gdb_output(result.text)
    result.text = _common._limit_output_length(result.text)
    if result.classification == _common.NOT_AN_EXCEPTION:
        raise RuntimeError("Failed to process %s output:\n%s" % (tool, output))
    return result 
开发者ID:blackberry,项目名称:ALF,代码行数:23,代码来源:_gdb.py

示例2: _put

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def _put(self, time):
        buflist = []
        buf = repr(time)
        if buf[-1] == 'L':
            buf = buf[:-1]  # strip trailing L
        buflist.append(buf)
        if self._hasChange:
            self._hasChange = 0
            for s in self._fromSigs:
                v = int(s._val)
                # signed support
                if s._nrbits and v < 0:
                    v += (1 << s._nrbits)
                buf = hex(v)[2:]
                if buf[-1] == 'L':
                    buf = buf[:-1]  # strip trailing L
                buflist.append(buf)
        os.write(self._wf, (" ".join(buflist)).encode())
        self._getMode = 1 
开发者ID:myhdl,项目名称:myhdl,代码行数:21,代码来源:_Cosimulation.py

示例3: copyfileobj

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def copyfileobj(src, dst, length=None):
    """Copy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    """
    if length == 0:
        return
    if length is None:
        shutil.copyfileobj(src, dst)
        return

    BUFSIZE = 16 * 1024
    blocks, remainder = divmod(length, BUFSIZE)
    for b in range(blocks):
        buf = src.read(BUFSIZE)
        if len(buf) < BUFSIZE:
            raise IOError("end of file reached")
        dst.write(buf)

    if remainder != 0:
        buf = src.read(remainder)
        if len(buf) < remainder:
            raise IOError("end of file reached")
        dst.write(buf)
    return 
开发者ID:war-and-code,项目名称:jawfish,代码行数:26,代码来源:tarfile.py

示例4: addfile

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def addfile(self, tarinfo, fileobj=None):
        """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
           given, tarinfo.size bytes are read from it and added to the archive.
           You can create TarInfo objects using gettarinfo().
           On Windows platforms, `fileobj' should always be opened with mode
           'rb' to avoid irritation about the file size.
        """
        self._check("aw")

        tarinfo = copy.copy(tarinfo)

        buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
        self.fileobj.write(buf)
        self.offset += len(buf)

        # If there's data to follow, append it.
        if fileobj is not None:
            copyfileobj(fileobj, self.fileobj, tarinfo.size)
            blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
            if remainder > 0:
                self.fileobj.write(NUL * (BLOCKSIZE - remainder))
                blocks += 1
            self.offset += blocks * BLOCKSIZE

        self.members.append(tarinfo) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:tarfile.py

示例5: showTempPDF

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def showTempPDF(pdfData, cfgGl, mainFrame):
    try:
        try:
            util.removeTempFiles(misc.tmpPrefix)

            fd, filename = tempfile.mkstemp(prefix = misc.tmpPrefix,
                                            suffix = ".pdf")

            try:
                os.write(fd, pdfData)
            finally:
                os.close(fd)

            util.showPDF(filename, cfgGl, mainFrame)

        except IOError, (errno, strerror):
            raise MiscError("IOError: %s" % strerror)

    except TrelbyError, e:
        wx.MessageBox("Error writing temporary PDF file: %s" % e,
                      "Error", wx.OK, mainFrame) 
开发者ID:trelby,项目名称:trelby,代码行数:23,代码来源:gutil.py

示例6: _compile_module_file

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def _compile_module_file(template, text, filename, outputpath, module_writer):
    source, lexer = _compile(
        template, text, filename, generate_magic_comment=True
    )

    if isinstance(source, compat.text_type):
        source = source.encode(lexer.encoding or "ascii")

    if module_writer:
        module_writer(source, outputpath)
    else:
        # make tempfiles in the same location as the ultimate
        # location.   this ensures they're on the same filesystem,
        # avoiding synchronization issues.
        (dest, name) = tempfile.mkstemp(dir=os.path.dirname(outputpath))

        os.write(dest, source)
        os.close(dest)
        shutil.move(name, outputpath) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:template.py

示例7: _collect_protos

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def _collect_protos(argfile_fd, proto_files, dest):
  """Copies all proto_files into dest.

  Writes this list of files to `argfile_fd` which will be passed to protoc.

  Args:
    * argfile_fd (int): An open writable file descriptor for the argfile.
    * proto_files (List[Tuple[src_abspath: str, dest_relpath: str]])
    * dest (str): Path to the directory where we should collect the .proto
    files.

  Side-effects:
    * Each dest_relpath is written to `argfile_fd` on its own line.
    * Closes `argfile_fd`.
  """
  try:
    _makedirs = _DirMaker()
    for src_abspath, dest_relpath in proto_files:
      destpath = os.path.join(dest, dest_relpath)
      _makedirs(os.path.dirname(destpath))
      shutil.copyfile(src_abspath, destpath)
      os.write(argfile_fd, dest_relpath)
      os.write(argfile_fd, '\n')
  finally:
    os.close(argfile_fd)  # for windows 
开发者ID:luci,项目名称:recipes-py,代码行数:27,代码来源:proto_support.py

示例8: test_hooks

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def test_hooks(monkeypatch):
    def _boxed():
        return 1

    def _on_start():
        sys.stdout.write("some out\n")
        sys.stdout.flush()

    def _on_exit():
        sys.stderr.write("some err\n")
        sys.stderr.flush()

    result = py.process.ForkedFunc(_boxed, child_on_start=_on_start,
                                   child_on_exit=_on_exit).waitfinish()
    assert result.out == "some out\n"
    assert result.err == "some err\n"
    assert result.exitstatus == 0
    assert result.signal == 0
    assert result.retval == 1


# ======================================================================
# examples
# ======================================================================
# 
开发者ID:pytest-dev,项目名称:py,代码行数:27,代码来源:test_forkedfunc.py

示例9: test_suspend_resume

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def test_suspend_resume(self):
        cap = self.getcapture(out=True, err=False, in_=False)
        try:
            print ("hello")
            sys.stderr.write("error\n")
            out, err = cap.suspend()
            assert out == "hello\n"
            assert not err
            print ("in between")
            sys.stderr.write("in between\n")
            cap.resume()
            print ("after")
            sys.stderr.write("error_after\n")
        finally:
            out, err = cap.reset()
        assert out == "after\n"
        assert not err 
开发者ID:pytest-dev,项目名称:py,代码行数:19,代码来源:test_capture.py

示例10: test_callcapture_nofd

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def test_callcapture_nofd():
    def func(x, y):
        oswritebytes(1, "hello")
        oswritebytes(2, "hello")
        print (x)
        sys.stderr.write(str(y))
        return 42

    capfd = py.io.StdCaptureFD(patchsys=False)
    try:
        res, out, err = py.io.StdCapture.call(func, 3, y=4)
    finally:
        capfd.reset()
    assert res == 42
    assert out.startswith("3")
    assert err.startswith("4") 
开发者ID:pytest-dev,项目名称:py,代码行数:18,代码来源:test_capture.py

示例11: _gdb_core_debug

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def _gdb_core_debug(symbols, ucore=None, kcore=None, remote=None, solib_search=None):
    assert TOOL_GDB_NTO, "GDB targetting NTO not available for this platform"
    if kcore:
        assert TOOL_KDSRV, "kdserver not available for this platform"
    assert len([x for x in [ucore, kcore, remote] if x is not None]) == 1, "Must specify exactly one core file"
    with tempfile.TemporaryFile() as f:
        gdb_cmd = [TOOL_GDB_NTO, "-nx", "-x", GDB_CMDS, symbols]
        if ucore is not None:
            gdb_cmd.append(ucore)
        gdb = _common.subprocess.Popen(gdb_cmd, stdout=f, stderr=f, stdin=_common.subprocess.PIPE)
        if kcore is not None:
            gdb.stdin.write("target remote |%s %s\n" % (TOOL_KDSRV, kcore.replace("\\", "\\\\")))
        elif remote is not None:
            gdb.stdin.write("target remote %s\n" % remote)
        core = ucore or kcore
        for c in _gdb_cmd_gen(core=core, solib_search=solib_search, detach=not core):
            gdb.stdin.write("%s\n" % c)
        gdb_wait_st = _common.prof_timer()
        while gdb.poll() is None and (_common.prof_timer() - gdb_wait_st) < 20:
            time.sleep(0.1)
        if gdb.poll() is None:
            gdb.terminate()
        gdb.wait()
        f.seek(0)
        gdb_out = f.read()
    trim = gdb_out.find(r'$1 = "TRIM"')
    if trim != -1:
        gdb_out = "\n".join([l for l in gdb_out[:trim].splitlines()[:-1] if not l.startswith("#0")] +
                             gdb_out[trim:].splitlines()[1:] + [""])
    bt, cls = _process_gdb_output(gdb_out)
    gdb_out = _trim_disassembly(gdb_out)
    return _common.FuzzResult(cls, gdb_out, bt) 
开发者ID:blackberry,项目名称:ALF,代码行数:34,代码来源:_gdb.py

示例12: packet_writer_mac

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def packet_writer_mac(self, packet):
		packet = "\x00\x00\x00\x02"+packet
		os.write(self.tunnel, packet)

	# default packet writer for Linux 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:7,代码来源:Stateless_module.py

示例13: packet_writer_default

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def packet_writer_default(self, packet):
		os.write(self.tunnel, packet)

	# This function reades the packet from the tunnel.
	# on MacOS(X) utun, all packets needs to be prefixed with 4 specific bytes
	# this will take off the prefix if that is needed
	# first_read True: discard the first 4 bytes / utun related
	# serverorclient 1: server, there is no 4byte prefix, it comes fro the PS
	#				 0: client, it comes from the tunnel iface directly 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:11,代码来源:Stateless_module.py

示例14: packet_writer_mac

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def packet_writer_mac(self, packet):
		packet = "\x00\x00\x00\x02"+packet
		os.write(self.tunnel_w, packet)

	# default packet writer for Linux 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:7,代码来源:Stateful_module.py

示例15: packet_writer_default

# 需要导入模块: import os [as 别名]
# 或者: from os import write [as 别名]
def packet_writer_default(self, packet):
		os.write(self.tunnel_w, packet)

	# This function reades the packet from the tunnel.
	# on MacOS(X) utun, all packets needs to be prefixed with 4 specific bytes
	# this will take off the prefix if that is needed
	# first_read True: discard the first 4 bytes / utun related
	# serverorclient 1: server, there is no 4byte prefix, it comes fro the PS
	#				 0: client, it comes from the tunnel iface directly 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:11,代码来源:Stateful_module.py


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