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


Python mmap.ACCESS_READ属性代码示例

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


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

示例1: __init__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def __init__(self, path, mode):
        assert mode in ("r", "w")

        self.path = path
        self.file = open(self.path, mode + "b")
        self.mmfile = None
        self.mode = mode
        self.cnt = _CacheFileContent()

        if mode == "r":
            # Read the last part of the file which contains the contents of the
            # cache.
            self.cnt.read(self.file, self.path)
            self.mmfile = mmap.mmap(self.file.fileno(), 0, access=mmap.ACCESS_READ)
        else:
            # The 8 bytes header contain the position of the content index.
            # We fill this header with zeroes and write the actual position
            # once all samples have been written to the cache
            self.file.write(struct.pack('<Q', 0)) 
开发者ID:mme,项目名称:vergeml,代码行数:21,代码来源:cache.py

示例2: startFunction

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def startFunction(self):
        """ Return start function, attempt to find it in vba files if _startFunction is not set """
        result = None
        if self._startFunction is not None:
            result =  self._startFunction
        else:
             
            vbaFiles = self.getVBAFiles()
            for vbaFile in vbaFiles:
                if  os.stat(vbaFile).st_size != 0:  
                    with open(vbaFile, 'rb', 0) as file, mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s:
                        for potentialStartFunction in self.potentialStartFunctions:
                            if s.find(potentialStartFunction.encode()) != -1:
                                self._startFunction = potentialStartFunction
                                if self._startFunction not in self.reservedFunctions:
                                    self.reservedFunctions.append(self._startFunction)
                                result = potentialStartFunction
                                break                
        return result 
开发者ID:sevagas,项目名称:macro_pack,代码行数:21,代码来源:mp_module.py

示例3: getMainVBAFile

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def getMainVBAFile(self):
        """ return main vba file (the one containing macro entry point) """
        result = ""
        vbaFiles = self.getVBAFiles()
        if len(vbaFiles)==1:
            result = vbaFiles[0]
        else:
            if self.startFunction is not None:
                for vbaFile in vbaFiles:
                    if  os.stat(vbaFile).st_size != 0:  
                        with open(vbaFile, 'rb', 0) as file, mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s:
                            if s.find(self.startFunction.encode()) != -1:
                                result  = vbaFile
                                break
                            
        return result 
开发者ID:sevagas,项目名称:macro_pack,代码行数:18,代码来源:mp_module.py

示例4: test_main_gh1081

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def test_main_gh1081(self):
        """https://github.com/IronLanguages/main/issues/1081"""
        import io
        import mmap

        test_file_name = os.path.join(self.temporary_dir, "test_main_gh1081.bin")

        with open(test_file_name, "wb") as f:
            f.write(bytearray(range(256)))

        try:
            with io.open(test_file_name, "rb") as f:
                mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
                try:
                    self.assertEqual(mm[:], bytearray(range(256)))
                finally:
                    mm.close()
        finally:
            os.remove(test_file_name) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_regressions.py

示例5: test_file_handles

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def test_file_handles(self):
        # GH 14418 - don't close user provided file handles

        fh = StringIO('a,b\n1,2')
        self.read_csv(fh)
        assert not fh.closed

        with open(self.csv1, 'r') as f:
            self.read_csv(f)
            assert not f.closed

        # mmap not working with python engine
        if self.engine != 'python':

            import mmap
            with open(self.csv1, 'r') as f:
                m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
                self.read_csv(m)
                # closed attribute new in python 3.2
                if PY3:
                    assert not m.closed
                m.close() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:common.py

示例6: _read_word2vec_mmap

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def _read_word2vec_mmap(self, filename, idx, known_vocab, keep_unused):
        import mmap

        word_vectors = []
        with io.open(filename, "rb") as f:
            with contextlib.closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as m:
                header_end = m[:50].find(b"\n")
                vsz, dsz = map(int, (m[:header_end]).split(b" "))
                width = 4 * dsz
                current = header_end + 1
                for i in range(vsz):
                    word, vec, current = self._read_word2vec_line_mmap(m, width, current)
                    if word in self.vocab:
                        continue
                    if keep_unused is False and word not in known_vocab:
                        continue
                    if known_vocab and word in known_vocab:
                        known_vocab[word] = 0

                    word_vectors.append(vec)
                    self.vocab[word] = idx
                    idx += 1
                return word_vectors, dsz, known_vocab, idx 
开发者ID:dpressel,项目名称:mead-baseline,代码行数:25,代码来源:embeddings.py

示例7: __init__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def __init__(self, file_name='-', read_values=False, debug=False):
        self._debug = debug
        self._read_values = read_values
        if file_name == '-':
            fh = sys.stdin
        else:
            try:
                fh = open(file_name)
            except IOError as ex:
                raise ThriftFile.Error('Could not open %s: %s' % (file_name, ex))

        if HAS_MMAP and file_name != '-':
            self._data = mmap.mmap(fh.fileno(), 0, access=mmap.ACCESS_READ)
            self._view = None
        else:
            # this might hurt...
            self._data = fh.read()
            self._view = memoryview(self._data) 
