當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。