Esempio n. 1
0
    def _write(self, config):
        # Sort frames by 'importance', then reverse frame size and then frame
        # hash to get a stable result
        order = ["TIT2", "TPE1", "TRCK", "TALB", "TPOS", "TDRC", "TCON"]

        framedata = [(f, save_frame(f, config=config))
                     for f in itervalues(self)]

        def get_prio(frame):
            try:
                return order.index(frame.FrameID)
            except ValueError:
                return len(order)

        def sort_key(items):
            frame, data = items
            return (get_prio(frame), len(data), frame.HashKey)

        framedata = [d for (f, d) in sorted(framedata, key=sort_key)]

        # only write unknown frames if they were loaded from the version
        # we are saving with. Theoretically we could upgrade frames
        # but some frames can be nested like CHAP, so there is a chance
        # we create a mixed frame mess.
        if self._unknown_v2_version == config.v2_version:
            framedata.extend(data for data in self.unknown_frames
                             if len(data) > 10)

        return bytearray().join(framedata)
Esempio n. 2
0
    def _write(self, config):
        # Sort frames by 'importance', then reverse frame size and then frame
        # hash to get a stable result
        order = ["TIT2", "TPE1", "TRCK", "TALB", "TPOS", "TDRC", "TCON"]

        framedata = [
            (f, save_frame(f, config=config)) for f in itervalues(self)]

        def get_prio(frame):
            try:
                return order.index(frame.FrameID)
            except ValueError:
                return len(order)

        def sort_key(items):
            frame, data = items
            return (get_prio(frame), len(data), frame.HashKey)

        framedata = [d for (f, d) in sorted(framedata, key=sort_key)]

        # only write unknown frames if they were loaded from the version
        # we are saving with. Theoretically we could upgrade frames
        # but some frames can be nested like CHAP, so there is a chance
        # we create a mixed frame mess.
        if self._unknown_v2_version == config.v2_version:
            framedata.extend(data for data in self.unknown_frames
                             if len(data) > 10)

        return bytearray().join(framedata)
Esempio n. 3
0
 def test_values(self):
     self.failUnlessEqual(
         list(self.fdict.values()), list(self.rdict.values()))
     self.failUnlessEqual(
         list(itervalues(self.fdict)), list(itervalues(self.rdict)))
Esempio n. 4
0
 def test_values(self):
     self.failUnlessEqual(list(self.fdict.values()),
                          list(self.rdict.values()))
     self.failUnlessEqual(list(itervalues(self.fdict)),
                          list(itervalues(self.rdict)))