[Zope-Checkins] SVN: Zope/branches/2.9/ deprecated OFS.content_types

Andreas Jung andreas at andreas-jung.com
Fri Dec 23 23:55:15 EST 2005


Log message for revision 41015:
  deprecated OFS.content_types
  

Changed:
  U   Zope/branches/2.9/doc/CHANGES.txt
  U   Zope/branches/2.9/lib/python/OFS/content_types.py
  D   Zope/branches/2.9/lib/python/OFS/tests/testContentTypes.py

-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt	2005-12-23 23:29:55 UTC (rev 41014)
+++ Zope/branches/2.9/doc/CHANGES.txt	2005-12-24 04:55:14 UTC (rev 41015)
@@ -22,7 +22,12 @@
 
    - Collector #1233: port ZOPE_CONFIG patch from Zope 2.7 to Zope 2.8
 
+  after Zope 2.9.0 beta 2 
 
+    Bugs fixed
+
+      - deprecated OFS.content_types
+
   Zope 2.9.0 beta 2 (2005/12/24)
 
     Bugs fixed

Modified: Zope/branches/2.9/lib/python/OFS/content_types.py
===================================================================
--- Zope/branches/2.9/lib/python/OFS/content_types.py	2005-12-23 23:29:55 UTC (rev 41014)
+++ Zope/branches/2.9/lib/python/OFS/content_types.py	2005-12-24 04:55:14 UTC (rev 41015)
@@ -14,62 +14,11 @@
 
 $Id$
 """
-import mimetypes
-import os.path
-import re
 
+import warnings
+warnings.warn('Using OFS.content_types is deprecated (will be removed in Zope '
+              '2.11). Instead use zope.app.contenttypes.', 
+              DeprecationWarning,
+              stacklevel=2) 
 
-find_binary = re.compile('[\0-\7]').search
-
-def text_type(s):
-    # Yuk. See if we can figure out the type by content.
-    if (s.strip().lower()[:6] == '<html>' or s.find('</') > 0):
-        return 'text/html'
-
-    elif s.strip().startswith('<?xml'):
-        return 'text/xml'
-
-    else:
-        return 'text/plain'
-
-
-def guess_content_type(name='', body='', default=None):
-    # Attempt to determine the content type (and possibly
-    # content-encoding) based on an an object's name and
-    # entity body.
-    type, enc = mimetypes.guess_type(name)
-    if type is None:
-        if body:
-            if find_binary(body) is not None:
-                type = default or 'application/octet-stream'
-            else:
-                type = (default or text_type(body)
-                        or 'text/x-unknown-content-type')
-        else:
-            type = default or 'text/x-unknown-content-type'
-
-    return type.lower(), enc and enc.lower() or None
-
-
-def add_files(filenames):
-    # Make sure the additional files are either loaded or scheduled to
-    # be loaded:
-    if mimetypes.inited:
-        # Re-initialize the mimetypes module, loading additional files
-        mimetypes.init(filenames)
-    else:
-        # Tell the mimetypes module about the additional files so
-        # when it is initialized, it will pick up all of them, in
-        # the right order.
-        mimetypes.knownfiles.extend(filenames)
-
-
-# Provide definitions shipped as part of Zope:
-here = os.path.dirname(os.path.abspath(__file__))
-add_files([os.path.join(here, "mime.types")])
-
-
-if __name__ == '__main__':
-    items = mimetypes.types_map.items()
-    items.sort()
-    for item in items: print "%s:\t%s" % item
+from zope.app.content_types import text_type, guess_content_type, add_files

Deleted: Zope/branches/2.9/lib/python/OFS/tests/testContentTypes.py
===================================================================
--- Zope/branches/2.9/lib/python/OFS/tests/testContentTypes.py	2005-12-23 23:29:55 UTC (rev 41014)
+++ Zope/branches/2.9/lib/python/OFS/tests/testContentTypes.py	2005-12-24 04:55:14 UTC (rev 41015)
@@ -1,75 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation 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 content_types extension mechanism.
-
-$Id$
-"""
-
-import mimetypes
-import os.path
-import sys
-import unittest
-
-from OFS import content_types
-
-try:
-    __file__
-except NameError:
-    __file__ = os.path.realpath(sys.argv[0])
-
-here = os.path.dirname(os.path.abspath(__file__))
-MIME_TYPES_1 = os.path.join(here, "mime.types-1")
-MIME_TYPES_2 = MIME_TYPES_1[:-1] + "2"
-
-
-class ContentTypesTestCase(unittest.TestCase):
-
-    def setUp(self):
-        self._old_state = mimetypes.__dict__.copy()
-
-    def tearDown(self):
-        mimetypes.__dict__.update(self._old_state)
-
-    def check_types_count(self, delta):
-        self.assertEqual(len(mimetypes.types_map),
-                         len(self._old_state["types_map"]) + delta)
-
-    def test_add_one_file(self):
-        ntypes = len(mimetypes.types_map)
-        content_types.add_files([MIME_TYPES_1])
-        ctype, encoding = content_types.guess_content_type("foo.ztmt-1")
-        self.assert_(encoding is None)
-        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
-        ctype, encoding = content_types.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):
-        ntypes = len(mimetypes.types_map)
-        content_types.add_files([MIME_TYPES_1, MIME_TYPES_2])
-        ctype, encoding = content_types.guess_content_type("foo.ztmt-1")
-        self.assert_(encoding is None)
-        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
-        ctype, encoding = content_types.guess_content_type("foo.ztmt-2")
-        self.assert_(encoding is None)
-        self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-2")
-        self.check_types_count(2)
-
-
-def test_suite():
-    return unittest.makeSuite(ContentTypesTestCase)
-
-if __name__ == '__main__':
-    unittest.main()



More information about the Zope-Checkins mailing list