Пример #1
0
    def test_main(self):
        self.assertEqual(from_filetime(116444736000000000),
                         datetime(1970, 1, 1))

        current = time()
        filetime = current * 10000000 + 116444736000000000
        a = from_filetime(filetime)
        b = datetime.utcfromtimestamp(current)

        try:
            self.assertEqual(a, b)
        except AssertionError:
            # TODO Retest one microsecond leaking. Maybe bug.
            if (a - b).microseconds == 1 or (b - a).microseconds == 1:
                pass
            else:
                raise
Пример #2
0
    def test_main(self):
        self.assertEqual(from_filetime(116444736000000000),
                         datetime(1970, 1, 1))

        current = time()
        filetime = current * 10000000 + 116444736000000000
        a = from_filetime(filetime)
        b = datetime.utcfromtimestamp(current)

        try:
            self.assertEqual(a, b)
        except AssertionError:
            # TODO Retest one microsecond leaking. Maybe bug.
            if (a - b).microseconds == 1 or (b - a).microseconds == 1:
                pass
            else:
                raise
Пример #3
0
    def __init__(self, entry_id, source, position):
        super(Entry, self).__init__(source.minimum_defect)

        # pylint: disable=C0103
        self.id = entry_id
        self.source = source

        self.source.seek(position)
        try:
            (name, name_length, self.type, self.color, self.left_sibling_id,
             self.right_sibling_id, self.child_id, clsid, self.state_bits,
             creation_time, modified_time, self.sector_start, self.size) \
                = unpack('<64sHBBLLL16sLQQLQ', self.source.read(128))

            try:
                self.name = name[:name_length].decode("utf-16").rstrip("\0")
            except UnicodeDecodeError:
                self._error("Bad Directory Entry name, maybe truncated.")

            if search(r'[/\\:!]', self.name, UNICODE):
                self._warning("The following characters are illegal and MUST "
                              "NOT be part of the name: '/', '\', ':', '!'.")

            if self.type not in (UNALLOCATED, STORAGE, STREAM, ROOT):
                self._error("This field MUST be 0x00, 0x01, 0x02, or 0x05, "
                            "depending on the actual type of object. All "
                            "other values are not valid.")
            elif self.type == UNALLOCATED:
                self._error("Can't create Directory Entry for unallocated "
                            "place.")

            if self.color not in (0x00, 0x01):
                self._warning("This field MUST be 0x00 (red) or 0x01 (black). "
                              "All other values are not valid.")

            if MAXREGSID < self.left_sibling_id < NOSTREAM:
                self._warning("This field contains the Stream ID of the left "
                              "sibling. If there is no left sibling, the "
                              "field MUST be set to NOSTREAM (0xFFFFFFFF).")
                self.left_sibling_id = NOSTREAM
            if MAXREGSID < self.right_sibling_id < NOSTREAM:
                self._warning("This field contains the Stream ID of the right "
                              "sibling. If there is no right sibling, the "
                              "field MUST be set to NOSTREAM (0xFFFFFFFF).")
                self.right_sibling_id = NOSTREAM
            if MAXREGSID < self.child_id < NOSTREAM:
                self._warning("This field contains the Stream ID of a child "
                              "object. If there is no child object, then the "
                              "field MUST be set to NOSTREAM (0xFFFFFFFF).")
                self.child_id = NOSTREAM

            self.clsid = Guid(clsid)

            self.creation_time = from_filetime(creation_time) \
                if creation_time else None
            self.modified_time = from_filetime(modified_time) \
                if modified_time else None

            if self.source.header.version[0] == 3 and self.size > 0x80000000:
                self._error("For a version 3 compound file 512-byte sector "
                            "size, this value of this field MUST be less than "
                            "or equal to 0x80000000.")

            self._is_mini = self.type != ROOT \
                and self.size < self.source.header.cutoff_size

            self._position = 0
            self._position_in_sector = 0
            self._source_position = self.source.tell()

            self._sector_number = self.sector_start

            self.next_sector = self.source.next_minifat if self._is_mini \
                else self.source.next_fat

            self.seek(0)
        except UnpackError:
            self._fatal("Bad Directory Entry header")