<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def export(self, swf, shape, **export_opts):
 """ Exports the specified shape of the SWF to SVG. @param swf The SWF. @param shape Which shape to export, either by characterId(int) or as a Tag object. """


        # If `shape` is given as int, find corresponding shape tag.
        if isinstance(shape, Tag):
            shape_tag = shape
        else:
            shapes = [x for x in swf.all_tags_of_type((TagDefineShape, TagDefineSprite)) if x.characterId == shape]
            if len(shapes):
                shape_tag = shapes[0]
            else:
                raise Exception("Shape %s not found" % shape)

        from swf.movie import SWF

        # find a typical use of this shape
        example_place_objects = [x for x in swf.all_tags_of_type(TagPlaceObject) if x.hasCharacter and x.characterId == shape_tag.characterId]

        if len(example_place_objects):
            place_object = example_place_objects[0]
            characters = swf.build_dictionary()
            ids_to_export = place_object.get_dependencies()
            ids_exported = set()
            tags_to_export = []

            # this had better form a dag!
            while len(ids_to_export):
                id = ids_to_export.pop()
                if id in ids_exported or id not in characters:
                    continue
                tag = characters[id]
                ids_to_export.update(tag.get_dependencies())
                tags_to_export.append(tag)
                ids_exported.add(id)
            tags_to_export.reverse()
            tags_to_export.append(place_object)
        else:
            place_object = TagPlaceObject()
            place_object.hasCharacter = True
            place_object.characterId = shape_tag.characterId
            tags_to_export = [ shape_tag, place_object ]

        stunt_swf = SWF()
        stunt_swf.tags = tags_to_export

        return super(SingleShapeSVGExporterMixin, self).export(stunt_swf, **export_opts)