(self, dat, new_obj)
Encode dat as a class or instance.
Encode dat as a class or instance.
Encode dat as a class or instance .
def encode_class_or_instance(self, dat, new_obj):
    """Encode dat as a class or instance."""
    if is_instance(dat):
      if hasattr(dat, '__class__'):
        # common case ...
        class_name = get_name(dat.__class__)
      else:
        # super special case for something like
        # "from datetime import datetime_CAPI" in Python 3.2,
        # which is some weird 'PyCapsule' type ...
        # http://docs.python.org/release/3.1.5/c-api/capsule.html
        class_name = get_name(type(dat))

      new_obj.extend(['INSTANCE', class_name])
      # don't traverse inside modules, or else risk EXPLODING the visualization
      if class_name == 'module':
        return
    else:
      superclass_names = [e.__name__ for e in dat.__bases__ if e is not object]
      new_obj.extend(['CLASS', get_name(dat), superclass_names])

    # traverse inside of its __dict__ to grab attributes
    # (filter out useless-seeming ones):
    hidden = ('__doc__', '__module__', '__return__', '__dict__',
        '__locals__', '__weakref__')
    if hasattr(dat, '__dict__'):
      user_attrs = sorted([e for e in dat.__dict__ if e not in hidden])
    else:
      user_attrs = []

    for attr in user_attrs:
      new_obj.append([self.encode(attr, None), self.encode(dat.__dict__[attr], None)])
def encode_class_or_instance ( self , dat , new_obj ) : if is_instance ( dat ) : if hasattr ( dat , '__class__' ) : # common case ... class_name = get_name ( dat . __class__ ) else : # super special case for something like # "from datetime import datetime_CAPI" in Python 3.2, # which is some weird 'PyCapsule' type ... # http://docs.python.org/release/3.1.5/c-api/capsule.html class_name = get_name ( type ( dat ) ) new_obj . extend ( [ 'INSTANCE' , class_name ] ) # don't traverse inside modules, or else risk EXPLODING the visualization if class_name == 'module' : return else : superclass_names = [ e . __name__ for e in dat . __bases__ if e is not object ] new_obj . extend ( [ 'CLASS' , get_name ( dat ) , superclass_names ] ) # traverse inside of its __dict__ to grab attributes # (filter out useless-seeming ones): hidden = ( '__doc__' , '__module__' , '__return__' , '__dict__' , '__locals__' , '__weakref__' ) if hasattr ( dat , '__dict__' ) : user_attrs = sorted ( [ e for e in dat . __dict__ if e not in hidden ] ) else : user_attrs = [ ] for attr in user_attrs : new_obj . append ( [ self . encode ( attr , None ) , self . encode ( dat . __dict__ [ attr ] , None ) ] )