def get_body(lines):
    """
    Extracts only the body of the "net use" table. The body is everything between the column
    headers and the end of the output.
    `lines` is a list of strings from the output of `NET USE`.
    """
    bottom = drop_while(not_(is_line_separator), lines)
    is_last_line = lambda x: x and x != LAST_TABLE_LINE
    return (take_while(is_last_line, bottom[1:]) if len(bottom) > 1 else [])
Esempio n. 2
0
def get_body(lines):
    """
    Extracts only the body of the "net use" table. The body is everything between the column
    headers and the end of the output.
    `lines` is a list of strings from the output of `NET USE`.
    """
    bottom = drop_while(not_(is_line_separator), lines)
    is_last_line = lambda x: x and x != LAST_TABLE_LINE
    return take_while(is_last_line, bottom[1:]) if len(bottom) > 1 else []
def is_valid_unc_path(string):
    """
    Valid UNC paths are at least three characters long, begin with exactly two backslashes, do not
    start or end with whitepsace, and do not contain certain invalid characters
    (see `sanitize_unc_path`).
    """
    return (len(string) > 2
            and len(take_while(lambda c: c == '\\', string)) == 2
            and string == string.strip()
            and string == sanitize_unc_path(string))
Esempio n. 4
0
def get_columns(lines):
    """
    Parses the column headers from a "net use" table into a list of `NetUseColumn` objects.
    `lines` is a list of strings from the output of `NET USE`.
    """
    header_iter = take_while(not_(is_line_separator), lines)
    headings = rfirst(lambda x: x and x[0].isalpha(), header_iter)

    names = headings.split()
    starts = [headings.index(name) for name in names]
    ends = [right - 1 for right in starts[1:]] + [None]

    return [NetUseColumn(name, start, end) for name, start, end in zip(names, starts, ends)]
def get_columns(lines):
    """
    Parses the column headers from a "net use" table into a list of `NetUseColumn` objects.
    `lines` is a list of strings from the output of `NET USE`.
    """
    header_iter = take_while(not_(is_line_separator), lines)
    headings = rfirst(lambda x: x and x[0].isalpha(), header_iter)

    names = headings.split()
    starts = [headings.index(name) for name in names]
    ends = [right - 1 for right in starts[1:]] + [None]

    return [
        NetUseColumn(name, start, end)
        for name, start, end in zip(names, starts, ends)
    ]
 def test_take_with_predicate(self):
     self.assertEqualAsLists(U.take_while(is_alpha, ''), '')
     self.assertEqualAsLists(U.take_while(is_alpha, 'abc'), 'abc')
     self.assertEqualAsLists(U.take_while(is_alpha, '123abc456'), '')
     self.assertEqualAsLists(U.take_while(is_alpha, '   abc   '), '')
     self.assertEqualAsLists(U.take_while(is_alpha, '   '), '')
 def test_take_everything(self):
     self.assertEqualAsLists(U.take_while(always, ''), '')
     self.assertEqualAsLists(U.take_while(always, 'a'), 'a')
     self.assertEqualAsLists(U.take_while(always, 'abc'), 'abc')
 def test_take_nothing(self):
     self.assertEqualAsLists(U.take_while(never, ''), '')
     self.assertEqualAsLists(U.take_while(never, 'a'), '')
     self.assertEqualAsLists(U.take_while(never, 'abc'), '')