GNUnet 0.22.2
gnunet_pyexpect.pexpect Class Reference
Inheritance diagram for gnunet_pyexpect.pexpect:
[legend]
Collaboration diagram for gnunet_pyexpect.pexpect:
[legend]

Public Member Functions

def __init__ (self)
 
def spawn (self, stdin, arglist, *pargs, **kwargs)
 
def expect (self, s, r, flags=0)
 
def read (self, s, size=-1)
 

Data Fields

 proc
 
 stde
 
 stdo
 

Detailed Description

Definition at line 30 of file gnunet_pyexpect.py.

Constructor & Destructor Documentation

◆ __init__()

def gnunet_pyexpect.pexpect.__init__ (   self)

Definition at line 31 of file gnunet_pyexpect.py.

31 def __init__(self):
32 super(pexpect, self).__init__()
33

References gnunet_pyexpect.pexpect.__init__().

Referenced by gnunet_pyexpect.pexpect.__init__().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ spawn()

def gnunet_pyexpect.pexpect.spawn (   self,
  stdin,
  arglist,
pargs,
**  kwargs 
)

Definition at line 34 of file gnunet_pyexpect.py.

34 def spawn(self, stdin, arglist, *pargs, **kwargs):
35 env = kwargs.pop('env', None)
36 if env is None:
37 env = os.environ.copy()
38 # This messes up some testcases, disable log redirection
39 env.pop('GNUNET_FORCE_LOGFILE', None)
40 self.proc = subprocess.Popen(arglist, *pargs, env=env, **kwargs)
41 if self.proc is None:
42 print("Failed to spawn a process {0}".format(arglist))
43 sys.exit(1)
44 if stdin is not None:
45 self.stdo, self.stde = self.proc.communicate(stdin)
46 else:
47 self.stdo, self.stde = self.proc.communicate()
48 return self.proc
49

◆ expect()

def gnunet_pyexpect.pexpect.expect (   self,
  s,
  r,
  flags = 0 
)

Definition at line 50 of file gnunet_pyexpect.py.

50 def expect(self, s, r, flags=0):
51 stream = self.stdo if s == 'stdout' else self.stde
52 if isinstance(r, str):
53 if r == "EOF":
54 if len(stream) == 0:
55 return True
56 else:
57 print(
58 "Failed to find `{1}' in {0}, which is `{2}' ({3})".
59 format(s, r, stream, len(stream))
60 )
61 sys.exit(2)
62 raise ValueError(
63 "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'"
64 .format(r)
65 )
66 m = r.search(stream.decode(), flags)
67 if not m:
68 print(
69 "Failed to find `{1}' in {0}, which is is `{2}'".format(
70 s, r.pattern, stream
71 )
72 )
73 sys.exit(2)
74 stream = stream[m.end():]
75 if s == 'stdout':
76 self.stdo = stream
77 else:
78 self.stde = stream
79 return m
80

References gnunet_pyexpect.pexpect.stde, and gnunet_pyexpect.pexpect.stdo.

◆ read()

def gnunet_pyexpect.pexpect.read (   self,
  s,
  size = -1 
)

Definition at line 81 of file gnunet_pyexpect.py.

81 def read(self, s, size=-1):
82 stream = self.stdo if s == 'stdout' else self.stde
83 result = ""
84 if size < 0:
85 result = stream
86 new_stream = ""
87 else:
88 result = stream[0:size]
89 new_stream = stream[size:]
90 if s == 'stdout':
91 self.stdo = new_stream
92 else:
93 self.stde = new_stream
94 return result

References gnunet_pyexpect.pexpect.stde, and gnunet_pyexpect.pexpect.stdo.

Field Documentation

◆ proc

gnunet_pyexpect.pexpect.proc

Definition at line 40 of file gnunet_pyexpect.py.

◆ stde

gnunet_pyexpect.pexpect.stde

◆ stdo

gnunet_pyexpect.pexpect.stdo

The documentation for this class was generated from the following file: