Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Virtualization:Tests
aexpect
0008-aexpect.client-Add-support-to-sendcontrol-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0008-aexpect.client-Add-support-to-sendcontrol-characters.patch of Package aexpect
From 2a29cada8b9f223edca7e6497998bee9eb30cce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= <ldoktor@redhat.com> Date: Tue, 11 Oct 2016 09:06:04 +0200 Subject: [PATCH 10/10] aexpect.client: Add support to sendcontrol characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From time to time one needs to send ctrl+... characters to the underlying process. One can either find and use the actual value, or they can use this function, which does the mapping itself. To use it simply specify the key to be pressed together with ctrl and you're set. Note: Don't mistake this method with send_ctrl, which is used to send control messages to the aexpect process and not to your underlying process. Signed-off-by: Lukáš Doktor <ldoktor@redhat.com> --- aexpect/client.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/aexpect/client.py b/aexpect/client.py index b8b38b5..493b6b7 100644 --- a/aexpect/client.py +++ b/aexpect/client.py @@ -374,6 +374,28 @@ class Spawn(object): """ self.send(cont + self.linesep) + def sendcontrol(self, char): + """ + This sends a control character to the child such as Ctrl-C or + Ctrl-D. For example, to send a Ctrl-G (ASCII 7):: + session.sendcontrol('g') + :param char: single character you want to send (ctrl+$char) + :raise KeyError: When unable to map char to ctrl+comand + """ + char = char.lower() + val = ord(char) + if val >= 97 and val <= 122: + val = val - 97 + 1 # ctrl+a = '\0x01' + return self.send(chr(val)) + mapping = {'@': 0, '`': 0, + '[': 27, '{': 27, + '\\': 28, '|': 28, + ']': 29, '}': 29, + '^': 30, '~': 30, + '_': 31, + '?': 127} + return self.send(chr(mapping[char])) + def send_ctrl(self, control_str=""): """ Send a control string to the aexpect process. -- 2.10.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor