Skip to content

Commit

Permalink
Merge pull request #41 from aichaos/bug/40-unicode
Browse files Browse the repository at this point in the history
Fix a regression supporting Unicode in Python 2
  • Loading branch information
kirsle authored Aug 9, 2016
2 parents 6b5392d + 3eba80c commit 33e5a72
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions rivescript/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# https://www.rivescript.com/

from __future__ import unicode_literals
from .regexp import RE
from .exceptions import (
RiveScriptError, RepliesNotSortedError, NoDefaultRandomTopicError,
Expand Down
5 changes: 4 additions & 1 deletion rivescript/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import json
import re
from six.moves import input
from six import text_type
from six import text_type, PY2

from rivescript import RiveScript

Expand Down Expand Up @@ -245,6 +245,9 @@ def interactive_mode():

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

# Commands
if msg == '/help':
Expand Down
1 change: 1 addition & 0 deletions rivescript/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# https://www.rivescript.com/

from __future__ import unicode_literals
from .regexp import RE

import re
Expand Down
1 change: 1 addition & 0 deletions rivescript/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# https://www.rivescript.com/

from __future__ import unicode_literals
from .regexp import RE
from . import utils
import re
Expand Down
1 change: 1 addition & 0 deletions rivescript/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# https://www.rivescript.com/

from __future__ import unicode_literals
from .regexp import RE
import re
import string
Expand Down
8 changes: 8 additions & 0 deletions tests/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def test_unicode(self):
+ ブラッキー
- エーフィ
+ my favorite game is *
- <set game=<formal>>When did you first start playing <get game>?
+ what is my favorite game
- Wasn't it <get game>?
// Make sure %Previous continues working in UTF-8 mode.
+ knock knock
- Who's there?
Expand Down Expand Up @@ -51,6 +57,8 @@ def test_unicode(self):

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

0 comments on commit 33e5a72

Please sign in to comment.