Esempio n. 1
0
 def _repr_pretty_(self, p, cycle):
     from easypy.colors import DARK_CYAN
     # used by IPython
     class_name = self.__class__.__name__
     if cycle:
         p.text('%s(...)' % DARK_CYAN(class_name))
         return
     prefix = '%s(' % DARK_CYAN(class_name)
     with p.group(len(class_name) + 1, prefix, ')'):
         for idx, v in enumerate(self):
             if idx:
                 p.text(',')
                 p.breakable()
             p.pretty(v)
Esempio n. 2
0
 def _repr_pretty_(self, p, cycle):
     # used by IPython
     from easypy.colors import DARK_CYAN
     if cycle:
         p.text('Bunch(...)')
         return
     with p.group(6, 'Bunch(', ')'):
         for idx, (k, v) in enumerate(sorted(self.items())):
             if idx:
                 p.text(',')
                 p.breakable()
             with p.group(len(k) + 1, DARK_CYAN(k) + "="):
                 p.pretty(self[k])
Esempio n. 3
0
def ipython_fields_repr(name, field_items, p, cycle):
    from easypy.colors import DARK_CYAN
    if cycle:
        p.text('%s(...)' % (name, ))
        return
    prefix = '%s(' % (name, )
    with p.group(len(prefix), prefix, ')'):
        for idx, (k, v) in enumerate(field_items):
            if idx:
                p.text(',')
                p.breakable()
            with p.group(len(k) + 1, DARK_CYAN(k) + "="):
                p.pretty(v)
Esempio n. 4
0
def ipython_mapping_repr(mapping, p, cycle):
    # used by IPython. add to any mapping class as '_repr_pretty_'
    from easypy.colors import DARK_CYAN
    if cycle:
        p.text('%s(...)' % mapping.__class__.__name__)
        return
    prefix = '%s(' % mapping.__class__.__name__
    with p.group(len(prefix), prefix, ')'):
        for idx, (k, v) in enumerate(sorted(mapping.items())):
            if idx:
                p.text(',')
                p.breakable()
            with p.group(len(k)+1, DARK_CYAN(k) + "="):
                p.pretty(mapping[k])