no python2 nonsense

pull/1/head
Bobloy 7 years ago
parent bb6a336e0e
commit 33307aa76f

@ -58,19 +58,14 @@ class LevenshteinDistance(Comparator):
:rtype: float
"""
PYTHON = sys.version_info[0]
# Return 0 if either statement has a falsy text value
if not statement.text or not other_statement.text:
return 0
# Get the lowercase version of both strings
if PYTHON < 3:
statement_text = unicode(statement.text.lower()) # NOQA
other_statement_text = unicode(other_statement.text.lower()) # NOQA
else:
statement_text = str(statement.text.lower())
other_statement_text = str(other_statement.text.lower())
statement_text = str(statement.text.lower())
other_statement_text = str(other_statement.text.lower())
similarity = SequenceMatcher(
None,

@ -33,13 +33,6 @@ class Statement(StatementMixin):
except UnicodeEncodeError:
pass
# Prefer decoded utf8-strings in Python 2.7
if sys.version_info[0] < 3:
try:
text = text.decode('utf-8')
except UnicodeEncodeError:
pass
self.text = text
self.tags = kwargs.pop('tags', [])
self.in_response_to = kwargs.pop('in_response_to', [])

@ -13,9 +13,4 @@ class UnicodeString(TypeDecorator):
Coerce Python bytestrings to unicode before
saving them to the database.
"""
import sys
if sys.version_info[0] < 3:
if isinstance(value, str):
value = value.decode('utf-8')
return value

@ -14,10 +14,8 @@ class VariableInputTypeAdapter(InputAdapter):
def detect_type(self, statement):
import sys
if sys.version_info[0] < 3:
string_types = basestring # NOQA
else:
string_types = str
string_types = str
if hasattr(statement, 'text'):
return self.OBJECT

@ -30,11 +30,7 @@ def unescape_html(chatbot, statement):
import sys
# Replace HTML escape characters
if sys.version_info[0] < 3:
from HTMLParser import HTMLParser
html = HTMLParser()
else:
import html
import html
statement.text = html.unescape(statement.text)
@ -49,9 +45,6 @@ def convert_to_ascii(chatbot, statement):
import unicodedata
import sys
# Normalize unicode characters
if sys.version_info[0] < 3:
statement.text = unicode(statement.text) # NOQA
text = unicodedata.normalize('NFKD', statement.text)
text = text.encode('ascii', 'ignore').decode('utf-8')

@ -393,10 +393,10 @@ class UbuntuCorpusTrainer(Trainer):
file_kwargs = {}
if sys.version_info[0] > 2:
# Specify the encoding in Python versions 3 and up
file_kwargs['encoding'] = 'utf-8'
# WARNING: This might fail to read a unicode corpus file in Python 2.x
# Specify the encoding in Python versions 3 and up
file_kwargs['encoding'] = 'utf-8'
# WARNING: This might fail to read a unicode corpus file in Python 2.x
for file in glob.iglob(extracted_corpus_path):
self.logger.info('Training from: {}'.format(file))

@ -77,15 +77,8 @@ def input_function():
"""
import sys
if sys.version_info[0] < 3:
user_input = str(raw_input()) # NOQA
# Avoid problems using format strings with unicode characters
if user_input:
user_input = user_input.decode('utf-8')
else:
user_input = input() # NOQA
user_input = input() # NOQA
return user_input

Loading…
Cancel
Save