print a table of items, for a set of fields defined

            Parameters
            ==========
            items: a list of items to print
            fields: a list of fields to select from items
434031
def print_table(self, items, fields):
        
        formats = []
        borders = []
        for f in fields:
            length = max(
                len(f), max([len(self.string(getattr(i, f))) for i in items]))
            justify = '>' if isinstance(getattr(
                items[0], f), int) or f == 'size' or f == 'reward' else '<'
            formats.append('{:' + justify + self.string(length + 2) + '}')
            borders.append('-' * length + '  ')
        row_format = u''.join(formats)
        headers = [f + '  ' for f in fields]
        print(row_format.format(*headers))
        print(row_format.format(*borders))
        for i in items:
            i_fields = [self.string(getattr(i, f)) + '  ' for f in fields]
            try:
                print(row_format.format(*i_fields))
            except UnicodeEncodeError:
                print(row_format.format(*i_fields).encode('utf-8'))
88770
def print_item_with_children(ac, classes, level):
    
    print_row(ac.id, ac.name, f"{ac.allocation:,.2f}", level)
    print_children_recursively(classes, ac, level + 1)
539360
def parameter_list(data):
        
        items = []
        for item in data:
            param = Parameter(item['name'], item['value'])
            if 'meta' in item: param.meta = item['meta']
            items.append(param)
        return items
1208026
def tabulate(data, header=True, headers=None, accessors=None,
             **table_options):
    
    if header and not headers:
        data = iter(data)
        try:
            headers = next(data)
        except StopIteration:
            pass
    if headers and hasattr(headers, 'items') and accessors is None:
        # Dict mode; Build accessors and headers from keys of data.
        data = itertools.chain([headers], data)
        accessors = list(headers)
        headers = [' '.join(map(str.capitalize, x.replace('_', ' ').split()))
                   for x in accessors]
    t = Table(headers=headers, accessors=accessors, **table_options)
    try:
        t.print(data)
    except RowsNotFound:
        pass
    return t
829254
def list( items, mode = :rows, option = nil )
    items = items.to_ary.map do |item|
      ERB.new(item, nil, "%").result(binding)
    end
    
    case mode
    when :inline
      option = " or " if option.nil?
      
      case items.size
      when 0
        ""
      when 1
        items.first
      when 2
        "#{items.first}#{option}#{items.last}"
      else
        items[0..-2].join(", ") + "#{option}#{items.last}"
      end
    when :columns_across, :columns_down
      max_length = actual_length(
        items.max { |a, b| actual_length(a) <=> actual_length(b) }
      )

      if option.nil?
        limit  = @wrap_at || 80
        option = (limit + 2) / (max_length + 2)
      end

      items     = items.map do |item|
        pad = max_length + (item.length - actual_length(item))
        "%-#{pad}s" % item
      end
      row_count = (items.size / option.to_f).ceil
      
      if mode == :columns_across
        rows = Array.new(row_count) { Array.new }
        items.each_with_index do |item, index|
          rows[index / option] << item
        end

        rows.map { |row| row.join("  ") + "\n" }.join
      else
        columns = Array.new(option) { Array.new }
        items.each_with_index do |item, index|
          columns[index / row_count] << item
        end
      
        list = ""
        columns.first.size.times do |index|
          list << columns.map { |column| column[index] }.
                          compact.join("  ") + "\n"
        end
        list
      end
    else
      items.map { |i| "#{i}\n" }.join
    end
  end
72454
def table_info_to_parameters(table_info):
    

    # Example of item in table_info:
    #   MyDBRow([('cid', 0), ('name', 'id'), ('type', 'integer'), ('notnull', 0), ('dflt_value', None), ('pk', 1)])

    opbj = a99.Parameters()
    for field_info in table_info.values():
        p = a99.Parameter()
        if field_info.type == "integer":
            p.type = int
        elif field_info.type == "real":
            p.type = float
        else:
            p.type = str

        p.name = field_info.name
        if field_info.dflt_value is not None:
            p.value = field_info.dflt_value
        opbj.params.append(p)
    return opbj
