def GetFieldFromUser(user, field_name, sub_field_name=None):
  """Safely retrieves a field from a user dictionary object.

  Some User fields are expressed as dictionaries of sub-fields instead of as
  simple values. This method allows retrieval of both field values and
  sub_field values.  In the following sample User record:

    fields: customerId, isAdmin, kind, name
    sub_fields: fullName, givenName, familyName

    {customerId: A03abcde4
     isAdmin: True
     kind: directory#user
     name: {u'fullName': u'George Enlighten', u'givenName': u'George',
            u'familyName': u'Enlighten'}
    }

  Args:
    user: A user object returned from an Apiary service.
    field_name: String field name for an element in a dictionary.
    sub_field_name: Sometimes retrieve a field from an embedded dictionary.

  Returns:
    If the field is present, returns the field contents.
    Otherwise returns template text to warn the user
    that data fields have changed.
  """
  if field_name not in user:
    return _MISSING_FIELD_STUB % field_name
  field_value = user.get(field_name)
  if sub_field_name:
    if not field_value or sub_field_name not in field_value:
      return _MISSING_FIELD_STUB % ('[%s][%s]' % (field_name, sub_field_name))
    return field_value.get(sub_field_name)
  return field_value
dataset/ETHPy150Open google/gfw-toolkit/toolkit/admin_sdk_directory_api/users_api.py/GetFieldFromUser/original