Exemplo n.º 1
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_with_predicate(self):
     self.assertEqual(U.rfirst(is_alpha, ''), None)
     self.assertEqual(U.rfirst(is_alpha, 'abc'), 'c')
     self.assertEqual(U.rfirst(is_alpha, 'abc123'), 'c')
     self.assertEqual(U.rfirst(is_alpha, 'abc   '), 'c')
 def test_all_match(self):
     self.assertEqual(U.rfirst(always, ''), None)
     self.assertEqual(U.rfirst(always, 'abc'), 'c')
 def test_no_match(self):
     self.assertEqual(U.rfirst(never, ''), None)
     self.assertEqual(U.rfirst(never, 'abc'), None)