示例#1
0
def communicate(p, commands=None):
    if isinstance(commands, list) or isinstance(commands, tuple):
        commands = "\n".join(str(c) for c in commands)
    if commands is not None:
        commands = str.encode(commands)
    stdout, stderr = p.communicate(commands)
    if stdout is not None:
        stdout = textprocessing.bytes_to_text(stdout)
    if stderr is not None:
        stderr = textprocessing.bytes_to_text(stderr)
    return stdout, stderr
示例#2
0
def communicate(p, commands=None):
    if isinstance(commands, list) or isinstance(commands, tuple):
        commands = "\n".join(str(c) for c in commands)
    if commands is not None:
        commands = str.encode(commands)
    stdout, stderr = p.communicate(commands)
    if stdout is not None:
        stdout = textprocessing.bytes_to_text(stdout)
    if stderr is not None:
        stderr = textprocessing.bytes_to_text(stderr)
    return stdout, stderr
示例#3
0
def read_url(url, strip_markup=False):
    """
    Return contents of url as string.
    """
    s = urlopen(url)
    text = textprocessing.bytes_to_text(s.read())
    if strip_markup:
        return re.sub(r'<[^>]*?>', '', text)
    else:
        return text
示例#4
0
def read_url(url, strip_markup=False):
    """
    Return contents of url as string.
    """
    s = urlopen(url)
    text = textprocessing.bytes_to_text(s.read())
    if strip_markup:
        return re.sub(r'<[^>]*?>', '', text)
    else:
        return text
示例#5
0
def communicate(p, commands=None, timeout=None):
    if isinstance(commands, list) or isinstance(commands, tuple):
        commands = "\n".join(str(c) for c in commands)
    if commands is not None:
        commands = str.encode(commands)
    if timeout is None:
        stdout, stderr = p.communicate(commands)
    else:
        try:
            stdout, stderr = p.communicate(commands, timeout=timeout)
        except TypeError as e:
            if "unexpected keyword argument 'timeout'" in str(e):
                stdout, stderr = p.communicate(commands)
            else:
                raise
    if stdout is not None:
        stdout = textprocessing.bytes_to_text(stdout)
    if stderr is not None:
        stderr = textprocessing.bytes_to_text(stderr)
    return stdout, stderr
示例#6
0
def communicate(p, commands=None, timeout=None):
    if isinstance(commands, list) or isinstance(commands, tuple):
        commands = "\n".join(str(c) for c in commands)
    if commands is not None:
        commands = str.encode(commands)
    if timeout is None:
        stdout, stderr = p.communicate(commands)
    else:
        try:
            stdout, stderr = p.communicate(commands, timeout=timeout)
        except TypeError as e:
            if "unexpected keyword argument 'timeout'" in str(e):
                stdout, stderr = p.communicate(commands)
            else:
                raise
    if stdout is not None:
        stdout = textprocessing.bytes_to_text(stdout)
    if stderr is not None:
        stderr = textprocessing.bytes_to_text(stderr)
    return stdout, stderr