##// END OF EJS Templates
Rename ipipe._default to ipipe.noitem (which makes...
walter.doerwald -
Show More
@@ -232,7 +232,7 b' class _BrowserLevel(object):'
232 self.displayattrs = []
232 self.displayattrs = []
233
233
234 # index and name of attribute under the cursor
234 # index and name of attribute under the cursor
235 self.displayattr = (None, ipipe._default)
235 self.displayattr = (None, ipipe.noitem)
236
236
237 # Maps attribute names to column widths
237 # Maps attribute names to column widths
238 self.colwidths = {}
238 self.colwidths = {}
@@ -284,13 +284,13 b' class _BrowserLevel(object):'
284 item = self.items[i].item
284 item = self.items[i].item
285 for attrname in self.displayattrs:
285 for attrname in self.displayattrs:
286 try:
286 try:
287 value = ipipe._getattr(item, attrname, ipipe._default)
287 value = ipipe._getattr(item, attrname, ipipe.noitem)
288 except (KeyboardInterrupt, SystemExit):
288 except (KeyboardInterrupt, SystemExit):
289 raise
289 raise
290 except Exception, exc:
290 except Exception, exc:
291 value = exc
291 value = exc
292 # only store attribute if it exists (or we got an exception)
292 # only store attribute if it exists (or we got an exception)
293 if value is not ipipe._default:
293 if value is not ipipe.noitem:
294 parts = []
294 parts = []
295 totallength = 0
295 totallength = 0
296 align = None
296 align = None
@@ -351,7 +351,7 b' class _BrowserLevel(object):'
351 break
351 break
352 pos += self.colwidths[attrname]+1
352 pos += self.colwidths[attrname]+1
353 else:
353 else:
354 self.displayattr = (None, ipipe._default)
354 self.displayattr = (None, ipipe.noitem)
355
355
356 def moveto(self, x, y, refresh=False):
356 def moveto(self, x, y, refresh=False):
357 # Move the cursor to the position ``(x,y)`` (in data coordinates,
357 # Move the cursor to the position ``(x,y)`` (in data coordinates,
@@ -846,12 +846,12 b' class ibrowse(ipipe.Display):'
846 def cmd_pickattr(self):
846 def cmd_pickattr(self):
847 level = self.levels[-1]
847 level = self.levels[-1]
848 attrname = level.displayattr[1]
848 attrname = level.displayattr[1]
849 if attrname is ipipe._default:
849 if attrname is ipipe.noitem:
850 curses.beep()
850 curses.beep()
851 self.report(AttributeError(ipipe._attrname(attrname)))
851 self.report(AttributeError(ipipe._attrname(attrname)))
852 return
852 return
853 attr = ipipe._getattr(level.items[level.cury].item, attrname)
853 attr = ipipe._getattr(level.items[level.cury].item, attrname)
854 if attr is ipipe._default:
854 if attr is ipipe.noitem:
855 curses.beep()
855 curses.beep()
856 self.report(AttributeError(ipipe._attrname(attrname)))
856 self.report(AttributeError(ipipe._attrname(attrname)))
857 else:
857 else:
@@ -861,14 +861,14 b' class ibrowse(ipipe.Display):'
861 def cmd_pickallattrs(self):
861 def cmd_pickallattrs(self):
862 level = self.levels[-1]
862 level = self.levels[-1]
863 attrname = level.displayattr[1]
863 attrname = level.displayattr[1]
864 if attrname is ipipe._default:
864 if attrname is ipipe.noitem:
865 curses.beep()
865 curses.beep()
866 self.report(AttributeError(ipipe._attrname(attrname)))
866 self.report(AttributeError(ipipe._attrname(attrname)))
867 return
867 return
868 result = []
868 result = []
869 for cache in level.items:
869 for cache in level.items:
870 attr = ipipe._getattr(cache.item, attrname)
870 attr = ipipe._getattr(cache.item, attrname)
871 if attr is not ipipe._default:
871 if attr is not ipipe.noitem:
872 result.append(attr)
872 result.append(attr)
873 self.returnvalue = result
873 self.returnvalue = result
874 return True
874 return True
@@ -881,7 +881,7 b' class ibrowse(ipipe.Display):'
881 def cmd_pickmarkedattr(self):
881 def cmd_pickmarkedattr(self):
882 level = self.levels[-1]
882 level = self.levels[-1]
883 attrname = level.displayattr[1]
883 attrname = level.displayattr[1]
884 if attrname is ipipe._default:
884 if attrname is ipipe.noitem:
885 curses.beep()
885 curses.beep()
886 self.report(AttributeError(ipipe._attrname(attrname)))
886 self.report(AttributeError(ipipe._attrname(attrname)))
887 return
887 return
@@ -889,7 +889,7 b' class ibrowse(ipipe.Display):'
889 for cache in level.items:
889 for cache in level.items:
890 if cache.marked:
890 if cache.marked:
891 attr = ipipe._getattr(cache.item, attrname)
891 attr = ipipe._getattr(cache.item, attrname)
892 if attr is not ipipe._default:
892 if attr is not ipipe.noitem:
893 result.append(attr)
893 result.append(attr)
894 self.returnvalue = result
894 self.returnvalue = result
895 return True
895 return True
@@ -947,7 +947,7 b' class ibrowse(ipipe.Display):'
947 def cmd_enterattr(self):
947 def cmd_enterattr(self):
948 level = self.levels[-1]
948 level = self.levels[-1]
949 attrname = level.displayattr[1]
949 attrname = level.displayattr[1]
950 if attrname is ipipe._default:
950 if attrname is ipipe.noitem:
951 curses.beep()
951 curses.beep()
952 self.report(AttributeError(ipipe._attrname(attrname)))
952 self.report(AttributeError(ipipe._attrname(attrname)))
953 return
953 return
@@ -958,7 +958,7 b' class ibrowse(ipipe.Display):'
958 curses.beep()
958 curses.beep()
959 else:
959 else:
960 attr = ipipe._getattr(item, attrname)
960 attr = ipipe._getattr(item, attrname)
961 if attr is ipipe._default:
961 if attr is ipipe.noitem:
962 self.report(AttributeError(ipipe._attrname(attrname)))
962 self.report(AttributeError(ipipe._attrname(attrname)))
963 else:
963 else:
964 self.report("entering object attribute %s..." % ipipe._attrname(attrname))
964 self.report("entering object attribute %s..." % ipipe._attrname(attrname))
@@ -978,7 +978,7 b' class ibrowse(ipipe.Display):'
978 def cmd_detailattr(self):
978 def cmd_detailattr(self):
979 level = self.levels[-1]
979 level = self.levels[-1]
980 attrname = level.displayattr[1]
980 attrname = level.displayattr[1]
981 if attrname is ipipe._default:
981 if attrname is ipipe.noitem:
982 curses.beep()
982 curses.beep()
983 self.report(AttributeError(ipipe._attrname(attrname)))
983 self.report(AttributeError(ipipe._attrname(attrname)))
984 return
984 return
@@ -989,7 +989,7 b' class ibrowse(ipipe.Display):'
989 curses.beep()
989 curses.beep()
990 else:
990 else:
991 attr = ipipe._getattr(item, attrname)
991 attr = ipipe._getattr(item, attrname)
992 if attr is ipipe._default:
992 if attr is ipipe.noitem:
993 self.report(AttributeError(ipipe._attrname(attrname)))
993 self.report(AttributeError(ipipe._attrname(attrname)))
994 else:
994 else:
995 self.report("entering detail view for attribute...")
995 self.report("entering detail view for attribute...")
@@ -1013,7 +1013,7 b' class ibrowse(ipipe.Display):'
1013 def cmd_sortattrasc(self):
1013 def cmd_sortattrasc(self):
1014 level = self.levels[-1]
1014 level = self.levels[-1]
1015 attrname = level.displayattr[1]
1015 attrname = level.displayattr[1]
1016 if attrname is ipipe._default:
1016 if attrname is ipipe.noitem:
1017 curses.beep()
1017 curses.beep()
1018 self.report(AttributeError(ipipe._attrname(attrname)))
1018 self.report(AttributeError(ipipe._attrname(attrname)))
1019 return
1019 return
@@ -1030,7 +1030,7 b' class ibrowse(ipipe.Display):'
1030 def cmd_sortattrdesc(self):
1030 def cmd_sortattrdesc(self):
1031 level = self.levels[-1]
1031 level = self.levels[-1]
1032 attrname = level.displayattr[1]
1032 attrname = level.displayattr[1]
1033 if attrname is ipipe._default:
1033 if attrname is ipipe.noitem:
1034 curses.beep()
1034 curses.beep()
1035 self.report(AttributeError(ipipe._attrname(attrname)))
1035 self.report(AttributeError(ipipe._attrname(attrname)))
1036 return
1036 return
@@ -1276,7 +1276,7 b' class ibrowse(ipipe.Display):'
1276
1276
1277 attrstyle = [(astyle.style_default, "no attribute")]
1277 attrstyle = [(astyle.style_default, "no attribute")]
1278 attrname = level.displayattr[1]
1278 attrname = level.displayattr[1]
1279 if attrname is not ipipe._default and attrname is not None:
1279 if attrname is not ipipe.noitem and attrname is not None:
1280 posx += self.addstr(posy, posx, 0, endx, " | ", self.style_footer)
1280 posx += self.addstr(posy, posx, 0, endx, " | ", self.style_footer)
1281 posx += self.addstr(posy, posx, 0, endx, ipipe._attrname(attrname), self.style_footer)
1281 posx += self.addstr(posy, posx, 0, endx, ipipe._attrname(attrname), self.style_footer)
1282 posx += self.addstr(posy, posx, 0, endx, ": ", self.style_footer)
1282 posx += self.addstr(posy, posx, 0, endx, ": ", self.style_footer)
@@ -1286,7 +1286,7 b' class ibrowse(ipipe.Display):'
1286 raise
1286 raise
1287 except Exception, exc:
1287 except Exception, exc:
1288 attr = exc
1288 attr = exc
1289 if attr is not ipipe._default:
1289 if attr is not ipipe.noitem:
1290 attrstyle = ipipe.xrepr(attr, "footer")
1290 attrstyle = ipipe.xrepr(attr, "footer")
1291 for (nostyle, text) in attrstyle:
1291 for (nostyle, text) in attrstyle:
1292 if not isinstance(nostyle, int):
1292 if not isinstance(nostyle, int):
@@ -219,9 +219,9 b' except TypeError:'
219 return real_eval(code, _globals, newlocals)
219 return real_eval(code, _globals, newlocals)
220
220
221
221
222 _default = object()
222 noitem = object()
223
223
224 def item(iterator, index, default=_default):
224 def item(iterator, index, default=noitem):
225 """
225 """
226 Return the ``index``th item from the iterator ``iterator``.
226 Return the ``index``th item from the iterator ``iterator``.
227 ``index`` must be an integer (negative integers are relative to the
227 ``index`` must be an integer (negative integers are relative to the
@@ -249,7 +249,7 b' def item(iterator, index, default=_default):'
249 cache.popleft()
249 cache.popleft()
250 if len(cache)==i:
250 if len(cache)==i:
251 return cache.popleft()
251 return cache.popleft()
252 if default is _default:
252 if default is noitem:
253 raise IndexError(index)
253 raise IndexError(index)
254 else:
254 else:
255 return default
255 return default
@@ -336,7 +336,7 b' class Pipe(Table):'
336 return self
336 return self
337
337
338
338
339 def _getattr(obj, name, default=_default):
339 def _getattr(obj, name, default=noitem):
340 """
340 """
341 Internal helper for getting an attribute of an item. If ``name`` is ``None``
341 Internal helper for getting an attribute of an item. If ``name`` is ``None``
342 return the object itself. If ``name`` is an integer, use ``__getitem__``
342 return the object itself. If ``name`` is an integer, use ``__getitem__``
General Comments 0
You need to be logged in to leave comments. Login now