本文整理汇总了Python中_curses.error方法的典型用法代码示例。如果您正苦于以下问题:Python _curses.error方法的具体用法?Python _curses.error怎么用?Python _curses.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_curses
的用法示例。
在下文中一共展示了_curses.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def search(self):
"""Open search window, get input and set the search string."""
if self.init_search is not None:
return
scr2 = curses.newwin(3, self.max_x, self.max_y - 3, 0)
scr3 = scr2.derwin(1, self.max_x - 12, 1, 9)
scr2.box()
scr2.move(1, 1)
addstr(scr2, "Search: ")
scr2.refresh()
curses.curs_set(1)
self._search_win_open = 3
self.textpad = Textbox(scr3, insert_mode=True)
self.search_str = self.textpad.edit(self._search_validator)
self.search_str = self.search_str.lower().strip()
try:
curses.curs_set(0)
except _curses.error:
pass
if self.search_str:
self.init_search = None
self._search_win_open = 0
示例2: handle_keys
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def handle_keys(self):
"""Determine what method to call for each keypress.
"""
c = self.scr.getch() # Get a keystroke
if c == curses.KEY_RESIZE:
self.resize()
return
if 0 < c < 256:
c = chr(c)
# Digits are commands without a modifier
try:
found_digit = c.isdigit()
except AttributeError:
# Since .isdigit() doesn't exist if c > 256, we need to catch the
# error for those keys.
found_digit = False
if found_digit and (len(self.modifier) > 0 or c not in self.keys):
self.handle_modifier(c)
elif c in self.keys:
self.keys[c]()
else:
self.modifier = str()
示例3: _calculate_layout
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def _calculate_layout(self):
"""Setup popup window and format data. """
self.scr.touchwin()
self.term_rows, self.term_cols = self.scr.getmaxyx()
self.box_height = self.term_rows - int(self.term_rows / 2)
self.win = curses.newwin(int(self.term_rows / 2),
self.term_cols, self.box_height, 0)
try:
curses.curs_set(False)
except _curses.error:
pass
# transform raw data into list of lines ready to be printed
s = self.data.splitlines()
s = [wrap(i, self.term_cols - 3, subsequent_indent=" ")
or [""] for i in s]
self.tdata = [i for j in s for i in j]
# -3 -- 2 for the box lines and 1 for the title row
self.nlines = min(len(self.tdata), self.box_height - 3)
self.scr.refresh()
示例4: event_listener
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def event_listener(scr, timeout):
'''
Wait for curses events on screen ``scr`` at mot ``timeout`` ms
return
- 1 OK
- 2 redraw
- 0 error
'''
try:
scr.timeout(timeout)
c = scr.getch()
if c == -1:
return 1
elif c == curses.KEY_MOUSE:
return on_mouse()
elif c == curses.KEY_RESIZE:
return on_resize()
else:
return on_keyboard(c)
except _curses.error:
return 0
示例5: get_dhcp_servers
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def get_dhcp_servers(interface):
""" get dhcp servers by running nmap
Args:
interface (str): interface to query for dhcp servers
Returns:
output (str): string output of command
"""
cmd = DHCP_SERVER_CMD.format(interface)
output = ""
data = None
try:
output = bash_cmd(cmd)
except Exception as e:
LOG.error("{0}".format(e))
raise e
else:
data = parse_dhcp_servers(output)
return data
示例6: scan_subnet
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def scan_subnet(cidr):
"""Scans a subnet for responding devices.
Args:
cidr (str): subnet in cidr format or can be list of ips separated by
spaces
Returns:
list of tuples of (ip_addr, mac_addr)
"""
cmd = f'sudo nmap -sn {cidr}'
res, err, rc = sub_proc_exec(cmd)
items = []
if rc != 0:
LOG.error(f'Error while scanning subnet {cidr}, rc: {rc}')
for line in res.split('Nmap scan report'):
match = re.search(PATTERN_EMBEDDED_IP, line)
if match:
ip = match.group(0)
match2 = re.search(PATTERN_MAC, line)
if match2:
mac = match2.group(0)
else:
mac = ''
items += [(ip, mac)]
return items
示例7: stop
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def stop(self):
"""
Restore the screen.
"""
if self._started == False:
return
curses.echo()
self._curs_set(1)
try:
curses.endwin()
except _curses.error:
pass # don't block original error with curses error
if self._old_signal_keys:
self.tty_signal_keys(*self._old_signal_keys)
super(Screen, self).stop()
示例8: event_listener
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def event_listener(scr, timeout):
'''
Wait for curses events on screen ``scr`` at mot ``timeout`` ms
return
- 1 OK
- 2 redraw
- 0 error
'''
try:
scr.timeout(timeout)
c = scr.getch()
if c == -1:
return 1
elif c == curses.KEY_MOUSE:
return on_mouse()
elif c == curses.KEY_RESIZE:
return on_resize()
else:
return on_keyboard(c)
except _curses.error:
return 0
示例9: event_listener
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def event_listener(scr, timeout):
'''
Wait for curses events on screen ``scr`` at mot ``timeout`` ms
return
- 1 OK
- 2 redraw
- 0 error
'''
try:
scr.timeout(timeout)
c = scr.getch()
if c == -1:
return 1
elif c == curses.KEY_MOUSE:
return on_mouse()
elif c == curses.KEY_RESIZE:
return on_resize()
else:
return on_keyboard(scr, c)
except _curses.error:
return 0
示例10: main
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def main(stdscr, *args, **kwargs):
try:
curses.use_default_colors()
except (AttributeError, _curses.error):
pass
try:
curses.curs_set(False)
except (AttributeError, _curses.error):
pass
Viewer(stdscr, *args, **kwargs).run()
示例11: safe_get_mouse_event
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def safe_get_mouse_event(self):
try:
mouse_event = curses.getmouse()
return mouse_event
except _curses.error:
return None
示例12: find_previous_editable
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def find_previous_editable(self, *args):
if not self.editw == 0:
# remember that xrange does not return the 'last' value,
# so go to -1, not 0! (fence post error in reverse)
for n in range(self.editw-1, -1, -1 ):
if self._widgets__[n].editable and not self._widgets__[n].hidden:
self.editw = n
break
#def widget_useable_space(self, rely=0, relx=0):
# #Slightly misreports space available.
# mxy, mxx = self.lines-1, self.columns-1
# return (mxy-1-rely, mxx-1-relx)
示例13: scan_subnet_for_port_open
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def scan_subnet_for_port_open(cidr, port):
"""Scans a subnet for responding devices.
Args:
cidr (str or list): subnet in cidr format or can be list of ips
separated by spaces.
port (str or int) : tcp port to check
returns: (list): list of tuples with ip and mac address
"""
if isinstance(cidr, list):
cidr = ' '.join(cidr)
cmd = f'sudo nmap -p {port} {cidr}'
res, err, rc = sub_proc_exec(cmd)
items = []
if rc != 0:
LOG.error(f'Error while scanning subnet {cidr}, rc: {rc}')
for line in res.split('Nmap scan report'):
match = re.search(PATTERN_EMBEDDED_IP, line)
if match:
ip = match.group(0)
match2 = re.search(r'\d+/tcp\s+open.+' + rf'({PATTERN_MAC})', line,
re.DOTALL)
if match2:
mac = match2.group(1)
if match2:
items += [(ip, mac)]
return items
示例14: dnsmasq_add_dhcp_range
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def dnsmasq_add_dhcp_range(dhcp_range,
lease_time='1h',
conf_path='/etc/dnsmasq.conf',
reload=True):
"""Add DHCP range to existing dnsmasq configuration
Args:
dhcp_range (str, optional): Range of IP addresses to lease to clients
formatted as "<start_ip>,<end_ip>"
lease_time (str, optional): Time duration of IP leases
conf_path (str, optional): Path to dnsmasq configuration file
reload (bool, optional): Reload dnsmasq after writing config
Returns:
int: Return code from nginx syntax check ('dnsmasq --test')
If syntax check rc=0 and reload=True the return code
from 'systemctl restart dnsmasq.service'
"""
append_line(conf_path, f'dhcp-range={dhcp_range},{lease_time}',
check_exists=True)
cmd = (f'dnsmasq --test')
stdout, stderr, rc = sub_proc_exec(cmd)
LOG.debug(f"Command: \'{cmd}\'\nstdout: \'{stdout}\'\n"
f"stderr: \'{stderr}\'\nrc: {rc}")
if rc != 0:
LOG.warning('dnsmasq configuration check failed')
elif reload:
cmd = ('systemctl restart dnsmasq.service')
stdout, stderr, rc = sub_proc_exec(cmd)
LOG.debug(f"Command: \'{cmd}\'\nstdout: \'{stdout}\'\n"
f"stderr: \'{stderr}\'\nrc: {rc}")
if rc != 0:
LOG.error('dnsmasq service restart failed')
return rc
示例15: breakpoint
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import error [as 别名]
def breakpoint():
""" Wrapper for pdb.set_trace() with curses cleanup
Note: python>=3.7 includes a built-in 'breakpoint()'
"""
from pdb import set_trace
from _curses import error
try:
clear_curses()
except error:
pass
set_trace()