Skip to content

Commit 33e5a72

Browse files
authored
Merge pull request aichaos#41 from aichaos/bug/40-unicode
Fix a regression supporting Unicode in Python 2
2 parents 6b5392d + 3eba80c commit 33e5a72

6 files changed

Lines changed: 16 additions & 1 deletion

File tree

rivescript/brain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# https://www.rivescript.com/
77

8+
from __future__ import unicode_literals
89
from .regexp import RE
910
from .exceptions import (
1011
RiveScriptError, RepliesNotSortedError, NoDefaultRandomTopicError,

rivescript/interactive.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
import re
1313
from six.moves import input
14-
from six import text_type
14+
from six import text_type, PY2
1515

1616
from rivescript import RiveScript
1717

@@ -245,6 +245,9 @@ def interactive_mode():
245245

246246
while True:
247247
msg = input("You> ")
248+
if PY2:
249+
# For Python 2 only: cast the message to Unicode.
250+
msg = msg.decode("utf-8")
248251

249252
# Commands
250253
if msg == '/help':

rivescript/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# https://www.rivescript.com/
77

8+
from __future__ import unicode_literals
89
from .regexp import RE
910

1011
import re

rivescript/sorting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# https://www.rivescript.com/
77

8+
from __future__ import unicode_literals
89
from .regexp import RE
910
from . import utils
1011
import re

rivescript/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# https://www.rivescript.com/
77

8+
from __future__ import unicode_literals
89
from .regexp import RE
910
import re
1011
import string

tests/test_unicode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def test_unicode(self):
2020
+ ブラッキー
2121
- エーフィ
2222
23+
+ my favorite game is *
24+
- <set game=<formal>>When did you first start playing <get game>?
25+
26+
+ what is my favorite game
27+
- Wasn't it <get game>?
28+
2329
// Make sure %Previous continues working in UTF-8 mode.
2430
+ knock knock
2531
- Who's there?
@@ -51,6 +57,8 @@ def test_unicode(self):
5157

5258
self.reply("äh", "What's the matter?")
5359
self.reply("ブラッキー", "エーフィ")
60+
self.reply("My favorite game is Pokémon", "When did you first start playing Pokémon?")
61+
self.reply("What is my favorite game?", "Wasn't it Pokémon?")
5462
self.reply("knock knock", "Who's there?")
5563
self.reply("Orange", "Orange who?")
5664
self.reply("banana", "Haha! Banana!")

0 commit comments

Comments
 (0)