本文整理汇总了Python中curses.error方法的典型用法代码示例。如果您正苦于以下问题:Python curses.error方法的具体用法?Python curses.error怎么用?Python curses.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curses
的用法示例。
在下文中一共展示了curses.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: supported
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
raise
# guess false in case of error
return False
示例2: supported
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例3: addstr
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def addstr(self, y, x, msg, color = None, attr = curses.A_NORMAL):
# Curses throws an error if we try to draw a message that spans out of the
# window's bounds (... seriously?), so doing our best to avoid that.
if color is not None:
if color not in self._colors:
recognized_colors = ", ".join(self._colors.keys())
raise ValueError("The '%s' color isn't recognized: %s" % (color, recognized_colors))
attr |= self._colors[color]
max_y, max_x = self._stdscr.getmaxyx()
if max_x > x and max_y > y:
try:
self._stdscr.addstr(y, x, msg[:max_x - x], attr)
except:
pass # maybe an edge case while resizing the window
示例4: _insert_printable_char
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def _insert_printable_char(self, ch):
self._update_max_yx()
(y, x) = self.win.getyx()
backyx = None
while y < self.maxy or x < self.maxx:
if self.insert_mode:
oldch = self.win.inch()
# The try-catch ignores the error we trigger from some curses
# versions by trying to write into the lowest-rightmost spot
# in the window.
try:
self.win.addch(ch)
except curses.error:
pass
if not self.insert_mode or not curses.ascii.isprint(oldch):
break
ch = oldch
(y, x) = self.win.getyx()
# Remember where to put the cursor back since we are in insert_mode
if backyx is None:
backyx = y, x
if backyx is not None:
self.win.move(*backyx)
示例5: supported
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def supported(cls, stream=sys.stdout):
"""Check the current platform supports coloring terminal output
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例6: refresh_window
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def refresh_window(procs, disks_read, disks_write):
"""Print results on screen by using curses."""
curses.endwin()
templ = "%-5s %-7s %11s %11s %s"
win.erase()
disks_tot = "Total DISK READ: %s | Total DISK WRITE: %s" \
% (bytes2human(disks_read), bytes2human(disks_write))
print_line(disks_tot)
header = templ % ("PID", "USER", "DISK READ", "DISK WRITE", "COMMAND")
print_line(header, highlight=True)
for p in procs:
line = templ % (
p.pid,
p._username[:7],
bytes2human(p._read_per_sec),
bytes2human(p._write_per_sec),
p._cmdline)
try:
print_line(line)
except curses.error:
break
win.refresh()
示例7: print_line
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def print_line(line, highlight=False):
"""A thin wrapper around curses's addstr()."""
global lineno
try:
if highlight:
line += " " * (win.getmaxyx()[1] - len(line))
win.addstr(lineno, 0, line, curses.A_REVERSE)
else:
win.addstr(lineno, 0, line, 0)
except curses.error:
lineno = 0
win.refresh()
raise
else:
lineno += 1
# --- /curses stuff
示例8: _insert_printable_char
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def _insert_printable_char(self, ch):
(y, x) = self.win.getyx()
if y < self.maxy or x < self.maxx:
if self.insert_mode:
oldch = self.win.inch()
# The try-catch ignores the error we trigger from some curses
# versions by trying to write into the lowest-rightmost spot
# in the window.
try:
self.win.addch(ch)
except curses.error:
pass
if self.insert_mode:
(backy, backx) = self.win.getyx()
if curses.ascii.isprint(oldch):
self._insert_printable_char(oldch)
self.win.move(backy, backx)
示例9: _printResults
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def _printResults(self, flavor, errors, formatter):
"""
Print a group of errors to the stream.
@param flavor: A string indicating the kind of error (e.g. 'TODO').
@param errors: A list of errors, often L{failure.Failure}s, but
sometimes 'todo' errors.
@param formatter: A callable that knows how to format the errors.
"""
for reason, cases in self._groupResults(errors, formatter):
self._writeln(self._doubleSeparator)
self._writeln(flavor)
self._write(reason)
self._writeln('')
for case in cases:
self._writeln(case.id())
示例10: supported
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
# guess false in case of error
return False
示例11: test_tparm_returns_null
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def test_tparm_returns_null(monkeypatch):
""" Test 'tparm() returned NULL' is caught (win32 PDCurses systems). """
# on win32, any calls to tparm raises curses.error with message,
# "tparm() returned NULL", function PyCurses_tparm of _cursesmodule.c
from blessed.formatters import ParameterizingString, NullCallableString
def tparm(*args):
raise curses.error("tparm() returned NULL")
monkeypatch.setattr(curses, 'tparm', tparm)
term = mock.Mock()
term.normal = 'seq-normal'
pstr = ParameterizingString(u'cap', u'norm', u'seq-name')
value = pstr(u'x')
assert type(value) is NullCallableString
示例12: test_tparm_other_exception
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def test_tparm_other_exception(monkeypatch):
""" Test 'tparm() returned NULL' is caught (win32 PDCurses systems). """
# on win32, any calls to tparm raises curses.error with message,
# "tparm() returned NULL", function PyCurses_tparm of _cursesmodule.c
from blessed.formatters import ParameterizingString, NullCallableString
def tparm(*args):
raise curses.error("unexpected error in tparm()")
monkeypatch.setattr(curses, 'tparm', tparm)
term = mock.Mock()
term.normal = 'seq-normal'
pstr = ParameterizingString(u'cap', u'norm', u'seq-name')
try:
pstr(u'x')
assert False, "previous call should have raised curses.error"
except curses.error:
pass
示例13: _get_key_py33
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def _get_key_py33(self):
"""Python 3.3+ implementation of get_key."""
# pylint: disable=too-many-return-statements
try:
# Curses in Python 3.3 handles unicode via get_wch
key = self.window.get_wch()
if isinstance(key, int):
if key == curses.KEY_BACKSPACE:
return "KEY_BACKSPACE"
if key == curses.KEY_LEFT:
return "KEY_LEFT"
if key == curses.KEY_RIGHT:
return "KEY_RIGHT"
if key == curses.KEY_RESIZE:
return "KEY_RESIZE"
return None
return key
except curses.error:
return None
except KeyboardInterrupt:
raise
示例14: refresh
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def refresh(self):
pmfuncs.hide_cursor()
_my, _mx = self._max_physical()
self.curses_pad.move(0,0)
# Since we can have pannels larger than the screen
# let's allow for scrolling them
# Getting strange errors on OS X, with curses sometimes crashing at this point.
# Suspect screen size not updated in time. This try: seems to solve it with no ill effects.
try:
self.curses_pad.refresh(self.show_from_y,self.show_from_x,self.show_aty,self.show_atx,_my,_mx)
except curses.error:
pass
if self.show_from_y is 0 and \
self.show_from_x is 0 and \
(_my >= self.lines) and \
(_mx >= self.columns):
self.ALL_SHOWN = True
else:
self.ALL_SHOWN = False
示例15: IO_safe
# 需要导入模块: import curses [as 别名]
# 或者: from curses import error [as 别名]
def IO_safe(func, *args, _tries=5, _raise=True, **kwargs):
""" Wrapper calling function func with arguments args and keyword arguments kwargs to catch input/output errors
on cluster.
:param func: function to execute (intended to be read/write operation to a problematic cluster drive, but can be
any function).
:param args: positional args of func.
:param kwargs: kw args of func.
:param _tries: how many attempts to make executing func.
"""
for _try in range(_tries):
try:
return func(*args, **kwargs)
except OSError as e: # to catch cluster issues with network drives
if _raise:
raise e
else:
print("After attempting execution {} time{}, following error occurred:\n{}".format(_try + 1,
"" if _try == 0 else "s",
e))
continue