def compress_kml(kml):
 kmz = cStringIO.StringIO()
 zf = zipfile.ZipFile(kmz, 'a', zipfile.ZIP_DEFLATED)
 zf.writestr('doc.kml', kml.encode(settings.DEFAULT_CHARSET))
 zf.close()
 kmz.seek(0)
 return kmz.read()

def compress_kml ( kml ) : kmz = cStringIO . StringIO ( ) zf = zipfile . ZipFile ( kmz , 'a' , zipfile . ZIP_DEFLATED ) zf . writestr ( 'doc.kml' , kml . encode ( settings . DEFAULT_CHARSET ) ) zf . close ( ) kmz . seek ( 0 ) return kmz . read ( )
returns compressed kmz from the given kml string .