def install_extension(self, url, filename=None):
        """Download and install an IPython extension. 
        
        If filename is given, the file will be so named (inside the extension
        directory). Otherwise, the name from the URL will be used. The file must
        have a .py or .zip extension; otherwise, a ValueError will be raised.
        
        Returns the full path to the installed file.
        """
        # Ensure the extension directory exists
        if not os.path.isdir(self.ipython_extension_dir):
            os.makedirs(self.ipython_extension_dir, mode = 0777)
        
        if os.path.isfile(url):
            src_filename = os.path.basename(url)
            copy = copyfile
        else:
            src_filename = urlparse(url).path.split('/')[-1]
            copy = urlretrieve
            
        if filename is None:
            filename = src_filename
        if os.path.splitext(filename)[1] not in ('.py', '.zip'):
            raise ValueError("The file must have a .py or .zip extension", filename)
        
        filename = os.path.join(self.ipython_extension_dir, filename)
        copy(url, filename)
        return filename
Download and install an IPython extension. 
        
        If filename is given, the file will be so named (inside the extension
        directory). Otherwise, the name from the URL will be used. The file must
        have a .py or .zip extension; otherwise, a ValueError will be raised.
        
        Returns the full path to the installed file.