summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2014-05-11 19:54:35 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2014-05-11 21:30:23 -0700
commitbe714a183206490aafec0e244b166ba3de803142 (patch)
tree1986bc42504e299e1cb472ffe608a7e34c83de99
parentef05b48a1cd4d0071873022d1a31d2a076911eb0 (diff)
downloadurwid-be714a183206490aafec0e244b166ba3de803142.tar.gz
Fix some Python 3 things that work fine in 2.6 anyway.
-rwxr-xr-xexamples/calc.py2
-rwxr-xr-xexamples/dialog.py2
-rwxr-xr-xurwid/container.py20
-rwxr-xr-xurwid/display_common.py2
-rw-r--r--urwid/escape.py8
-rwxr-xr-xurwid/font.py2
-rwxr-xr-xurwid/monitored_list.py4
-rwxr-xr-xurwid/old_str_util.py7
-rw-r--r--urwid/signals.py4
-rw-r--r--urwid/util.py12
-rwxr-xr-xurwid/web_display.py6
11 files changed, 36 insertions, 33 deletions
diff --git a/examples/calc.py b/examples/calc.py
index ec1f039..2ac324a 100755
--- a/examples/calc.py
+++ b/examples/calc.py
@@ -311,7 +311,7 @@ class CellColumn( urwid.WidgetWrap ):
if sub != 0:
# f is not an edit widget
return key
- if OPERATORS.has_key(key):
+ if key in OPERATORS:
# move trailing text to new cell below
edit = self.walker.get_cell(i).edit
cursor_pos = edit.edit_pos
diff --git a/examples/dialog.py b/examples/dialog.py
index dbdeb28..7f3a4d5 100755
--- a/examples/dialog.py
+++ b/examples/dialog.py
@@ -321,7 +321,7 @@ status may be either on or off.
def main():
- if len(sys.argv) < 2 or not MODES.has_key(sys.argv[1]):
+ if len(sys.argv) < 2 or sys.argv[1] not in MODES:
show_usage()
return
diff --git a/urwid/container.py b/urwid/container.py
index 24dddf9..8b61383 100755
--- a/urwid/container.py
+++ b/urwid/container.py
@@ -284,7 +284,7 @@ class GridFlow(WidgetWrap, WidgetContainerMixin, WidgetContainerListContentsMixi
empty.
"""
if not self.contents:
- raise IndexError, "No focus_position, GridFlow is empty"
+ raise IndexError("No focus_position, GridFlow is empty")
return self.contents.focus
def _set_focus_position(self, position):
"""
@@ -296,7 +296,7 @@ class GridFlow(WidgetWrap, WidgetContainerMixin, WidgetContainerListContentsMixi
if position < 0 or position >= len(self.contents):
raise IndexError
except (TypeError, IndexError):
- raise IndexError, "No GridFlow child widget at position %s" % (position,)
+ raise IndexError("No GridFlow child widget at position %s" % (position,))
self.contents.focus = position
focus_position = property(_get_focus_position, _set_focus_position, doc="""
index of child widget in focus. Raises :exc:`IndexError` if read when
@@ -607,7 +607,7 @@ class Overlay(Widget, WidgetContainerMixin, WidgetContainerListContentsMixin):
position -- index of child widget to be made focus
"""
if position != 1:
- raise IndexError, ("Overlay widget focus_position currently "
+ raise IndexError("Overlay widget focus_position currently "
"must always be set to 1, not %s" % (position,))
focus_position = property(_get_focus_position, _set_focus_position,
doc="index of child widget in focus, currently always 1")
@@ -871,10 +871,10 @@ class Frame(Widget, WidgetContainerMixin):
:type part: str
"""
if part not in ('header', 'footer', 'body'):
- raise IndexError, 'Invalid position for Frame: %s' % (part,)
+ raise IndexError('Invalid position for Frame: %s' % (part,))
if (part == 'header' and self._header is None) or (
part == 'footer' and self._footer is None):
- raise IndexError, 'This Frame has no %s' % (part,)
+ raise IndexError('This Frame has no %s' % (part,))
self.focus_part = part
self._invalidate()
@@ -1407,7 +1407,7 @@ class Pile(Widget, WidgetContainerMixin, WidgetContainerListContentsMixin):
empty.
"""
if not self.contents:
- raise IndexError, "No focus_position, Pile is empty"
+ raise IndexError("No focus_position, Pile is empty")
return self.contents.focus
def _set_focus_position(self, position):
"""
@@ -1419,7 +1419,7 @@ class Pile(Widget, WidgetContainerMixin, WidgetContainerListContentsMixin):
if position < 0 or position >= len(self.contents):
raise IndexError
except (TypeError, IndexError):
- raise IndexError, "No Pile child widget at position %s" % (position,)
+ raise IndexError("No Pile child widget at position %s" % (position,))
self.contents.focus = position
focus_position = property(_get_focus_position, _set_focus_position, doc="""
index of child widget in focus. Raises :exc:`IndexError` if read when
@@ -1488,7 +1488,7 @@ class Pile(Widget, WidgetContainerMixin, WidgetContainerListContentsMixin):
l.append(0) # zero-weighted items treated as ('given', 0)
if wtotal == 0:
- raise PileError, "No weighted widgets found for Pile treated as a box widget"
+ raise PileError("No weighted widgets found for Pile treated as a box widget")
if remaining < 0:
remaining = 0
@@ -1957,7 +1957,7 @@ class Columns(Widget, WidgetContainerMixin, WidgetContainerListContentsMixin):
empty.
"""
if not self.widget_list:
- raise IndexError, "No focus_position, Columns is empty"
+ raise IndexError("No focus_position, Columns is empty")
return self.contents.focus
def _set_focus_position(self, position):
"""
@@ -1969,7 +1969,7 @@ class Columns(Widget, WidgetContainerMixin, WidgetContainerListContentsMixin):
if position < 0 or position >= len(self.contents):
raise IndexError
except (TypeError, IndexError):
- raise IndexError, "No Columns child widget at position %s" % (position,)
+ raise IndexError("No Columns child widget at position %s" % (position,))
self.contents.focus = position
focus_position = property(_get_focus_position, _set_focus_position, doc="""
index of child widget in focus. Raises :exc:`IndexError` if read when
diff --git a/urwid/display_common.py b/urwid/display_common.py
index 789442f..b539f53 100755
--- a/urwid/display_common.py
+++ b/urwid/display_common.py
@@ -750,7 +750,7 @@ class BaseScreen(object):
raise ScreenError("Invalid register_palette entry: %s" %
repr(item))
name, like_name = item
- if not self._palette.has_key(like_name):
+ if like_name not in self._palette:
raise ScreenError("palette entry '%s' doesn't exist"%like_name)
self._palette[name] = self._palette[like_name]
diff --git a/urwid/escape.py b/urwid/escape.py
index 077e38e..12501b8 100644
--- a/urwid/escape.py
+++ b/urwid/escape.py
@@ -102,7 +102,7 @@ input_sequences = [
] + [
# modified cursor keys + home, end, 5 -- [#X and [1;#X forms
(prefix+digit+letter, escape_modifier(digit) + key)
- for prefix in "[","[1;"
+ for prefix in ("[", "[1;")
for digit in "12345678"
for letter,key in zip("ABCDEFGH",
('up','down','right','left','5','end','5','home'))
@@ -138,7 +138,7 @@ class KeyqueueTrie(object):
assert type(root) == dict, "trie conflict detected"
assert len(s) > 0, "trie conflict detected"
- if root.has_key(ord(s[0])):
+ if ord(s[0]) in root:
return self.add(root[ord(s[0])], s[1:], result)
if len(s)>1:
d = {}
@@ -163,7 +163,7 @@ class KeyqueueTrie(object):
if more_available:
raise MoreInputRequired()
return None
- if not root.has_key(keys[0]):
+ if keys[0] not in root:
return None
return self.get_recurse(root[keys[0]], keys[1:], more_available)
@@ -318,7 +318,7 @@ def process_keyqueue(codes, more_available):
if code >= 32 and code <= 126:
key = chr(code)
return [key], codes[1:]
- if _keyconv.has_key(code):
+ if code in _keyconv:
return [_keyconv[code]], codes[1:]
if code >0 and code <27:
return ["ctrl %s" % chr(ord('a')+code-1)], codes[1:]
diff --git a/urwid/font.py b/urwid/font.py
index 0a3261b..bf0c2b1 100755
--- a/urwid/font.py
+++ b/urwid/font.py
@@ -111,7 +111,7 @@ class Font(object):
return "".join(l)
def char_width(self, c):
- if self.char.has_key(c):
+ if c in self.char:
return self.char[c][0]
return 0
diff --git a/urwid/monitored_list.py b/urwid/monitored_list.py
index 86d749e..2e8bd00 100755
--- a/urwid/monitored_list.py
+++ b/urwid/monitored_list.py
@@ -158,9 +158,9 @@ class MonitoredFocusList(MonitoredList):
self._focus = 0
return
if index < 0 or index >= len(self):
- raise IndexError, 'focus index is out of range: %s' % (index,)
+ raise IndexError('focus index is out of range: %s' % (index,))
if index != int(index):
- raise IndexError, 'invalid focus index: %s' % (index,)
+ raise IndexError('invalid focus index: %s' % (index,))
index = int(index)
if index != self._focus:
self._focus_changed(index)
diff --git a/urwid/old_str_util.py b/urwid/old_str_util.py
index 04594ec..83190f5 100755
--- a/urwid/old_str_util.py
+++ b/urwid/old_str_util.py
@@ -19,6 +19,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Urwid web site: http://excess.org/urwid/
+from __future__ import print_function
import re
@@ -357,10 +358,10 @@ def process_east_asian_width():
out.append( (num, l) )
last = l
- print "widths = ["
+ print("widths = [")
for o in out[1:]: # treat control characters same as ascii
- print "\t%r," % (o,)
- print "]"
+ print("\t%r," % (o,))
+ print("]")
if __name__ == "__main__":
process_east_asian_width()
diff --git a/urwid/signals.py b/urwid/signals.py
index 80b6646..b716939 100644
--- a/urwid/signals.py
+++ b/urwid/signals.py
@@ -150,8 +150,8 @@ class Signals(object):
sig_cls = obj.__class__
if not name in self._supported.get(sig_cls, []):
- raise NameError, "No such signal %r for object %r" % \
- (name, obj)
+ raise NameError("No such signal %r for object %r" %
+ (name, obj))
# Just generate an arbitrary (but unique) key
key = Key()
diff --git a/urwid/util.py b/urwid/util.py
index 4e71f97..f04e152 100644
--- a/urwid/util.py
+++ b/urwid/util.py
@@ -281,13 +281,14 @@ def rle_len( rle ):
run += r
return run
-def rle_append_beginning_modify( rle, (a, r) ):
+def rle_append_beginning_modify(rle, a_r):
"""
Append (a, r) to BEGINNING of rle.
Merge with first run when possible
MODIFIES rle parameter contents. Returns None.
"""
+ a, r = a_r
if not rle:
rle[:] = [(a, r)]
else:
@@ -298,13 +299,14 @@ def rle_append_beginning_modify( rle, (a, r) ):
rle[0:0] = [(al, r)]
-def rle_append_modify( rle, (a, r) ):
+def rle_append_modify(rle, a_r):
"""
Append (a,r) to the rle list rle.
Merge with last run when possible.
MODIFIES rle parameter contents. Returns None.
"""
+ a, r = a_r
if not rle or rle[-1][0] != a:
rle.append( (a,r) )
return
@@ -405,13 +407,13 @@ def _tagmarkup_recurse( tm, attr ):
if type(tm) == tuple:
# tuples mark a new attribute boundary
if len(tm) != 2:
- raise TagMarkupException, "Tuples must be in the form (attribute, tagmarkup): %r" % (tm,)
+ raise TagMarkupException("Tuples must be in the form (attribute, tagmarkup): %r" % (tm,))
attr, element = tm
return _tagmarkup_recurse( element, attr )
if not isinstance(tm,(basestring, bytes)):
- raise TagMarkupException, "Invalid markup element: %r" % tm
+ raise TagMarkupException("Invalid markup element: %r" % tm)
# text
return [tm], [(attr, len(tm))]
@@ -431,7 +433,7 @@ class MetaSuper(type):
def __init__(cls, name, bases, d):
super(MetaSuper, cls).__init__(name, bases, d)
if hasattr(cls, "_%s__super" % name):
- raise AttributeError, "Class has same name as one of its super classes"
+ raise AttributeError("Class has same name as one of its super classes")
setattr(cls, "_%s__super" % name, super(cls))
diff --git a/urwid/web_display.py b/urwid/web_display.py
index e088476..eccbad8 100755
--- a/urwid/web_display.py
+++ b/urwid/web_display.py
@@ -593,7 +593,7 @@ class Screen:
continue
assert len(item) == 2, "Invalid register_palette usage"
name, like_name = item
- if not self.palette.has_key(like_name):
+ if like_name not in self.palette:
raise Exception("palette entry '%s' doesn't exist"%like_name)
self.palette[name] = self.palette[like_name]
@@ -946,7 +946,7 @@ def is_web_request():
"""
Return True if this is a CGI web request.
"""
- return os.environ.has_key('REQUEST_METHOD')
+ return 'REQUEST_METHOD' in os.environ
def handle_short_request():
"""
@@ -973,7 +973,7 @@ def handle_short_request():
# Don't know what to do with head requests etc.
return False
- if not os.environ.has_key('HTTP_X_URWID_ID'):
+ if 'HTTP_X_URWID_ID' not in os.environ:
# If no urwid id, then the application should be started.
return False