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


Python os.close方法代码示例

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


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

示例1: whitelist_add

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def whitelist_add():
    log.info("whitelist_add called")
    try:
        file_ = request.files["file"]
        handle, filename = tempfile.mkstemp()
        os.close(handle)
        file_.save(filename)
        data = request.get_json()
        if data and "functions" in data:
            functions = data["functions"]
        else:
            functions = None
        bass.whitelist_add(filename, functions)
        os.unlink(filename)
    except KeyError:
        log.exception("")
        return make_response(jsonify(message = "Sample file 'file' missing in POST request"), 400)

    return jsonify(message = "OK") 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:21,代码来源:server.py

示例2: _symbolize

# 需要导入模块: import os [as 别名]
# 或者: from os import close [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

示例3: replace_client

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def replace_client(self, old_client, new_client):
		if old_client in self.clients:
			self.clients.remove(old_client)
			self.clients.append(new_client)
			try:
				old_client.get_pipe_w_fd().close()
			except:
				pass
			try:
				old_client.get_pipe_r_fd().close()
			except:
				pass
			try:
				socket.close(old_client.get_socket())
			except:
				pass

	# removing client from the client list 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:20,代码来源:packetselector.py

示例4: stop_running

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def stop_running(self):
        """
        Stops the program execution. Notifies the view to finish itself, then deletes the reference.
        :return: none

        :Author: Miguel Yanes Fernández
        """
        try:
            self.stop_scan()
            self.semGeneral.release()
            self.view.reaper_calls()
            self.show_message("\n\n\tClossing WiCC ...\n\n")
            os.close(2)  # block writing to stderr
            del self.view
            self.running_stopped = True
            exit(0)
        except:
            raise SystemExit 
开发者ID:pabloibiza,项目名称:WiCC,代码行数:20,代码来源:wicc_control.py

示例5: open_cracked_passwords

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def open_cracked_passwords(self):
        """
        Opens the cracked passwords file.

        :author: Pablo Sanz Alguacil
        """

        try:
            self.show_message("Opening passwords file")
            passwords = self.local_folder + "/" + self.passwords_file_name
            open(passwords, 'r').close()  # just to raise an exception if the file doesn't exists
            command = ['xdg-open', passwords]
            thread = threading.Thread(target=self.execute_command, args=(command,))
            thread.start()
        except FileNotFoundError:
            self.show_warning_notification("No stored cracked networks. You need to do and finish an attack") 
开发者ID:pabloibiza,项目名称:WiCC,代码行数:18,代码来源:wicc_control.py

示例6: update

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def update(ctx):
    """
    Update the chute from the working directory.
    """
    url = ctx.obj['chute_url']
    headers = {'Content-Type': 'application/x-tar'}

    if not os.path.exists("paradrop.yaml"):
        raise Exception("No paradrop.yaml file found in working directory.")

    with tempfile.TemporaryFile() as temp:
        tar = tarfile.open(fileobj=temp, mode="w")
        for dirName, subdirList, fileList in os.walk('.'):
            for fname in fileList:
                path = os.path.join(dirName, fname)
                arcname = os.path.normpath(path)
                tar.add(path, arcname=arcname)
        tar.close()

        temp.seek(0)
        res = router_request("PUT", url, headers=headers, data=temp)
        data = res.json()
        ctx.invoke(watch, change_id=data['change_id']) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:25,代码来源:device.py

示例7: update_database

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def update_database(self, field, value):
        """
        Update a given field in the database.
        """
        ret = True
        if self.database:
            try:
                cur = self.database.cursor()
                cur.execute("UPDATE image SET " + field + "='" + value +
                            "' WHERE id=%s", (self.tag, ))
                self.database.commit()
            except BaseException:
                ret = False
                traceback.print_exc()
                self.database.rollback()
            finally:
                if cur:
                    cur.close()
        return ret 
开发者ID:kyechou,项目名称:firmanal,代码行数:21,代码来源:extractor.py

