code: def _get_period_range_edges(first, last, offset, closed='left', base=0):
      
      if not all(isinstance(obj, pd.Period) for obj in [first, last]):
          raise TypeError("'first' and 'last' must be instances of type Period")
  
      # GH 23882
      first = first.to_timestamp()
      last = last.to_timestamp()
      adjust_first = not offset.onOffset(first)
      adjust_last = offset.onOffset(last)
  
      first, last = _get_timestamp_range_edges(first, last, offset,
                                               closed=closed, base=base)
  
      first = (first + adjust_first * offset).to_period(offset)
      last = (last - adjust_last * offset).to_period(offset)
      return first, last
docs: Adjust the provided `first` and `last` Periods to the respective Period of
      the given offset that encompasses them.
  
      Parameters
      ----------
      first : pd.Period
          The beginning Period of the range to be adjusted.
      last : pd.Period
          The ending Period of the range to be adjusted.
      offset : pd.DateOffset
          The dateoffset to which the Periods will be adjusted.
      closed : {'right', 'left'}, default None
          Which side of bin interval is closed.
      base : int, default 0
          The "origin" of the adjusted Periods.
  
      Returns
      -------
      A tuple of length 2, containing the adjusted pd.Period objects.