<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
#http://localhost/wsgi/getSearchGeom.wsgi?searchtable=av_user.suchtabelle&displaytext=Oberlandautobahn (Strasse, Uster)

DB_CONN_STRING="host='yourhost' dbname='yourdb' port='5432' user='yourusername' password='<PASSWORD>'"

import re #regular expression support
import string #string manipulation support
from webob import Request
from webob import Response
import psycopg2 #PostgreSQL DB Connection
import psycopg2.extras #z.b. für named column indexes
import sys #für Fehlerreporting

def application(environ, start_response):
  request = Request(environ)
  searchtable = request.params["searchtable"]
  displaytext = request.params["displaytext"]

  #sanitize
  if re.search(r"[^A-Za-z,._]", searchtable):
    print >> environ['wsgi.errors'], "offending input: %s" % searchtable
    sql = ""
  else:
    sql = "SELECT ST_AsText(the_geom) AS geom FROM "+searchtable+" WHERE displaytext = %(displaytext)s;"
  
  result = "nogeom"
  
  if searchtable != "null":
    errorText = ''
    try:
      conn = psycopg2.connect(DB_CONN_STRING)
    except:
      errorText += 'error: database connection failed.'
      # write the error message to the error.log
      print >> environ['wsgi.errors'], "%s" % errorText
      response_headers = [('Content-type', 'text/plain'),
                          ('Content-Length', str(len(errorText)))]
      start_response('500 INTERNAL SERVER ERROR', response_headers)

      return [errorText]

    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

    try:
      cur.execute(sql,{'displaytext':displaytext})
    except:
      exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
      conn.close()
      errorText += 'error: could not execute query'
      # write the error message to the error.log<commit_msg>[BUG] Respond correctly if no geometry is available<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
#http://localhost/wsgi/getSearchGeom.wsgi?searchtable=av_user.suchtabelle&displaytext=Oberlandautobahn (Strasse, Uster)

DB_CONN_STRING="host='yourhost' dbname='yourdb' port='5432' user='yourusername' password='<PASSWORD>'"

import re #regular expression support
import string #string manipulation support
from webob import Request
from webob import Response
import psycopg2 #PostgreSQL DB Connection
import psycopg2.extras #z.b. für named column indexes
import sys #für Fehlerreporting

def application(environ, start_response):
  request = Request(environ)
  searchtable = request.params["searchtable"]
  displaytext = request.params["displaytext"]

  #sanitize
  if re.search(r"[^A-Za-z,._]", searchtable):
    print >> environ['wsgi.errors'], "offending input: %s" % searchtable
    sql = ""
  else:
    sql = "SELECT COALESCE(ST_AsText(the_geom), \'nogeom\') AS geom FROM "+searchtable+" WHERE displaytext = %(displaytext)s;"
  
  result = "nogeom"
  
  if searchtable != "null":
    errorText = ''
    try:
      conn = psycopg2.connect(DB_CONN_STRING)
    except:
      errorText += 'error: database connection failed.'
      # write the error message to the error.log
      print >> environ['wsgi.errors'], "%s" % errorText
      response_headers = [('Content-type', 'text/plain'),
                          ('Content-Length', str(len(errorText)))]
      start_response('500 INTERNAL SERVER ERROR', response_headers)

      return [errorText]

    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

    try:
      cur.execute(sql,{'displaytext':displaytext})
    except:
      exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
      conn.close()
      errorText += 'error: could not execute query'
      # write the error message to the error.log
{'fraction_non_alphanumeric': 0.12399139322216245, 'fraction_numerical': 0.006455083378160301, 'mean_word_length': 4.046132971506106, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2064705', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1137, 'n_words': 281}