<commit_before>"""Serve files directly from the ContentsManager."""

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import mimetypes
import json
import base64

from tornado import web

from IPython.html.base.handlers import IPythonHandler

class FilesHandler(IPythonHandler):
    """serve files via ContentsManager"""

    @web.authenticated
    def get(self, path):
        cm = self.contents_manager
        if cm.is_hidden(path):
            self.log.info("Refusing to serve hidden file, via 404 Error")
            raise web.HTTPError(404)
        
        path = path.strip('/')
        if '/' in path:
            _, name = path.rsplit('/', 1)
        else:
            name = path
        
        model = cm.get(path)
        
        if self.get_argument("download", False):
            self.set_header('Content-Disposition','attachment; filename="%s"' % name)
        
        if model['type'] == 'notebook':<commit_msg>Get /files/ unmodified from contents<commit_after>"""Serve files directly from the ContentsManager."""

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import mimetypes
import json
import base64

from tornado import web

from IPython.html.base.handlers import IPythonHandler

class FilesHandler(IPythonHandler):
    """serve files via ContentsManager"""

    @web.authenticated
    def get(self, path):
        cm = self.contents_manager
        if cm.is_hidden(path):
            self.log.info("Refusing to serve hidden file, via 404 Error")
            raise web.HTTPError(404)
        
        path = path.strip('/')
        if '/' in path:
            _, name = path.rsplit('/', 1)
        else:
            name = path
        
        model = cm.get(path, type='file')
        
        if self.get_argument("download", False):
            self.set_header('Content-Disposition','attachment; filename="%s"' % name)
        
        if model['type'] == 'notebook' or name.endswith('.ipynb'):
{'fraction_non_alphanumeric': 0.1100828056502679, 'fraction_numerical': 0.00876765708718948, 'mean_word_length': 2.457912457912458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '792113', 'n_tokens_mistral': 599, 'n_tokens_neox': 571, 'n_words': 170}