code: def parse_dataset_name(name, project_id=None):
    
    _project_id = _dataset_id = None
    if isinstance(name, basestring):
      # Try to parse as absolute name first.
      m = re.match(_ABS_DATASET_NAME_PATTERN, name, re.IGNORECASE)
      if m is not None:
        _project_id, _dataset_id = m.groups()
      else:
        # Next try to match as a relative name implicitly scoped within current project.
        m = re.match(_REL_DATASET_NAME_PATTERN, name)
        if m is not None:
          groups = m.groups()
          _dataset_id = groups[0]
    elif isinstance(name, dict):
      try:
        _dataset_id = name['dataset_id']
        _project_id = name['project_id']
      except KeyError:
        pass
    else:
      # Try treat as an array or tuple
      if len(name) == 2:
        # Treat as a tuple or array.
        _project_id, _dataset_id = name
      elif len(name) == 1:
        _dataset_id = name[0]
    if not _dataset_id:
      raise Exception('Invalid dataset name: ' + str(name))
    if not _project_id:
      _project_id = project_id
  
    return DatasetName(_project_id, _dataset_id)
docs: Parses a dataset name into its individual parts.
  
    Args:
      name: the name to parse, or a tuple, dictionary or array containing the parts.
      project_id: the expected project ID. If the name does not contain a project ID,
          this will be used; if the name does contain a project ID and it does not match
          this, an exception will be thrown.
    Returns:
      A DatasetName named tuple for the dataset.
    Raises:
      Exception: raised if the name doesn't match the expected formats or a project_id was
          specified that does not match that in the name.