<commit_before># -*- coding: iso8859-1 -*-
#
# Copyright (C) 2003, 2004 Edgewall Software
# Copyright (C) 2003, 2004 <NAME> <<EMAIL>>
#
# Trac is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Trac is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: <NAME> <<EMAIL>>
#
# FIXME:
# * We need to figure out the encoding used somehow.

import os
import sys
import time
import urllib

import svn

import perm
import util
import Module
from WikiFormatter import wiki_to_html

class FileCommon(Module.Module):
    CHUNK_SIZE = 4096
    DISP_MAX_FILE_SIZE = 256 * 1024

    filename = None
    rev = None
    mime_type = None

    def render(self, req):
        self.perm.assert_permission (perm.FILE_VIEW)

    def display(self, req):
        self.log.debug("Displaying file: %s  mime-type: %s" % (self.filename,
                                                               self.mime_type))
        # We don't have to guess if the charset is specified in the
        # svn:mime-type property
        ctpos = self.mime_type.find('charset=')
        if ctpos >= 0:
            charset = self.mime_type[ctpos + 8:]
            self.log.debug("Charset %s selected" % charset)
        else:
            charset = self.env.get_config('trac', 'default_charset', 'iso-8859-15')
        data = util.to_utf8(self.read_func(self.DISP_MAX_FILE_SIZE), charset)

        if len(data) == self.DISP_MAX_FILE_SIZE:
            req.hdf.setValue('file.max_file_size_reached', '1')
            req.hdf.setValue('file.max_file_size', str(self.DISP_MAX_FILE_SIZE))
            vdata = ' '
        else:
            vdata = self.env.mimeview.display(data, filename=self.filename,
                                              rev=self.rev,
                                              mimetype=self.mime_type)
        req.hdf.setValue('file.highlighted_html', vdata)
        req.display('file.cs')

    def display_raw(self, req):
        req.send_response(200)
        req.send_header('Content-Type', self.mime_type)
        req.send_header('Content-Length', str(self.length))
        req.send_header('Last-Modified',
                             time.strftime("%a, %d %b %Y %H:%M:%S GMT",
                                           self.last_modified))
        req.send_header('Pragma', 'no-cache')
        req.send_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT')
        req.send_header('Cache-Control',
                             'no-store, no-cache, must-revalidate, max-age=0')
        req.send_header('Cache-Control', 'post-check=0, pre-check=0')
        req.end_headers()
        i = 0
        while 1:
            data = self.read_func(self.CHUNK_SIZE)
            if not data:
                break
            req.write(data)
            i += self.CHUNK_SIZE

    def display_txt(self, req):
        self.mime_type = 'text/plain;charset=utf-8'
        self.display_raw(req)

class Attachment(FileCommon):

    def get_attachment_parent_link(self):<commit_msg>Don't send ''no-cache'' headers for repository files and attachments. The contents of attachments can't change anyway, and repository files have the revision identifier in the URL, so they can also be safely cached. This should fix downloading of files associated with external applications in IE/Win under SSL (#1020).<commit_after># -*- coding: iso8859-1 -*-
#
# Copyright (C) 2003, 2004 Edgewall Software
# Copyright (C) 2003, 2004 <NAME> <<EMAIL>>
#
# Trac is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Trac is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: <NAME> <<EMAIL>>
#
# FIXME:
# * We need to figure out the encoding used somehow.

import os
import sys
import time
import urllib

import svn

import perm
import util
import Module
from WikiFormatter import wiki_to_html

class FileCommon(Module.Module):
    CHUNK_SIZE = 4096
    DISP_MAX_FILE_SIZE = 256 * 1024

    filename = None
    rev = None
    mime_type = None

    def render(self, req):
        self.perm.assert_permission (perm.FILE_VIEW)

    def display(self, req):
        self.log.debug("Displaying file: %s  mime-type: %s" % (self.filename,
                                                               self.mime_type))
        # We don't have to guess if the charset is specified in the
        # svn:mime-type property
        ctpos = self.mime_type.find('charset=')
        if ctpos >= 0:
            charset = self.mime_type[ctpos + 8:]
            self.log.debug("Charset %s selected" % charset)
        else:
            charset = self.env.get_config('trac', 'default_charset', 'iso-8859-15')
        data = util.to_utf8(self.read_func(self.DISP_MAX_FILE_SIZE), charset)

        if len(data) == self.DISP_MAX_FILE_SIZE:
            req.hdf.setValue('file.max_file_size_reached', '1')
            req.hdf.setValue('file.max_file_size', str(self.DISP_MAX_FILE_SIZE))
            vdata = ' '
        else:
            vdata = self.env.mimeview.display(data, filename=self.filename,
                                              rev=self.rev,
                                              mimetype=self.mime_type)
        req.hdf.setValue('file.highlighted_html', vdata)
        req.display('file.cs')

    def display_raw(self, req):
        req.send_response(200)
        req.send_header('Content-Type', self.mime_type)
        req.send_header('Content-Length', str(self.length))
        req.send_header('Last-Modified',
                        time.strftime("%a, %d %b %Y %H:%M:%S GMT",
                                      self.last_modified))
        req.end_headers()
        i = 0
        while 1:
            data = self.read_func(self.CHUNK_SIZE)
            if not data:
                break
            req.write(data)
            i += self.CHUNK_SIZE

    def display_txt(self, req):
        self.mime_type = 'text/plain;charset=utf-8'
        self.display_raw(req)

class Attachment(FileCommon):

    def get_attachment_parent_link(self):
{'fraction_non_alphanumeric': 0.10014245014245014, 'fraction_numerical': 0.018945868945868947, 'mean_word_length': 2.3055555555555554, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5122633', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2011, 'n_words': 615}