(XMLWriter.encode): Don't assume that we get a string in Latin1. If we get such as string convert it to unicode first, otherwise leave if alone before encoding. (SessionSaver.write_layer): Add support for writing both Layers and RasterLayers.