def upload():
    require_logged_in ()
    form = FORM (LABEL ('Map: '), INPUT (_type="file", _name="map"), BR (), LABEL ('EPSG: '), INPUT (_type="text", _name="epsg"), BR (), INPUT (_type="submit", _value="Upload"))
    if form.accepts (request, session):
        from os import mkdir
        from shutil import rmtree
        if form.vars.epsg:
            epsg = require_int (form.vars.epsg)
        else:
            epsg = 4326
        path = getcwd () + '/applications/' + request.application + '/.tmp/' + uuid4 ().hex
        filename = path + '/' + sub ('/', '', form.vars.map.filename)
        mkdir (path)
        buffer = open (filename, 'w')
        buffer.write (form.vars.map.file.read ())
        buffer.close ()
        proc = subprocess.Popen (['tar', '-xvf', filename, '-C', path], stdout = subprocess.PIPE)
        #proc = subprocess.Popen (['tar', '-tvf', filename], stdout = subprocess.PIPE)
        files = proc.communicate ()[0].split ('\n')
        #files = files [:len (files) - 2]
        matches = map (lambda x: search ('\.shp$', x), files)
        for item, m in zip (files, matches):
            if m:
                table_name = 'upload_' + uuid4 ().hex
                dp = deployment_settings.postgis
                dg = deployment_settings.geoserver
                proc1 = subprocess.Popen (['shp2pgsql', path + '/' + item, table_name], stdout = subprocess.PIPE)
                psql_dump = proc1.communicate ()[0]
                cursor = dp.connection ().cursor ()
                cursor.execute (psql_dump)
                req_body = '<featureType><name>%s</name><title>%s</title><srs>EPSG:%d</srs></featureType>' % (table_name, sub ('.shp', '', item), epsg)
                proc3 = subprocess.Popen (['curl', '-u', '%s:%s' % (dg.username, dg.password), '-v', '-XPOST', '-H', 'Content-type: text/xml', '-d', req_body, (dg.host, dg.port, dg.workspace, dg.pgis_store) % '%s:%d/geoserver/rest/workspaces/%s/datastores/%s/featuretypes'], stdout = subprocess.PIPE)
                proc3.communicate ()
                rmtree (path)
                response.flash = 'Map Successfully Uploaded'
                break
    return {'form': form}
dataset/ETHPy150Open dotskapes/dotSkapes/controllers/geoserver.py/upload/swapped operands of `%`