def mangle_attr(source, attr):
    """
  Simulate python private attritubutes mangling. Taken from:
  http://stackoverflow.com/a/7789483/1162884
  """
    if not attr.startswith('__') or attr.endswith('__') or '.' in attr:
        return attr
    if not hasattr(source, '__bases__'):
        source = source.__class__
    return '_%s%s' % (source.__name__.lstrip('_'), attr)
