Lint рефактор (кое-что поправлено)

This commit is contained in:
Jack Stdin
2016-02-03 14:33:01 +03:00
parent 16a144205b
commit 29a26132e1
11 changed files with 46 additions and 41 deletions

View File

@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
import re
from uuid import UUID
import psycopg2
from bottle import template
import sys
from aore.config import db_conf
from aore.dbutils.dbimpl import DBImpl
from aore.fias.search import SphinxSearch
from aore.config import db_conf
from uuid import UUID
import re
class FiasFactory:
@@ -30,18 +31,20 @@ class FiasFactory:
# rule - "boolean", "uuid", "text"
def __check_param(self, param, rule):
if rule == "boolean":
assert type(param) is bool, "Invalid parameter type"
assert isinstance(param, bool), "Invalid parameter type"
if rule == "uuid":
assert (type(param) is str or type(param) is unicode) and self.__check_uuid(param), "Invalid parameter value"
if rule == "text":
assert type(param) is str or type(param) is unicode, "Invalid parameter type"
assert (isinstance(param, str) or isinstance(param, unicode)) and self.__check_uuid(
param), "Invalid parameter value"
if rule == "text":
assert isinstance(param, str) or isinstance(param, unicode), "Invalid parameter type"
assert len(param) > 3, "Text too short"
pattern = re.compile("[A-za-zА-Яа-я \-,.#№]+")
pattern = re.compile(r"[A-za-zА-Яа-я \-,.#№]+")
assert pattern.match(param), "Invalid parameter value"
# text - строка поиска
# strong - строгий поиск (True) или "мягкий" (False) (с допущением ошибок, опечаток)
# Строгий используется при импорте из внешних систем (автоматически), где ошибка критична
# text - строка поиска
# strong - строгий поиск (True) или "мягкий" (False) (с допущением ошибок, опечаток)
# Строгий используется при импорте из внешних систем (автоматически), где ошибка критична
def find(self, text, strong=False):
try:
self.__check_param(text, "text")

View File

@@ -74,15 +74,12 @@ class SphinxSearch:
maxleven = jaro_rating - jaro_rating * self.regression_coef
if jaro_rating >= rating_limit and jaro_rating >= maxleven:
outlist.append([match['attrs']['word'], jaro_rating])
del jaro_rating
outlist.sort(key=lambda x: x[1], reverse=True)
return outlist
def __split_phrase(self, phrase):
phrase = unicode(phrase).replace('-', '').replace('@', '').lower()
return re.split(r"[ ,:.#$]+", phrase)
def __add_word_variations(self, word_entry, strong):
if word_entry.MT_MANY_SUGG and not strong:
suggs = self.__get_suggest(word_entry.word, self.rating_limit_soft, self.rating_limit_soft_count)
@@ -111,7 +108,11 @@ class SphinxSearch:
return we_list
def find(self, text, strong):
words = self.__split_phrase(text)
def split_phrase(phrase):
phrase = unicode(phrase).replace('-', '').replace('@', '').lower()
return re.split(r"[ ,:.#$]+", phrase)
words = split_phrase(text)
word_entries = self.__get_word_entries(words, strong)
word_count = len(word_entries)
for x in range(word_count, max(0, word_count - 3), -1):