def DSQuery(dstype, objectname, attribute=None, node='.'):
  """DirectoryServices query.

  Args:
    dstype: The type of objects to query. user, group.
    objectname: the object to query.
    attribute: the optional attribute to query.
    node: the node to query.
  Returns:
    If an attribute is specified, the value of the attribute. Otherwise, the
    entire plist.
  Raises:
    DSException: Cannot query DirectoryServices.
  """
  ds_path = '/%ss/%s' % (dstype.capitalize(), objectname)
  cmd = [_DSCL, '-plist', node, '-read', ds_path]
  if attribute:
    cmd.append(attribute)
  (stdout, stderr, returncode) = gmacpyutil.RunProcess(cmd)
  if returncode:
    raise DSException('Cannot query %s for %s: %s' % (ds_path,
                                                      attribute,
                                                      stderr))
  plist = NSString.stringWithString_(stdout).propertyList()
  if attribute:
    value = None
    if 'dsAttrTypeStandard:%s' % attribute in plist:
      value = plist['dsAttrTypeStandard:%s' % attribute]
    elif attribute in plist:
      value = plist[attribute]
    try:
      # We're copying to a new list to convert from NSCFArray
      return value[:]
    except __HOLE__:
      # ... unless we can't
      return value
  else:
    return plist
dataset/ETHPy150Open google/macops/gmacpyutil/gmacpyutil/ds.py/DSQuery