1162456
def prepare_fields(fields):
    
    def process_item(value):
        if not isinstance(value, NUMERIC_TYPES):
            if isinstance(value, six.string_types):
                # encode utf-8 to unicode, if necessary
                return force_text(value)
            else:
                if isinstance(value, dict):
                    return prepare_fields(value)
                elif isinstance(value, list):
                    return list(map(process_item, value))

                return six.text_type(value)
        return value

    return dict((key, process_item(value))
                for key, value
                in fields.items())
136752
def pretty_print_table(headers, rows):
    """"""
    table = make_table(headers=headers, rows=rows)
    pretty_print_table_instance(table)
436181
def a_list(label=None, kwargs=None, attributes=None):
    
    result = ['label=%s' % quote(label)] if label is not None else []
    if kwargs:
        items = ['%s=%s' % (quote(k), quote(v))
            for k, v in tools.mapping_items(kwargs) if v is not None]
        result.extend(items)
    if attributes:
        if hasattr(attributes, 'items'):
            attributes = tools.mapping_items(attributes)
        items = ['%s=%s' % (quote(k), quote(v))
            for k, v in attributes if v is not None]
        result.extend(items)
    return ' '.join(result)
544136
def list(self,table, **kparams):
        
        records = self.api.list(table, **kparams)
        return records
465599
def print_horiz_table(self, data):
        """"""

        # Build list of returned objects
        return_objects = list()
        fields = self.job_args.get('fields')
        if not fields:
            fields = set()
            for item_dict in data:
                for field_item in item_dict.keys():
                    fields.add(field_item)
            fields = sorted(fields)

        for obj in data:
            item_struct = dict()
            for item in fields:
                item_struct[item] = obj.get(item)
            else:
                return_objects.append(item_struct)

        table = prettytable.PrettyTable(fields)
        for obj in return_objects:
            table.add_row([obj.get(i) for i in fields])

        for tbl in table.align.keys():
            table.align[tbl] = 'l'

        sort_key = self.job_args.get('sort_by')
        if sort_key:
            table.sortby = sort_key

        self.printer(table)
534063
def fieldnames(self):
        ''' 
        '''
        if not self._fields:
            if self._item_class is not None:
                for m in inspect.getmembers(self._item_class):
                    if m[0] == 'fields' and isinstance(m[1], dict):
                        self._fields = m[1]
                if not self._fields:
                    raise RuntimeError('Unknown item type, no fields: %s' % self._item_class)
            else:
                raise RuntimeError('Item class is not defined, %s' % self._item_class)
        return self._fields.keys()
957553
def _parse_fields(self, result, field_name):
        
        field_list = []
        for key, value in result.get('schema', {}).get(field_name, {}).items():
            if key not in field_list:
                field_list.append(key)
        return field_list
196298
def format_items(self, data, many):
        
        if many:
            return [self.format_item(item) for item in data]
        else:
            return self.format_item(data)
866032
def __print_table(table):
        """"""

        col_width = [max(len(x) for x in col) for col in zip(*table)]
        print("| " + " | ".join("{:{}}".format(x, col_width[i])
                                for i, x in enumerate(table[0])) + " |")
        print("| " + " | ".join("{:{}}".format('-' * col_width[i], col_width[i])
                                for i, x in enumerate(table[0])) + " |")
        for line in table[1:]:
            print("| " + " | ".join("{:{}}".format(x, col_width[i])
                                    for i, x in enumerate(line)) + " |")
674728
def parse_items(self, field: Field) -> Mapping[str, Any]:
        
        return self.build_parameter(field.container)
596829
def list(cls, params=None):
        
        return fields.ListField(name=cls.ENDPOINT, init_class=cls).decode(
            cls.element_from_string(cls._get_request(params=params).text)
        )