Skip to content

Commit

Permalink
Merge pull request #429 from eoyilmaz/296-cant-install-the-profile-af…
Browse files Browse the repository at this point in the history
…ter-calibration-sudo-timeout

[#296] Fixed #296.
  • Loading branch information
eoyilmaz authored Oct 15, 2024
2 parents 8903be9 + c211362 commit 0aff7b0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 63 deletions.
109 changes: 55 additions & 54 deletions DisplayCAL/wexpect.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,12 @@ def spawn(


class spawn_unix(object):
"""This is the main class interface for Pexpect. Use this class to start and control child applications.
"""The main class interface for Pexpect.
The command parameter may be a string that
includes a command and any arguments to the command. For example::
Use this class to start and control child applications.
The command parameter may be a string that includes a command and any arguments to
the command. For example::
child = pexpect.spawn('/usr/bin/ftp')
child = pexpect.spawn('/usr/bin/ssh [email protected]')
Expand Down Expand Up @@ -500,8 +502,6 @@ class spawn_unix(object):
If you need more detail you can also read the self.status member which
stores the status returned by os.waitpid. You can interpret this using
os.WIFEXITED/os.WEXITSTATUS or os.WIFSIGNALED/os.TERMSIG.
"""

def __init__(
Expand Down Expand Up @@ -984,7 +984,7 @@ def read_nonblocking(self, size=1, timeout=-1):
raise EOF(
"End Of File (EOF) in read_nonblocking(). Exception style platform."
)
if s == "": # BSD style
if s == b"": # BSD style
self.flag_eof = True
raise EOF(
"End Of File (EOF) in read_nonblocking(). Empty string style platform."
Expand Down Expand Up @@ -1376,46 +1376,46 @@ def compile_pattern_list(self, patterns):
return compiled_pattern_list

def expect(self, pattern, timeout=-1, searchwindowsize=None):
"""This seeks through the stream until a pattern is matched. The
pattern is overloaded and may take several types. The pattern can be a
StringType, EOF, a compiled re, or a list of any of those types.
Strings will be compiled to re types. This returns the index into the
pattern list. If the pattern was not a list this returns index 0 on a
successful match. This may raise exceptions for EOF or TIMEOUT. To
avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to the pattern
list. That will cause expect to match an EOF or TIMEOUT condition
"""Seek through the stream until a pattern is matched.
The pattern is overloaded and may take several types. The pattern can be a
StringType, EOF, a compiled re, or a list of any of those types. Strings will be
compiled to re types.
This returns the index into the pattern list. If the pattern was not a list this
returns index 0 on a successful match. This may raise exceptions for EOF or
TIMEOUT. To avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to the
pattern list. That will cause expect to match an EOF or TIMEOUT condition
instead of raising an exception.
If you pass a list of patterns and more than one matches, the first match
in the stream is chosen. If more than one pattern matches at that point,
the leftmost in the pattern list is chosen. For example::
If you pass a list of patterns and more than one matches, the first match in the
stream is chosen. If more than one pattern matches at that point, the leftmost
in the pattern list is chosen. For example::
# the input is 'foobar'
index = p.expect (['bar', 'foo', 'foobar'])
# returns 1 ('foo') even though 'foobar' is a "better" match
Please note, however, that buffering can affect this behavior, since
input arrives in unpredictable chunks. For example::
Please note, however, that buffering can affect this behavior, since input
arrives in unpredictable chunks. For example::
# the input is 'foobar'
index = p.expect (['foobar', 'foo'])
# returns 0 ('foobar') if all input is available at once,
# but returs 1 ('foo') if parts of the final 'bar' arrive late
After a match is found the instance attributes 'before', 'after' and
'match' will be set. You can see all the data read before the match in
'before'. You can see the data that was matched in 'after'. The
re.MatchObject used in the re match will be in 'match'. If an error
occurred then 'before' will be set to all the data read so far and
'after' and 'match' will be None.
After a match is found the instance attributes 'before', 'after' and 'match'
will be set. You can see all the data read before the match in 'before'. You can
see the data that was matched in 'after'. The re.MatchObject used in the re
match will be in 'match'. If an error occurred then 'before' will be set to all
the data read so far and 'after' and 'match' will be None.
If timeout is -1 then timeout will be set to the self.timeout value.
A list entry may be EOF or TIMEOUT instead of a string. This will
catch these exceptions and return the index of the list entry instead
of raising the exception. The attribute 'after' will be set to the
exception type. The attribute 'match' will be None. This allows you to
write code like this::
A list entry may be EOF or TIMEOUT instead of a string. This will catch these
exceptions and return the index of the list entry instead of raising the
exception. The attribute 'after' will be set to the exception type. The
attribute 'match' will be None. This allows you to write code like this::
index = p.expect (['good', 'bad', pexpect.EOF, pexpect.TIMEOUT])
if index == 0:
Expand All @@ -1440,9 +1440,9 @@ def expect(self, pattern, timeout=-1, searchwindowsize=None):
except TIMEOUT:
do_something_completely_different()
These two forms are equivalent. It all depends on what you want. You
can also just expect the EOF if you are waiting for all output of a
child to finish. For example::
These two forms are equivalent. It all depends on what you want. You can also
just expect the EOF if you are waiting for all output of a child to finish. For
example::
p = pexpect.spawn('/bin/ls')
p.expect (pexpect.EOF)
Expand All @@ -1454,15 +1454,15 @@ def expect(self, pattern, timeout=-1, searchwindowsize=None):
return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)

def expect_list(self, pattern_list, timeout=-1, searchwindowsize=-1):
"""This takes a list of compiled regular expressions and returns the
index into the pattern_list that matched the child output. The list may
also contain EOF or TIMEOUT (which are not compiled regular
"""Return the index into the pattern_list that matched the child output.
The list may also contain EOF or TIMEOUT (which are not compiled regular
expressions). This method is similar to the expect() method except that
expect_list() does not recompile the pattern list on every call. This
may help if you are trying to optimize for speed, otherwise just use
the expect() method. This is called by expect(). If timeout==-1 then
the self.timeout value is used. If searchwindowsize==-1 then the
self.searchwindowsize value is used."""
expect_list() does not recompile the pattern list on every call. This may help
if you are trying to optimize for speed, otherwise just use the expect() method.
This is called by expect(). If timeout==-1 then the self.timeout value is used.
If searchwindowsize==-1 then the self.searchwindowsize value is used.
"""
return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)

def expect_exact(self, pattern_list, timeout=-1, searchwindowsize=-1):
Expand All @@ -1484,11 +1484,13 @@ def expect_exact(self, pattern_list, timeout=-1, searchwindowsize=-1):
)

def expect_loop(self, searcher, timeout=-1, searchwindowsize=-1):
"""This is the common loop used inside expect. The 'searcher' should be
an instance of searcher_re or searcher_string, which describes how and what
to search for in the input.
"""The common loop used inside expect.
The 'searcher' should be an instance of searcher_re or searcher_string, which
describes how and what to search for in the input.
See expect() for other arguments, return value and exceptions."""
See expect() for other arguments, return value and exceptions.
"""
self.searcher = searcher

end_time = -1
Expand Down Expand Up @@ -2841,8 +2843,7 @@ def search(self, buffer, freshlen, searchwindowsize=None):


class searcher_re(object):
"""This is regular expression string search helper for the
spawn.expect_any() method.
"""Regular expression string search helper for the spawn.expect_any() method.
Attributes:
Expand Down Expand Up @@ -2876,8 +2877,7 @@ def __init__(self, patterns):
self._searches.append((n, s))

def __str__(self):
"""This returns a human-readable string that represents the state of
the object."""
"""Return a human-readable string that represents the state of the object."""
ss = [
(n, ' %d: re.compile(r"%s")' % (n, str(s.pattern)))
for n, s in self._searches
Expand All @@ -2892,14 +2892,15 @@ def __str__(self):
return "\n".join(ss)

def search(self, buffer, freshlen, searchwindowsize=None):
"""This searches 'buffer' for the first occurence of one of the regular
expressions. 'freshlen' must indicate the number of bytes at the end of
'buffer' which have not been searched before.
"""Search 'buffer' for the first occurence of one of the regular expressions.
'freshlen' must indicate the number of bytes at the end of 'buffer' which have
not been searched before.
See class spawn for the 'searchwindowsize' argument.
If there is a match this returns the index of that string, and sets
'start', 'end' and 'match'. Otherwise, returns -1.
If there is a match this returns the index of that string, and sets 'start',
'end' and 'match'. Otherwise, returns -1.
"""
absurd_match = len(buffer)
first_match = absurd_match
Expand Down
19 changes: 10 additions & 9 deletions DisplayCAL/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1945,11 +1945,10 @@ def __str__(self):
def _expect_timeout(self, patterns, timeout=-1, child_timeout=1):
"""wexpect.spawn.expect with better timeout handling.

The default expect can block up to timeout seconds if the child is
already dead. To prevent this, we run expect in a loop until a pattern
is matched, timeout is reached or an exception occurs. The max time an
expect call will block if the child is already dead can be set with the
child_timeout parameter.
The default expect can block up to timeout seconds if the child is already dead.
To prevent this, we run expect in a loop until a pattern is matched, timeout is
reached or an exception occurs. The max time an expect call will block if the
child is already dead can be set with the child_timeout parameter.
"""
if timeout == -1:
timeout = self.subprocess.timeout
Expand Down Expand Up @@ -2082,10 +2081,12 @@ def authenticate(self, args, title, parent=None):
return self.is_allowed(args, pwd), pwd

def is_allowed(self, args=None, pwd=""):
"""Check if a command is allowed via sudo. Return either a string
listing allowed and forbidden commands, or the fully-qualified path of
the command along with any arguments, or an error message in case the
command is not allowed, or False if the password was not accepted.
"""Check if a command is allowed via sudo.

Return either a string listing allowed and forbidden commands, or the
fully-qualified path of the command along with any arguments, or an error
message in case the command is not allowed, or False if the password was not
accepted.

The returned error is a custom class that will always have length 0
if the command is not allowed (even if the actual string length is
Expand Down

0 comments on commit 0aff7b0

Please sign in to comment.