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


Python mmap.ACCESS_WRITE属性代码示例

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


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

示例1: create_shortcut

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def create_shortcut(lnk_out_path, target, parameters, working_dir, description, icon=None, run_as_admin=False, minimized=False):
    shell = win32com.client.Dispatch("WScript.Shell")
    shortcut = shell.CreateShortCut(lnk_out_path)
    shortcut.Targetpath = target
    shortcut.Arguments = '"{}"'.format(parameters)
    shortcut.Description = description
    shortcut.WorkingDirectory = working_dir
    if not icon is None:
        shortcut.IconLocation = icon
    if minimized:# 7 - Minimized, 3 - Maximized, 1 - Normal
        shortcut.WindowStyle = 7
    else:
        shortcut.WindowStyle = 1
    shortcut.save()

    if run_as_admin:
        with open(lnk_out_path, "r+b") as f:
            with contextlib.closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_WRITE)) as m:
                m[0x15] = m[0x15] | 0x20 # Enable 6th bit = Responsible for Run As Admin
                #m.flush() 
开发者ID:yarox24,项目名称:attack_monitor,代码行数:22,代码来源:installer.py

示例2: _initialize_shared_memory

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def _initialize_shared_memory(self):
        """
        This is the IPC channel between us (Python)
        and the PinTool (C/C++)
        """
        s_uint32 = self.utils.get_size_uint32()
        shm_name = "Local\\NaFlSharedMemory"

        self.shm_size = self.bitmap_size * s_uint32  # architecture dependent :)
        self.shm = mmap.mmap(0,
                        self.shm_size,
                        shm_name,
                        access = mmap.ACCESS_WRITE)

        if not self.shm:
            # Oops!
            self.ml.info('[!] Could not create the shared memory region')
            self.ml.info('[!] Aborting...')
            sys.exit(1) 
开发者ID:carlosgprado,项目名称:BrundleFuzz,代码行数:21,代码来源:BrundleFuzzClient.py

示例3: __new__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def __new__(subtype, shape, dtype=float, buffer=None, offset=0, strides=None, order=None, info=None):
		
		# Determine the size in bytes required to hold the array
		numBytes = _requiredSize(shape, dtype)
		
		# Create the temporary file, resize it, and map it into memory
		tempFile = tempfile.TemporaryFile()
		tempFile.truncate(numBytes)
		buf = mmap.mmap(tempFile.fileno(), numBytes, access=mmap.ACCESS_WRITE)
		
		# Create the ndarray with the memory map as the underlying buffer
		obj = super(TempfileBackedArray, subtype).__new__(subtype, shape, dtype, buf, 0, None, order)
		
		# Attach the file reference to the ndarray object
		obj._file = tempFile
		return obj 
开发者ID:PINTO0309,项目名称:MobileNetV2-PoseEstimation,代码行数:18,代码来源:ArrayUtils.py

示例4: test_file_update

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def test_file_update(self):
        aset   = AddressSet(self.TABLE_LEN)
        dbfile = tempfile.NamedTemporaryFile(delete=False)
        try:
            aset.tofile(dbfile)
            dbfile.seek(0)
            aset = AddressSet.fromfile(dbfile, mmap_access=mmap.ACCESS_WRITE)
            addr = "".join(chr(b) for b in xrange(20))
            aset.add(addr)
            aset.close()
            self.assertTrue(dbfile.closed)
            dbfile = open(dbfile.name, "rb")
            aset = AddressSet.fromfile(dbfile)
            self.assertIn(addr, aset)
            self.assertEqual(len(aset), 1)
        finally:
            aset.close()
            dbfile.close()
            os.remove(dbfile.name) 
开发者ID:gurnec,项目名称:btcrecover,代码行数:21,代码来源:test_seeds.py

示例5: __init__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def __init__(self, filename, read_mode=False):
        self._f = open(filename, 'rb' if read_mode else 'a+b')
        self._fname = filename
        capacity = os.fstat(self._f.fileno()).st_size
        if capacity == 0:
            self._f.truncate(_INITIAL_MMAP_SIZE)
            capacity = _INITIAL_MMAP_SIZE
        self._capacity = capacity
        self._m = mmap.mmap(self._f.fileno(), self._capacity,
                            access=mmap.ACCESS_READ if read_mode else mmap.ACCESS_WRITE)

        self._positions = {}
        self._used = _unpack_integer(self._m, 0)[0]
        if self._used == 0:
            self._used = 8
            _pack_integer(self._m, 0, self._used)
        else:
            if not read_mode:
                for key, _, pos in self._read_all_values():
                    self._positions[key] = pos 
开发者ID:prometheus,项目名称:client_python,代码行数:22,代码来源:mmap_dict.py

示例6: __init__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def __init__(self, filename, read_mode=False):
        self._f = open(filename, 'rb' if read_mode else 'a+b')
        self._fname = filename
        if os.fstat(self._f.fileno()).st_size == 0:
            self._f.truncate(_INITIAL_MMAP_SIZE)
        self._capacity = os.fstat(self._f.fileno()).st_size
        self._m = mmap.mmap(self._f.fileno(), self._capacity, access=mmap.ACCESS_READ if read_mode else mmap.ACCESS_WRITE)

        self._positions = {}
        self._used = _unpack_integer(self._m, 0)[0]
        if self._used == 0:
            self._used = 8
            _pack_integer(self._m, 0, self._used)
        else:
            if not read_mode:
                for key, _, pos in self._read_all_values():
                    self._positions[key] = pos 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:mmap_dict.py

示例7: __setstate__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def __setstate__(self, state):
        # If the object contained an mmap, recreate it from scratch
        if "dbfilename" in state:
            new = self.fromfile(open(state["dbfilename"], "r+b" if state["mmap_access"]==mmap.ACCESS_WRITE else "rb"),
                                mmap_access=state["mmap_access"], preload=False)
            self.__dict__ = new.__dict__.copy()
            new._dbfile = new._data = None  # ensure new's __del__() doesn't close() anything
        else:
            self.__dict__ = state 
开发者ID:gurnec,项目名称:btcrecover,代码行数:11,代码来源:addressset.py

示例8: _mmap_available

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def _mmap_available(cls):
        """Tests that mmap, and specifically mmap.flush works.  This may
        be the case on some uncommon platforms (see
        https://github.com/astropy/astropy/issues/968).

        If mmap.flush is found not to work, ``self.memmap = False`` is
        set and a warning is issued.
        """

        tmpfd, tmpname = tempfile.mkstemp()
        try:
            # Windows does not allow mappings on empty files
            os.write(tmpfd, b' ')
            os.fsync(tmpfd)
            try:
                mm = mmap.mmap(tmpfd, 1, access=mmap.ACCESS_WRITE)
            except OSError as exc:
                warnings.warn('Failed to create mmap: {}; mmap use will be '
                              'disabled'.format(str(exc)), AstropyUserWarning)
                del exc
                return False
            try:
                mm.flush()
            except OSError:
                warnings.warn('mmap.flush is unavailable on this platform; '
                              'using mmap in writeable mode will be disabled',
                              AstropyUserWarning)
                return False
            finally:
                mm.close()
        finally:
            os.close(tmpfd)
            os.remove(tmpname)

        return True 
开发者ID:holzschu,项目名称:Carnets,代码行数:37,代码来源:file.py

示例9: fromfile

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def fromfile(cls, dbfile, mmap_access = mmap.ACCESS_READ, preload = True):
        """Load the address set from a file

        :param dbfile: an open file object from which the set is loaded;
                       it will be closed by AddressSet when no longer needed
        :type dbfile: io.FileIO or file
        :param mmap_access: mmap.ACCESS_READ, .ACCESS_WRITE, or .ACCESS_COPY
        :type mmap_access: int
        :param preload: True to preload the entire address set, False to load on demand
        :type preload: bool
        """
        if "b" not in dbfile.mode:
            raise ValueError("must open file in binary mode")
        header_pos = dbfile.tell()
        if header_pos % mmap.ALLOCATIONGRANULARITY != 0:
            raise ValueError("header position in file must be a multiple of {}".format(mmap.ALLOCATIONGRANULARITY))
        #
        # Read in the header safely (ast.literal_eval() is safe for untrusted data)
        header = dbfile.read(cls.HEADER_LEN)
        if not header.startswith(cls.MAGIC):
            raise ValueError("unrecognized file format (invalid magic)")
        magic_len  = len(cls.MAGIC)
        config_end = header.find(b"\0", magic_len, cls.HEADER_LEN)
        assert config_end > 0
        config = ast.literal_eval(header[magic_len:config_end])
        if config["version"] != cls.VERSION:
            raise ValueError("can't load address database version {} (only supports {})"
                             .format(config["version"], cls.VERSION))
        #
        # Create an AddressSet object and replace its attributes
        self = cls(1)  # (size is irrelevant since it's getting replaced)
        cls._remove_nonheader_attribs(self.__dict__)
        for attr in self.__dict__.keys():  # only load expected attributes from untrusted data
            self.__dict__[attr] = config[attr]
        self._mmap_access = mmap_access
        #
        # The hash table is memory-mapped directly from the file instead of being loaded
        self._data = mmap.mmap(dbfile.fileno(), self._table_bytes, access=mmap_access,
                                offset= header_pos + cls.HEADER_LEN)
        if mmap_access == mmap.ACCESS_WRITE:
            dbfile.seek(header_pos)  # prepare for writing an updated header in close()
        else:
            dbfile.close()
        self._dbfile = dbfile
        #
        # Most of the time it makes sense to load the file serially instead of letting
        # the OS load each page as it's touched in random order, especially with HDDs;
        # reading a byte from each page is sufficient (CPython doesn't optimize this away)
        if preload:
            for i in xrange(self._table_bytes // mmap.PAGESIZE):
                self._data[i * mmap.PAGESIZE]
        #
        return self 
开发者ID:gurnec,项目名称:btcrecover,代码行数:55,代码来源:addressset.py

示例10: _query_pageant

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_WRITE [as 别名]
def _query_pageant(msg):
    hwnd = _get_pageant_window_object()
    if not hwnd:
        # Raise a failure to connect exception, pageant isn't running anymore!
        return None

    # Write our pageant request string into the file (pageant will read this to determine what to do)
    filename = tempfile.mktemp('.pag')
    map_filename = os.path.basename(filename)

    f = open(filename, 'w+b')
    f.write(msg )
    # Ensure the rest of the file is empty, otherwise pageant will read this
    f.write('\0' * (_AGENT_MAX_MSGLEN - len(msg)))
    # Create the shared file map that pageant will use to read from
    pymap = mmap.mmap(f.fileno(), _AGENT_MAX_MSGLEN, tagname=map_filename, access=mmap.ACCESS_WRITE)
    try:
        # Create an array buffer containing the mapped filename
        char_buffer = array.array("c", map_filename + '\0')
        char_buffer_address, char_buffer_size = char_buffer.buffer_info()
        # Create a string to use for the SendMessage function call
        cds = COPYDATASTRUCT(_AGENT_COPYDATA_ID, char_buffer_size, char_buffer_address)

        if _has_win32all:
            # win32gui.SendMessage should also allow the same pattern as
            # ctypes, but let's keep it like this for now...
            response = win32gui.SendMessage(hwnd, win32con_WM_COPYDATA, ctypes.sizeof(cds), ctypes.addressof(cds))
        elif _has_ctypes:
            response = ctypes.windll.user32.SendMessageA(hwnd, win32con_WM_COPYDATA, ctypes.sizeof(cds), ctypes.byref(cds))
        else:
            response = 0

        if response > 0:
            datalen = pymap.read(4)
            retlen = struct.unpack('>I', datalen)[0]
            return datalen + pymap.read(retlen)
        return None
    finally:
        pymap.close()
        f.close()
        # Remove the file, it was temporary only
        os.unlink(filename) 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:44,代码来源:win_pageant.py


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