|
80 | 80 | 'd': 'default', |
81 | 81 | } |
82 | 82 |
|
83 | | -# Add our keys to the urwid command_map |
| 83 | + |
| 84 | +def getpreferredencoding(): |
| 85 | + return locale.getpreferredencoding() or "ascii" |
84 | 86 |
|
85 | 87 |
|
86 | 88 | try: |
@@ -746,7 +748,8 @@ def _populate_completion(self): |
746 | 748 | func_name, args, is_bound, in_arg = self.argspec |
747 | 749 | args, varargs, varkw, defaults = args[:4] |
748 | 750 | if py3: |
749 | | - kwonly, kwonly_defaults = args[4:] |
| 751 | + kwonly = self.argspec[1][4] |
| 752 | + kwonly_defaults = self.argspec[1][5] or {} |
750 | 753 | else: |
751 | 754 | kwonly, kwonly_defaults = [], {} |
752 | 755 | markup = [('bold name', func_name), |
@@ -972,14 +975,17 @@ def prompt(self, more): |
972 | 975 | # We need the caption to use unicode as urwid normalizes later |
973 | 976 | # input to be the same type, using ascii as encoding. If the |
974 | 977 | # caption is bytes this breaks typing non-ascii into bpython. |
975 | | - # Currently this decodes using ascii as I do not know where |
976 | | - # ps1 is getting loaded from. If anyone wants to make |
977 | | - # non-ascii prompts work feel free to fix this. |
978 | 978 | if not more: |
979 | | - caption = ('prompt', self.ps1.decode('ascii')) |
| 979 | + if py3: |
| 980 | + caption = ('prompt', self.ps1) |
| 981 | + else: |
| 982 | + caption = ('prompt', self.ps1.decode(getpreferredencoding())) |
980 | 983 | self.stdout_hist += self.ps1 |
981 | 984 | else: |
982 | | - caption = ('prompt_more', self.ps2.decode('ascii')) |
| 985 | + if py3: |
| 986 | + caption = ('prompt_more', self.ps2) |
| 987 | + else: |
| 988 | + caption = ('prompt_more', self.ps2.decode(getpreferredencoding())) |
983 | 989 | self.stdout_hist += self.ps2 |
984 | 990 | self.edit = BPythonEdit(self.config, caption=caption) |
985 | 991 |
|
@@ -1024,7 +1030,11 @@ def handle_input(self, event): |
1024 | 1030 | self.history.append(inp) |
1025 | 1031 | self.edit.make_readonly() |
1026 | 1032 | # XXX what is this s_hist thing? |
1027 | | - self.stdout_hist += inp.encode(locale.getpreferredencoding()) + '\n' |
| 1033 | + if py3: |
| 1034 | + self.stdout_hist += inp |
| 1035 | + else: |
| 1036 | + self.stdout_hist += inp.encode(locale.getpreferredencoding()) |
| 1037 | + self.stdout_hist += '\n' |
1028 | 1038 | self.edit = None |
1029 | 1039 | # This may take a while, so force a redraw first: |
1030 | 1040 | self.main_loop.draw_screen() |
|
0 commit comments