def import_(self, arg, key):
        'Import all profiles and decode them.'
        # Decode the data being imported.
        try:
            source = open(arg, 'rb')
        except:
            raise Exception('%r CANNOT BE OPENED' % arg)
        random.seed(key)
        major = spice.major()
        minor = spice.minor()
        random.seed() # Restore randomness.
        destination = cStringIO.StringIO()
        spice.decode(source, destination, major, minor)
        source.close()
        destination.seek(0)
        # Import the decoded profiles.
        len_name = destination.read(1)
        while len_name:
            len_profile = destination.read(3)
            assert len(len_profile) == 3, '%r IS CORRUPT' % arg
            len_name = ord(len_name) + 1
            name = destination.read(len_name)
            assert len(name) == len_name, '%r IS CORRUPT' % arg
            len_profile = self.int_(len_profile) + 1
            profile = destination.read(len_profile)
            assert len(profile) == len_profile, '%r IS CORRUPT' % arg
            # Check for duplicate names.
            if name in self.aliases:
                name = name[:250]
                code = ''.join(random.sample(self.STRING, 3))
                temp = '%s [%s]' % (name, code)
                while temp in self.aliases:
                    code = ''.join(random.sample(self.STRING, 3))
                    temp = '%s [%s]' % (name, code)
                name = temp
            # Save the new profile to disk.
            self.save_act(name, profile, *self.save_new(name, profile))
            len_name = destination.read(1)
Import all profiles and decode them.
recipes/Python/578368_Profile_Manager_Cave_Story/recipe-578368.py