This file is indexed.

/usr/lib/python3/dist-packages/zope/contenttype/tests/testContentTypes.py is in python3-zope.contenttype 4.1.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of the contenttypes extension mechanism.
"""
import unittest

class ContentTypesTestCase(unittest.TestCase):

    def setUp(self):
        import mimetypes
        mimetypes.init()
        self._old_state = mimetypes.__dict__.copy()

    def tearDown(self):
        import mimetypes
        mimetypes.__dict__.clear()
        mimetypes.__dict__.update(self._old_state)

    def _check_types_count(self, delta):
        import mimetypes
        self.assertEqual(len(mimetypes.types_map),
                         len(self._old_state["types_map"]) + delta)

    def _getFilename(self, name):
        import os.path
        here = os.path.dirname(os.path.abspath(__file__))
        return os.path.join(here, name)

    def test_main(self):
        import zope.contenttype
        _print = zope.contenttype._print
        zope.contenttype._print = lambda s: None
        zope.contenttype.main()
        zope.contenttype._print = _print

    def test_guess_content_type(self):
        from zope.contenttype import add_files
        from zope.contenttype import guess_content_type
        filename = self._getFilename('mime.types-1')
        add_files([filename])
        ctype, encoding = guess_content_type(body=b'text file')
        self.assertEqual(ctype, "text/plain")
        ctype, encoding = guess_content_type(body=b'\001binary')
        self.assertEqual(ctype, "application/octet-stream")
        ctype, encoding = guess_content_type()
        self.assertEqual(ctype, "text/x-unknown-content-type")


    def test_add_one_file(self):
        from zope.contenttype import add_files
        from zope.contenttype import guess_content_type
        filename = self._getFilename('mime.types-1')
        add_files([filename])
        ctype, encoding = guess_content_type("foo.ztmt-1")
        self.assertTrue(encoding is None)
        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
        ctype, encoding = guess_content_type("foo.ztmt-1.gz")
        self.assertEqual(encoding, "gzip")
        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
        self._check_types_count(1)

    def test_add_two_files(self):
        from zope.contenttype import add_files
        from zope.contenttype import guess_content_type
        filename1 = self._getFilename('mime.types-1')
        filename2 = self._getFilename('mime.types-2')
        add_files([filename1, filename2])
        ctype, encoding = guess_content_type("foo.ztmt-1")
        self.assertTrue(encoding is None)
        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
        ctype, encoding = guess_content_type("foo.ztmt-2")
        self.assertTrue(encoding is None)
        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-2")
        self._check_types_count(2)

    def test_text_type(self):
        HTML = b'<HtmL><body>hello world</body></html>'
        from zope.contenttype import text_type
        self.assertEqual(text_type(HTML),
                         'text/html')
        self.assertEqual(text_type(b'<?xml version="1.0"><foo/>'),
                         'text/xml')
        self.assertEqual(text_type(b'<?XML version="1.0"><foo/>'),
                         'text/xml')
        self.assertEqual(text_type(b'foo bar'),
                         'text/plain')
        self.assertEqual(text_type(b'<!DOCTYPE HTML PUBLIC '
                                   b'"-//W3C//DTD HTML 4.01 Transitional//EN" '
                                   b'"http://www.w3.org/TR/html4/loose.dtd">'),
                         'text/html')
        self.assertEqual(text_type(b'\n\n<!DOCTYPE html>\n'), 'text/html')
        # we can also parse text snippets
        self.assertEqual(text_type(b'<p>Hello</p>'), 'text/html')
        longtext = b'abc ' * 100
        self.assertEqual(text_type(b'<p>' + longtext + b'</p>'), 'text/html')
        # See https://bugs.launchpad.net/bugs/487998
        self.assertEqual(text_type(b' ' * 14 + HTML),
                         'text/html')
        self.assertEqual(text_type(b' ' * 14 + b'abc'),
                         'text/plain')
        self.assertEqual(text_type(b' ' * 14),
                         'text/plain')


def test_suite():
    return unittest.makeSuite(ContentTypesTestCase)