code: def set_margins(self, top=None, bottom=None):
          
          # XXX 0 corresponds to the CSI with no parameters.
          if (top is None or top == 0) and bottom is None:
              self.margins = None
              return
  
          margins = self.margins or Margins(0, self.lines - 1)
  
          # Arguments are 1-based, while :attr:`margins` are zero
          # based -- so we have to decrement them by one. We also
          # make sure that both of them is bounded by [0, lines - 1].
          if top is None:
              top = margins.top
          else:
              top = max(0, min(top - 1, self.lines - 1))
          if bottom is None:
              bottom = margins.bottom
          else:
              bottom = max(0, min(bottom - 1, self.lines - 1))
  
          # Even though VT102 and VT220 require DECSTBM to ignore
          # regions of width less than 2, some programs (like aptitude
          # for example) rely on it. Practicality beats purity.
          if bottom - top >= 1:
              self.margins = Margins(top, bottom)
  
              # The cursor moves to the home position when the top and
              # bottom margins of the scrolling region (DECSTBM) changes.
              self.cursor_position()
docs: Select top and bottom margins for the scrolling region.
  
          :param int top: the smallest line number that is scrolled.
          :param int bottom: the biggest line number that is scrolled.