示例8: daemonize

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def daemonize(logfile = None):
    # Fork once
    if os.fork() != 0:
        os._exit(0)
    # Create new session
    os.setsid()
    if os.fork() != 0:
        os._exit(0)
    os.chdir('/')
    fd = os.open('/dev/null', os.O_RDWR)
    os.dup2(fd, sys.__stdin__.fileno())
    if logfile != None:
        fake_stdout = open(logfile, 'a', 1)
        sys.stdout = fake_stdout
        sys.stderr = fake_stdout
        fd = fake_stdout.fileno()
    os.dup2(fd, sys.__stdout__.fileno())
    os.dup2(fd, sys.__stderr__.fileno())
    if logfile == None:
        os.close(fd) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:22,代码来源:misc.py

示例9: bz2open

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
        """Open bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        """
        if len(mode) > 1 or mode not in "rw":
            raise ValueError("mode must be 'r' or 'w'.")

        try:
            import bz2
        except ImportError:
            raise CompressionError("bz2 module is not available")

        fileobj = bz2.BZ2File(fileobj or name, mode,
                              compresslevel=compresslevel)

        try:
            t = cls.taropen(name, mode, fileobj, **kwargs)
        except (IOError, EOFError):
            fileobj.close()
            raise ReadError("not a bzip2 file")
        t._extfileobj = False
        return t 
开发者ID:war-and-code,项目名称:jawfish,代码行数:24,代码来源:tarfile.py

示例10: xzopen

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs):
        """Open lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        """
        if mode not in ("r", "w"):
            raise ValueError("mode must be 'r' or 'w'")

        try:
            import lzma
        except ImportError:
            raise CompressionError("lzma module is not available")

        fileobj = lzma.LZMAFile(fileobj or name, mode, preset=preset)

        try:
            t = cls.taropen(name, mode, fileobj, **kwargs)
        except (lzma.LZMAError, EOFError):
            fileobj.close()
            raise ReadError("not an lzma file")
        t._extfileobj = False
        return t

    # All *open() methods are registered here. 
开发者ID:war-and-code,项目名称:jawfish,代码行数:25,代码来源:tarfile.py

示例11: put

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def put(self, key, sync_object, callback=None):
        path = os.path.join(self.path, key)
        self.ensure_path(path)

        BUFFER_SIZE = 4096
        fd, temp_path = tempfile.mkstemp()

        try:
            with open(temp_path, "wb") as fp_1:
                while True:
                    data = sync_object.fp.read(BUFFER_SIZE)
                    fp_1.write(data)
                    if callback is not None:
                        callback(len(data))
                    if len(data) < BUFFER_SIZE:
                        break
            shutil.move(temp_path, path)
        except Exception:
            os.remove(temp_path)
            raise
        finally:
            os.close(fd)

        self.set_remote_timestamp(key, sync_object.timestamp) 
开发者ID:MichaelAquilina,项目名称:S4,代码行数:26,代码来源:local.py

示例12: _get_terminal_size_linux

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def _get_terminal_size_linux(self):
        def ioctl_GWINSZ(fd):
            try:
                import fcntl
                import termios

                cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
                return cr
            except:
                pass

        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
        if not cr:
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass

        if not cr:
            try:
                cr = (os.environ["LINES"], os.environ["COLUMNS"])
            except:
                return None

        return int(cr[1]), int(cr[0]) 
开发者ID:sdispater,项目名称:clikit,代码行数:29,代码来源:terminal.py

示例13: job_add_sample

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def job_add_sample(job_id):
    try:
        samples = []
        for name, file_ in request.files.items():
            handle, filename = tempfile.mkstemp()
            os.close(handle)
            file_.save(filename)
            samples.append(bass.get_job(job_id).add_sample(filename, name))
        return jsonify(message = "ok", samples = [s.json() for s in samples])
    except KeyError:
        log.exception("Invalid job id")
        return make_response(jsonify(message = "Invalid job id"), 400) 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:14,代码来源:server.py

示例14: usocket_path

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def usocket_path():
    fd, path = tempfile.mkstemp('cp_test.sock')
    os.close(fd)
    os.remove(path)
    return path 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:7,代码来源:test_wsgi_unix_socket.py

示例15: run

# 需要导入模块: import os [as 别名]
# 或者: from os import close [as 别名]
def run(self):
    print("Attempting to pipein to pipe")
    self.pipein = os.fdopen(self.pipein, 'w')
    self.pipein.write("My Name is Elliot")
    self.pipein.close() 
开发者ID:PacktPublishing,项目名称:Learning-Concurrency-in-Python,代码行数:7,代码来源:pipes.py


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