aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2018-03-29 10:56:25 +0000
committerPjotr Prins2018-03-29 10:56:25 +0000
commitd215602d89ec6d929d489cd7f3507cbe3e8c29bf (patch)
tree588f955e715f26fe194a320bc5914593567606f4
parentb43c4ceae959fdff685985acf33ac311e939b008 (diff)
downloadgenenetwork2-d215602d89ec6d929d489cd7f3507cbe3e8c29bf.tar.gz
Search: improved regex and some debug info
-rw-r--r--wqflask/wqflask/correlation/show_corr_results.py42
-rw-r--r--wqflask/wqflask/search_results.py16
2 files changed, 11 insertions, 47 deletions
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py
index 9b048346..2c6c3a14 100644
--- a/wqflask/wqflask/correlation/show_corr_results.py
+++ b/wqflask/wqflask/correlation/show_corr_results.py
@@ -52,6 +52,7 @@ import utility.webqtlUtil #this is for parallel computing only.
from wqflask.correlation import correlation_functions
from utility.benchmark import Bench
import utility.webqtlUtil
+from utility.type_checking import is_float, is_int, is_str, get_float, get_int, get_string
from wqflask import user_manager
from MySQLdb import escape_string as escape
@@ -77,47 +78,6 @@ def print_mem(stage=""):
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
#print("{}: {}".format(stage, mem/1024))
-def is_float(value):
- try:
- float(value)
- return True
- except:
- return False
-
-def is_int(value):
- try:
- int(value)
- return True
- except:
- return False
-
-def is_str(value):
- if value is None:
- return False
- try:
- str(value)
- return True
- except:
- return False
-
-def get_float(vars,name,default=None):
- if name in vars:
- if is_float(vars[name]):
- return float(vars[name])
- return None
-
-def get_int(vars,name,default=None):
- if name in vars:
- if is_int(vars[name]):
- return float(vars[name])
- return default
-
-def get_string(vars,name,default=None):
- if name in vars:
- if not vars[name] is None:
- return str(vars[name])
- return default
-
class AuthException(Exception):
pass
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index 41fcf873..53c96591 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -26,6 +26,7 @@ from db import webqtlDatabaseFunction
from flask import render_template
from utility import formatting
+from utility.type_checking import is_float, is_int, is_str, get_float, get_int, get_string
from utility.logger import getLogger
logger = getLogger(__name__ )
@@ -67,8 +68,9 @@ views.py).
self.search_terms = kw['search_terms_and']
search = self.search_terms
# check for dodgy search terms
- regex = re.compile("http:|href|sql|select|update",re.IGNORECASE)
- if regex.match(search):
+ rx = re.compile(r'.*\W(href|http|sql|select|update)\W.*',re.IGNORECASE)
+ if rx.match(search):
+ logger.info("Regex failed search")
self.search_term_exists = False
return
else:
@@ -80,11 +82,10 @@ views.py).
dataset_type = "Publish"
elif type == "Genotypes":
dataset_type = "Geno"
- elif type == "ProbeSet":
- dataset_type = "ProbeSet" # ProbeSet is default
else:
- self.search_term_exists = False
- return
+ dataset_type = "ProbeSet" # ProbeSet is default
+
+ assert(is_str(kw.get('dataset')))
self.dataset = create_dataset(kw['dataset'], dataset_type)
logger.debug("search_terms:", self.search_terms)
self.search()
@@ -158,6 +159,7 @@ statement and executes
else:
combined_where_clause += "OR"
else:
+ logger.debug("Search failed 1")
self.search_term_exists = False
if self.search_term_exists:
combined_where_clause = "(" + combined_where_clause + ")"
@@ -168,6 +170,7 @@ statement and executes
else:
logger.debug("len(search_terms)<=1")
if self.search_terms == []:
+ logger.debug("Search failed 2")
self.search_term_exists = False
else:
for a_search in self.search_terms:
@@ -175,6 +178,7 @@ statement and executes
if the_search != None:
self.results.extend(the_search.run())
else:
+ logger.debug("Search failed 3")
self.search_term_exists = False
if self.search_term_exists: