<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def location(self, x=None, y=None):
        ''' Temporarily move the cursor, perform work, and return to the
            previous location.

            ::

                with screen.location(40, 20):
                    print('Hello, world!')
        '''
        stream = self._stream
        stream.write(self.save_pos)  # cursor position

        if x is not None and y is not None:
            stream.write(self.mv(y, x))
        elif x is not None:
            stream.write(self.mv_x(x))
        elif y is not None:
            stream.write(self.mv_y(y))

        stream.flush()
        try:
            yield self
        finally:
            stream.write(self.rest_pos)
            stream.flush()