开发者ID:pinterest,项目名称:thrift-tools,代码行数:20,代码来源:thrift_file.py

示例8: preprocess

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def preprocess(source):
    with open(source, 'rb', 0) as f, \
            mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as contents:
        for string in forbidden_strings:
            if contents.find(string) != -1:
                error_message = "Forbidden string '%s' is found." % string.decode()
                print(error_message, flush=True)
                post_data = {"error_message": error_message}
                exit_after_notifying_launcher(
                    ERR_CODE_CONTAININT_FORBIDDEN_STRING, post_data
                )

        for pattern in forbidden_pattern:
            match = re.search(pattern, contents)
            if match is not None:
                error_message = "The string '%s' in the source code matches forbidden pattern '%s'." % (
                    match.group(0).decode(), pattern.pattern.decode())
                print(error_message, flush=True)
                post_data = {"error_message": error_message}
                exit_after_notifying_launcher(
                    ERR_CODE_CONTAININT_FORBIDDEN_STRING, post_data) 
开发者ID:CryptoExperts,项目名称:wb_contest_submission_server,代码行数:23,代码来源:compile_and_test.py

示例9: startup

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def startup(self, test_file=None, dump_to=None):
        if test_file is None and not self._check_sim_status():
            return False

        if self._shared_mem is None:
            if test_file:
                f = open(test_file, 'rb')
                self._shared_mem = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
                self.__is_using_test_file = True
            else:
                self._shared_mem = mmap.mmap(0, MEMMAPFILESIZE, MEMMAPFILE, access=mmap.ACCESS_READ)

        if self._shared_mem:
            if dump_to:
                with open(dump_to, 'wb') as f:
                    f.write(self._shared_mem)
            self._header = Header(self._shared_mem)
            self.is_initialized = self._header.version >= 1 and len(self._header.var_buf) > 0

        return self.is_initialized 
开发者ID:kutu,项目名称:pyirsdk,代码行数:22,代码来源:irsdk.py

示例10: __init__

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

示例11: _detect_buffer_encoding

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def _detect_buffer_encoding(self, f):
        """Guess by checking BOM, and checking `_special_encode_check`, and using memory map."""

        encoding = None
        with contextlib.closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as m:
            encoding = self._analyze_file(m)
        return encoding 
开发者ID:facelessuser,项目名称:pyspelling,代码行数:9,代码来源:__init__.py

示例12: get_unicode_device_names

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def get_unicode_device_names():
    """Returns all Unicode strings within the binary currently being analysed in IDA which might be device names"""

    path = idc.GetInputFile()
    min_length = 4
    possible_names = set()
    with open(path, "rb") as f:
        b = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)

        for s in extract_unicode_strings(b, n=min_length):
            s_str = str(s.s)
            if s_str.startswith('\\Device\\') or s_str.startswith('\\DosDevices\\'):
                possible_names.add(str(s.s))
    return possible_names 
开发者ID:FSecureLABS,项目名称:win_driver_plugin,代码行数:16,代码来源:device_finder.py

示例13: test_file_handles_mmap

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def test_file_handles_mmap(c_parser_only, csv1):
    # gh-14418
    #
    # Don't close user provided file handles.
    parser = c_parser_only

    with open(csv1, "r") as f:
        m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
        parser.read_csv(m)

        if PY3:
            assert not m.closed
        m.close() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_c_parser_only.py

示例14: __init__

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def __init__(self, f):
        self.mmap = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:common.py

示例15: strings

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_READ [as 别名]
def strings(file_name, sections=None, min_length=4):
    """
    Finds all strings in a file; if it's an ELF file, you can specify where (in which section) to
    look for the strings.

    :param file_name: name of the file to be examined
    :param sections: a list of strings which identify the ELF sections; should be used only with ELF files
    :param min_length:
    :return:
    """
    pattern = '([\x20-\x7E]{' + str(min_length) + '}[\x20-\x7E]*)'  # ASCII table from character space to tilde
    pattern = pattern.encode()
    regexp = re.compile(pattern)
    if not sections:
        with open(file_name, 'rb') as f, mmap(f.fileno(), 0, access=ACCESS_READ) as m:
            for match in regexp.finditer(m):
                yield str(match.group(0), 'utf-8')
    else:
        with open(file_name, 'rb') as f:
            elffile = ELFFile(f)
            for section in sections:
                try:
                    sec = elffile.get_section_by_name(section)
                except AttributeError:
                    # section not found
                    continue
                # skip section if missing in elf file
                if not sec:
                    continue
                offset = sec['sh_offset']
                size = sec['sh_size']
                if offset is None or size is None:
                    continue
                # round to allocation granularity for mmap
                offset = max(offset - offset % ALLOCATIONGRANULARITY, 0)
                with mmap(f.fileno(), size, access=ACCESS_READ, offset=offset) as m:
                    for match in regexp.finditer(m):
                        yield str(match.group(0), 'utf-8') 
开发者ID:alessandrodd,项目名称:apk_api_key_extractor,代码行数:40,代码来源:strings_tool.py


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