Ignore:
Timestamp:
09/02/13 16:12:42 (8 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Rebase:
66656437653561326434663063336136316639326530643531646165636435346662656261303831
Message:

Render tuples to lists

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/yamlish.py

    r137 r138  
    3535
    3636    def _dump_block(self, data, indent=0):
    37         for type_ in (list, dict):
     37        for type_ in (list, tuple, dict):
    3838            if isinstance(data, type_):
    3939                f = getattr(self, '_dump_%s_block' % type_.__name__)
     
    4242
    4343    def _dump_inline(self, data):
    44         if data in (True, False, None):
     44        if data is True or data is False or data is None:
    4545            return self._dump_literal(data)
    46         for type_ in (list, dict, basestring, int, float):
     46        for type_ in (list, tuple, dict, basestring, int, float):
    4747            if isinstance(data, type_):
    4848                f = getattr(self, '_dump_%s' % type_.__name__)
     
    6161                output += dumped
    6262        return output
     63
     64    _dump_tuple_block = _dump_list_block
    6365
    6466    def _dump_dict_block(self, data, indent):
     
    7779
    7880    def _inlineable(self, data):
    79         if isinstance(data, list):
    80             return all(not isinstance(item, (list, dict)) for item in data)
     81        if isinstance(data, (list, tuple)):
     82            return all(not isinstance(item, (list, dict, tuple))
     83                       for item in data)
    8184        elif isinstance(data, dict):
    82             return all(not isinstance(item, (list, dict))
     85            return all(not isinstance(item, (list, dict, tuple))
    8386                       for item in data.itervalues())
    8487        else:
     
    8891        return '[%s]' % ', '.join(self._dump_inline(item) for item in data)
    8992
     93    _dump_tuple = _dump_list
     94
    9095    def _dump_dict(self, data):
    9196        return '{%s}' % ', '.join(
    92                 '%s: %s' % (self._dump_inline(key), self._dump_inline(value))
    93                 for key, value in data.iteritems())
     97            '%s: %s' % (self._dump_inline(key), self._dump_inline(value))
     98            for key, value in data.iteritems())
    9499
    95100    def _dump_basestring(self, data):
Note: See TracChangeset for help on using the changeset viewer.