當前位置: 首頁>>代碼示例>>Python>>正文


Python BinaryIO.tell方法代碼示例

本文整理匯總了Python中typing.BinaryIO.tell方法的典型用法代碼示例。如果您正苦於以下問題:Python BinaryIO.tell方法的具體用法?Python BinaryIO.tell怎麽用?Python BinaryIO.tell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing.BinaryIO的用法示例。


在下文中一共展示了BinaryIO.tell方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: put

# 需要導入模塊: from typing import BinaryIO [as 別名]
# 或者: from typing.BinaryIO import tell [as 別名]
 def put(
     self, namespace: str, metadata: Dict[str, Any], bytes_io: BinaryIO,
 ) -> None:
     """Store a file (``bytes_io``) inside ``namespace``."""
     if bytes_io.tell():
         bytes_io.seek(0)
     outdir = self._dir_of(namespace)
     if not outdir.exists():
         outdir.mkdir(parents=True)  # Create namespace directory as needed
     outfile = outdir / self._get_filename(metadata)
     with open(str(outfile), mode='wb', buffering=MEGABYTE) as writer:
         while True:
             chunk = bytes_io.read(MEGABYTE)
             if chunk:
                 writer.write(chunk)
             else:
                 break
     assert outfile.lstat().st_size == metadata['length']
開發者ID:nandoflorestan,項目名稱:keepluggable,代碼行數:20,代碼來源:local.py

示例2: _read_sequences

# 需要導入模塊: from typing import BinaryIO [as 別名]
# 或者: from typing.BinaryIO import tell [as 別名]
    def _read_sequences(f: BinaryIO, off, count) -> List[MDLSequence]:
        """Split this off to decrease stack in main parse method."""
        f.seek(off)
        sequences = [None] * count  # type: List[MDLSequence]
        for i in range(count):
            start_pos = f.tell()
            (
                base_ptr,
                label_pos,
                act_name_pos,
                flags,
                _,  # Seems to be a pointer.
                act_weight,
                event_count,
                event_pos,
            ) = str_read('8i', f)
            bbox_min = str_readvec(f)
            bbox_max = str_readvec(f)

            # Skip 20 ints, 9 floats to get to keyvalues = 29*4 bytes
            # Then 8 unused ints.
            (
                keyvalue_pos,
                keyvalue_size,
            ) = str_read('116xii32x', f)
            end_pos = f.tell()

            f.seek(start_pos + event_pos)
            events = [None] * event_count  # type: List[SeqEvent]
            for j in range(event_count):
                event_start = f.tell()
                (
                    event_cycle,
                    event_index,
                    event_flags,
                    event_options,
                    event_nameloc,
                ) = str_read('fii64si', f)
                event_end = f.tell()

                # There are two event systems.
                if event_flags == 1 << 10:
                    # New system, name in the file.
                    event_name = read_nullstr(f, event_start + event_nameloc)
                    if event_name.isdigit():
                        try:
                            event_type = ANIM_EVENT_BY_INDEX[int(event_name)]
                        except KeyError:
                            raise ValueError('Unknown event index!')
                    else:
                        try:
                            event_type = ANIM_EVENT_BY_NAME[event_name]
                        except KeyError:
                            # NPC-specific events, declared dynamically.
                            event_type = event_name
                else:
                    # Old system, index.
                    try:
                        event_type = ANIM_EVENT_BY_INDEX[event_index]
                    except KeyError:
                        # raise ValueError('Unknown event index!')
                        print('Unknown: ', event_index, event_options.rstrip(b'\0'))
                        continue

                f.seek(event_end)
                events[j] = SeqEvent(
                    type=event_type,
                    cycle=event_cycle,
                    options=event_options.rstrip(b'\0').decode('ascii')
                )

            if keyvalue_size:
                keyvalues = read_nullstr(f, start_pos + keyvalue_pos)
            else:
                keyvalues = ''

            sequences[i] = MDLSequence(
                label=read_nullstr(f, start_pos + label_pos),
                act_name=read_nullstr(f, start_pos + act_name_pos),
                flags=flags,
                act_weight=act_weight,
                events=events,
                bbox_min=bbox_min,
                bbox_max=bbox_max,
                keyvalues=keyvalues,
            )

            f.seek(end_pos)

        return sequences
開發者ID:TeamSpen210,項目名稱:srctools,代碼行數:92,代碼來源:mdl.py

示例3: _load

# 需要導入模塊: from typing import BinaryIO [as 別名]
# 或者: from typing.BinaryIO import tell [as 別名]
    def _load(self, f: BinaryIO):
        """Read data from the MDL file."""
        assert f.tell() == 0, "Doesn't begin at start?"
        if f.read(4) != b'IDST':
            raise ValueError('Not a model!')
        (
            self.version,
            name,
            file_len,
            # 4 bytes are unknown...
        ) = str_read('i 4x 64s i', f)

        if not 44 <= self.version <= 49:
            raise ValueError('Unknown MDL version {}!'.format(self.version))

        self.name = name.rstrip(b'\0').decode('ascii')
        self.eye_pos = str_readvec(f)
        self.illum_pos = str_readvec(f)
        # Approx dimensions
        self.hull_min = str_readvec(f)
        self.hull_max = str_readvec(f)
        
        self.view_min = str_readvec(f)
        self.view_max = str_readvec(f)

        # Break up the reading a bit to limit the stack size.
        (
            flags,

            bone_count,
            bone_off,

            bone_controller_count, bone_controller_off,

            hitbox_count, hitbox_off,
            anim_count, anim_off,
            sequence_count, sequence_off,
        ) = str_read('11I', f)

        self.flags = Flags(flags)

        (
            activitylistversion, eventsindexed,

            texture_count, texture_offset,
            cdmat_count, cdmat_offset,
            
            skinref_count, skinref_ind, skinfamily_count,
            
            bodypart_count, bodypart_offset,
            attachment_count, attachment_offset,
        ) = str_read('13i', f)

        (
            localnode_count,
            localnode_index,
            localnode_name_index,
         
            # mstudioflexdesc_t
            flexdesc_count,
            flexdesc_index,
         
            # mstudioflexcontroller_t
            flexcontroller_count,
            flexcontroller_index,
         
            # mstudioflexrule_t
            flexrules_count,
            flexrules_index,
         
            # IK probably refers to inverse kinematics
            # mstudioikchain_t
            ikchain_count,
            ikchain_index,
         
            # Information about any "mouth" on the model for speech animation
            # More than one sounds pretty creepy.
            # mstudiomouth_t
            mouths_count, 
            mouths_index,
         
            # mstudioposeparamdesc_t
            localposeparam_count,
            localposeparam_index,
        ) = str_read('15I', f)

        # VDC:
        # For anyone trying to follow along, as of this writing,
        # the next "surfaceprop_index" value is at position 0x0134 (308)
        # from the start of the file.
        assert f.tell() == 308, 'Offset wrong? {} != 308 {}'.format(f.tell(), f)

        (
            # Surface property value (single null-terminated string)
            surfaceprop_index,
         
            # Unusual: In this one index comes first, then count.
            # Key-value data is a series of strings. If you can't find
            # what you're interested in, check the associated PHY file as well.
            keyvalue_index,
#.........這裏部分代碼省略.........
開發者ID:TeamSpen210,項目名稱:srctools,代碼行數:103,代碼來源:mdl.py


注:本文中的typing.BinaryIO.tell方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。