<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save(self, filename, format=None):
 """ Save the SFrame to a file system for later use. Parameters filename : string The location to save the SFrame. Either a local directory or a remote URL. If the format is 'binary', a directory will be created at the location which will contain the sframe. format : {'binary', 'csv', 'json'}, optional Format in which to save the SFrame. Binary saved SFrames can be loaded much faster and without any format conversion losses. If not given, will try to infer the format from filename given. If file name ends with 'csv' or '.csv.gz', then save as 'csv' format, otherwise save as 'binary' format. See export_csv for more csv saving options. See Also -------- load_sframe, SFrame Examples -------- """


        if format is None:
            if filename.endswith(('.csv', '.csv.gz')):
                format = 'csv'
            elif filename.endswith(('.json')):
                format = 'json'
            else:
                format = 'binary'
        else:
            if format is 'csv':
                if not filename.endswith(('.csv', '.csv.gz')):
                    filename = filename + '.csv'
            elif format is not 'binary' and format is not 'json':
                raise ValueError("Invalid format: {}. Supported formats are 'csv' and 'binary' and 'json'".format(format))

        ## Save the SFrame
        url = _make_internal_url(filename)

        with cython_context():
            if format is 'binary':
                self.__proxy__.save(url)
            elif format is 'csv':
                assert filename.endswith(('.csv', '.csv.gz'))
                self.__proxy__.save_as_csv(url, {})
            elif format is 'json':
                self.export_json(url)
            else:
                raise ValueError("Unsupported format: {}".format(format))