From e2a2d4e0bd7d215f08228a74eab551cf313c9715 Mon Sep 17 00:00:00 2001 From: ryncsn Date: Wed, 25 Jan 2017 13:33:14 +0100 Subject: [PATCH 1/2] Fix problem with newer curses --- dice/client/panel.py | 24 ++++++++++++------------ dice/client/window.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dice/client/panel.py b/dice/client/panel.py index 29e1fd7..05d163c 100644 --- a/dice/client/panel.py +++ b/dice/client/panel.py @@ -17,9 +17,9 @@ def add_item(self, bundle): class _Pad(object): def __init__(self, height, width): - self.width = width - self.height = height - self.pad = curses.newpad(height, width) + self.width = int(width) + self.height = int(height) + self.pad = curses.newpad(self.height, self.width) self.cur_y = 1 def box(self): @@ -30,9 +30,9 @@ def reset(self): self.cur_y = 1 def resize(self, height, width): - self.width = width - self.height = height - self.pad.resize(height, width) + self.width = int(width) + self.height = int(height) + self.pad.resize(self.height, self.width) def println(self, text, align='left', style=curses.A_NORMAL): if self.cur_y > self.height - 2: @@ -55,17 +55,17 @@ class _PanelBase(object): def __init__(self, screen, height, width, x=0, y=0): self.screen = screen - self.height = height - self.width = width + self.height = int(height) + self.width = int(width) self.pad = _Pad(self.height, self.width) self.resize(self.height, self.width) - self.x, self.y = x, y + self.x, self.y = int(x), int(y) self.keypress_listeners = {} def resize(self, height, width): - self.height = height - self.width = width - self.pad.resize(height, width) + self.height = int(height) + self.width = int(width) + self.pad.resize(self.height, self.width) def add_keypress_listener(self, name, key, callback): if name not in self.keypress_listeners: diff --git a/dice/client/window.py b/dice/client/window.py index b9bda8d..7da9811 100644 --- a/dice/client/window.py +++ b/dice/client/window.py @@ -31,13 +31,13 @@ def __init__(self, app): self.stat_panel = panel.ListPanel( self.screen, - self.height, self.width / 6, + self.height, int(self.width / 6), format_str='{count} {key}' ) self.items_panel = panel.ListPanel( self.screen, - self.height, self.width / 2, + self.height, int(self.width / 2), x=self.width / 6, y=0, format_str='{item}' ) From c2946d05e8b14cb163d4ee50eb311b97376c1dc5 Mon Sep 17 00:00:00 2001 From: ryncsn Date: Wed, 25 Jan 2017 13:34:02 +0100 Subject: [PATCH 2/2] Fix some breakge on Python3 --- dice/client/__init__.py | 6 +++--- dice/client/panel.py | 2 +- dice/core/symbol.py | 4 ++-- dice/utils/__init__.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dice/client/__init__.py b/dice/client/__init__.py index 0100733..fb77430 100644 --- a/dice/client/__init__.py +++ b/dice/client/__init__.py @@ -284,7 +284,7 @@ def run_tests(self): Iteratively run tests. """ while not self.exiting: - item = random.choice(self.providers.values()).generate() + item = random.choice(list(self.providers.values())).generate() item.run() self.last_item = item @@ -323,7 +323,7 @@ def update_window(self): panel.clear() cat_name, item_idx = self.cur_class if cat_name is not None and item_idx is not None: - item_name, stat = self.stats[cat_name].items()[item_idx] + item_name, stat = list(self.stats[cat_name].items())[item_idx] try: for item in self.stats[cat_name][item_name].queue: bundle = {'item': item.cmdline} @@ -336,7 +336,7 @@ def update_window(self): panel.clear() cat_name, item_idx = self.cur_class if cat_name is not None and item_idx is not None: - item_name, stat = self.stats[cat_name].items()[item_idx] + item_name, stat = list(self.stats[cat_name].items())[item_idx] items = self.stats[cat_name][item_name].queue item_name, item_idx = self.cur_item diff --git a/dice/client/panel.py b/dice/client/panel.py index 05d163c..4e0e451 100644 --- a/dice/client/panel.py +++ b/dice/client/panel.py @@ -199,7 +199,7 @@ def draw(self, active=False): item_idx = None if self.catalogs: # pylint: disable=unsubscriptable-object - cat_name = self.catalogs.keys()[0] + cat_name = list(self.catalogs.keys())[0] items = self.catalogs[cat_name].items if items: item_idx = 0 diff --git a/dice/core/symbol.py b/dice/core/symbol.py index 53585ac..590cdfa 100644 --- a/dice/core/symbol.py +++ b/dice/core/symbol.py @@ -54,7 +54,7 @@ def generate(self): Generate a random bytes string. """ cnt = int(random.weibullvariate(65535, 1)) - return ''.join(bt for bt in os.urandom(cnt) if bt != b'\x00') + return ''.join(str(bt) for bt in os.urandom(cnt) if bt != b'\x00') class NonEmptyBytes(Bytes): @@ -66,7 +66,7 @@ def generate(self): Generate a random non-empty bytes string. """ cnt = int(random.weibullvariate(65535, 1)) + 1 - return ''.join(bt for bt in os.urandom(cnt) if bt != b'\x00') + return ''.join(str(bt) for bt in os.urandom(cnt) if bt != b'\x00') class String(Bytes): diff --git a/dice/utils/__init__.py b/dice/utils/__init__.py index d1ca6bc..3bacc13 100644 --- a/dice/utils/__init__.py +++ b/dice/utils/__init__.py @@ -122,10 +122,10 @@ def run(cmdline, timeout=10): select.select([process.stdout, process.stderr], [], [], 0.1) try: - out_lines = process.stdout.read() + out_lines = str(process.stdout.read()) if out_lines: result.stdout += out_lines - err_lines = process.stderr.read() + err_lines = str(process.stderr.read()) if err_lines: result.stderr += err_lines except IOError as detail: