示例#1
0
 def _repr_pretty_(self, p: pretty.PrettyPrinter, cycle: bool) -> None:
   del cycle  # Unused.
   icon = client_textify.online_icon(self._client.data.last_seen_at)
   last_seen = client_textify.last_seen(self._client.data.last_seen_at)
   data = '{icon} {id} @ {host} ({last_seen})'.format(
       icon=icon, id=self.id, last_seen=last_seen, host=self.hostname)
   p.text(data)
示例#2
0
    def _repr_contents(self, root: Text, p: pretty.PrettyPrinter) -> None:
        with p.group(4, '', ''):
            p.group_stack[-1].want_break = True

            for path, stat_entry in self._hierarchy[root]:
                p.breakable()
                p.text(str(_StatEntryData(stat_entry)))
                self._repr_contents(path, p)
示例#3
0
    def _repr_pretty_(self, p: pretty.PrettyPrinter, cycle: bool) -> None:
        """Print list of stat entries in IPython.

    Args:
      p: Pretty printer to pass output to.
      cycle: True, if printer detected a cycle.

    Returns:
      Nothing.
    """
        if cycle:
            raise AssertionError('Cycle in a stat entry list')

        if not self:
            p.text('No results.')
            return

        with p.group(0, '', ''):
            p.group_stack[-1].want_break = True

            for path, _ in self._hierarchy['']:
                p.breakable()
                p.text(path)
                self._repr_contents(path, p)
            p.breakable()
示例#4
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            '''Clean property format: Name[index] = (type) value'''
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            p.text(str(self.header.name) + '[')
            p.pretty(self.header.index)
            p.text(f'] = ')
            # p.text(f'{str(self.header.type)}) ')
            p.pretty(self.value)
示例#5
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            p.pretty(self._data)
            with p.group(4, '', ''):
                for node in self._nodes:
                    p.break_()
                    p.pretty(node)
示例#6
0
    def _repr_pretty_(self, p: pretty.PrettyPrinter, cycle: bool) -> None:
        """Print interface in IPython.

    Args:
      p: Pretty printer to pass output to.
      cycle: True, if printer detected a cycle.

    Returns:
      Nothing.
    """
        del cycle  # Unused.

        iface_data = '{name} (MAC: {mac}):'.format(name=self.name,
                                                   mac=self.mac)

        with p.group(0, iface_data, ''):
            p.group_stack[-1].want_break = True

            with p.group(4, '', ''):
                p.group_stack[-1].want_break = True

                for addr in self.addresses:
                    p.breakable()
                    p.text(str(_NetworkAddressData(addr)))
            p.breakable()
示例#7
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            '''Cleanly wrappable display in Jupyter.'''
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            with p.group(4, self.__class__.__name__ + '(', ')'):
                for idx, value in enumerate(self.values):
                    if idx:
                        p.text(',')
                        p.breakable()
                    p.pretty(value)
示例#8
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            p.text('Tree ')
            p.pretty(self.root)
示例#9
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            cls = self.__class__.__name__
            if cycle:
                p.text(f'{cls}(<cyclic>)')
                return

            if 'value' in self.field_values:
                p.pretty(self.value)
            else:
                p.text(f'{cls}(index={self.index})')
示例#10
0
    def _repr_pretty_(self, p: pretty.PrettyPrinter, cycle: bool) -> None:
        """Print list of clients in IPython.

    Args:
      p: Pretty printer to pass output to.
      cycle: True, if printer detected a cycle.

    Returns:
      Nothing.
    """
        if cycle:
            raise AssertionError('Cycle in a client list')

        if not self:
            p.text('No results.')
            return

        with p.group(0, '', ''):
            p.group_stack[-1].want_break = True

            for c in self:
                p.breakable()
                p.text(pretty.pretty(c))
            p.breakable()
示例#11
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            '''Cleanly wrappable display in Jupyter.'''
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            p.text(self.__class__.__name__ + '(')
            if self.enum.index == self.asset.none_index:
                p.pretty(self.value)
            else:
                p.pretty(self.enum)
                p.text(', ')
                p.pretty(self.value)
            p.text(')')
示例#12
0
def osquery_table_pretty(table: osquery_pb2.OsqueryTable,
                         p: pretty.PrettyPrinter, cycle: bool) -> None:
    del cycle  # Unused.
    df = convert.from_osquery_table(table)
    p.text(str(df))
示例#13
0
def interface_pretty(iface: jobs_pb2.Interface, p: pretty.PrettyPrinter,
                     cycle: bool) -> None:
    del cycle  # Unused.
    p.text(pretty.pretty(_InterfaceData(iface)))
示例#14
0
def network_address_pretty(address: jobs_pb2.NetworkAddress,
                           p: pretty.PrettyPrinter, cycle: bool) -> None:
    del cycle  # Unused.
    p.text(str(_NetworkAddressData(address)))
示例#15
0
def process_pretty(process: sysinfo_pb2.Process, p: pretty.PrettyPrinter,
                   cycle: bool) -> None:
    del cycle  # Unused.
    p.text(str(_ProcessData(process)))
示例#16
0
    def _repr_pretty_(self, p: pretty.PrettyPrinter, cycle: bool) -> None:
        """Print list of processes in IPython.

    Args:
      p: Pretty printer to pass output to.
      cycle: True, if printer detected a cycle.

    Returns:
      Nothing.
    """
        if cycle:
            raise AssertionError('Cycle in an process list')

        if not self:
            p.text('No results.')
            return

        header = (
            '{pid:>6s} {user:9s} {ni:>3s} {virt:>5s} {res:>5s} {s:1s} {cpu:4s} '
            '{mem:4s} {cmd}')
        header = header.format(pid='PID',
                               user='******',
                               ni='NI',
                               virt='VIRT',
                               res='RES',
                               s='S',
                               cpu='CPU%',
                               mem='MEM%',
                               cmd='Command')

        with p.group(0, '', ''):
            p.group_stack[-1].want_break = True
            p.breakable()
            p.text(header[:p.max_width])

            for process in self:
                p.breakable()
                p.text(str(_ProcessData(process))[:p.max_width])
            p.breakable()
示例#17
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            '''Cleanly wrappable display in Jupyter.'''
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            with p.group(4, self.__class__.__name__ + '(', ')'):
                p.text(
                    f'count={self.count}, itemType={self.itemType.__name__}')
                for idx, value in enumerate(self.values):
                    p.text(',')
                    p.breakable()
                    p.text(f'0x{idx:04X} ({idx:<4}): ')
                    p.pretty(value)
示例#18
0
def stat_entry_pretty(stat_entry: jobs_pb2.StatEntry, p: pretty.PrettyPrinter,
                      cycle: bool) -> None:
    del cycle  # Unused.
    p.text(str(_StatEntryData(stat_entry)))
示例#19
0
def buffer_reference_pretty(ref: jobs_pb2.BufferReference,
                            p: pretty.PrettyPrinter, cycle: bool) -> None:
    del cycle  # Unused.
    p.text(str(_BufferReferenceData(ref)))
示例#20
0
        def _repr_pretty_(self, p: PrettyPrinter, cycle: bool):
            '''Cleanly wrappable display in Jupyter.'''
            if cycle:
                p.text(self.__class__.__name__ + '(<cyclic>)')
                return

            if self.skip_level_field:
                p.pretty(getattr(self, self.skip_level_field))
                return

            if self.main_field:
                p.pretty(getattr(self, self.main_field))
                return

            if self.string_format:
                p.pretty(self.string_format.format(**self.field_values))
                return

            fields = self.display_fields or self.field_order
            with p.group(4, self.__class__.__name__ + '(', ')'):
                if len(fields) > 1:
                    for idx, name in enumerate(fields):
                        if idx:
                            p.text(',')
                            p.breakable()
                        p.text(name + '=')
                        p.pretty(self.field_values[name])
                else:
                    p.pretty(self.field_values[fields[0]])
示例#21
0
 def _repr_pretty_(self, p: PrettyPrinter, cycle: bool) -> None:
     class_name = self.__class__.__name__
     if cycle:
         p.text(f"{class_name}(...)")
     else:
         with p.group(indent=2, open=f"{class_name}("):
             p.breakable()
             p.text("sliders=")
             p.pretty(self._sliders)
             p.text(",")
             p.breakable()
             p.text("arg_to_symbol=")
             p.pretty(self._arg_to_symbol)
             p.text(",")
         p.breakable()
         p.text(")")