OpenLayers OpenLayers

Changeset 5634

Show
Ignore:
Timestamp:
01/03/08 00:59:38 (1 year ago)
Author:
rdewit
Message:

Experimental support for KMZ files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/rdewit/kml/examples/proxy.cgi

    r5550 r5634  
    1313import cgi 
    1414import sys, os 
     15import zipfile, re, StringIO #for KMZ support 
     16 
    1517 
    1618# Designed to prevent Open Proxy type stuff. 
     19 
    1720 
    1821allowedHosts = ['www.openlayers.org', 'openlayers.org',  
     
    3740try: 
    3841    host = url.split("/")[2] 
    39     if allowedHosts and not host in allowedHosts: 
     42    #isLocalHost = (os.environ["SERVER_NAME"] == "localhost") or (os.environ["HTTP_HOST"] == "localhost") 
     43    isLocalHost = False 
     44    if not isLocalHost and allowedHosts and not host in allowedHosts: 
    4045        print "Status: 502 Bad Gateway" 
    4146        print "Content-Type: text/plain" 
     
    6368            print "Content-Type: text/plain" 
    6469        print 
     70 
     71        # Handle KMZ files 
     72        # First put content in StringIO object, so ZipFile can handle it 
     73        fileObject = StringIO.StringIO() 
     74        fileObject.write(y.read()) 
     75 
     76        # Now try to handle it as a ZIP file 
     77        try: 
     78            zipObject = zipfile.ZipFile(fileObject, "r") 
     79 
     80        # if not, print the contents (most cases) 
     81        except zipfile.BadZipfile: 
     82            fileObject.seek(0) # reset pointer to start of file 
     83            print fileObject.read() 
     84 
     85        # It *is* a ZIP! Now loop through all files in ZIP 
     86        # and only print the ones ending in .kml 
     87        else: 
     88            for info in zipObject.infolist(): 
     89                if re.search(r'''\.kml$''', info.filename): 
     90                  print zipObject.read(info.filename) 
     91            zipObject.close() 
    6592         
    66         print y.read() 
    67          
     93        fileObject.close() 
    6894        y.close() 
    6995    else: