def pb_set(msg, field_name, val):
 field_desc = msg.DESCRIPTOR.fields_by_name[field_name]
 proper_type = cpp_type_to_python[field_desc.cpp_type]
 try_types = (type(val), proper_type)
 for t in try_types:
  log.debug(u'attempt %s.%s = %s(%r)', msg.__class__.__name__, field_name, t, val)
  try:
   setattr(msg, field_name, t(val))
   log.debug(u'! success')
   break
  except (TypeError, ValueError):
   log.debug(u'X failure')
 else:
  return False
 return True

def pb_set ( msg , field_name , val ) : field_desc = msg . DESCRIPTOR . fields_by_name [ field_name ] proper_type = cpp_type_to_python [ field_desc . cpp_type ] try_types = ( type ( val ) , proper_type ) for t in try_types : log . debug ( u'attempt %s.%s = %s(%r)' , msg . __class__ . __name__ , field_name , t , val ) try : setattr ( msg , field_name , t ( val ) ) log . debug ( u'! success' ) break except ( TypeError , ValueError ) : log . debug ( u'X failure' ) else : return False return True
return true and set val to field_name in msg if the assignment is type-compatible .