zope.contenttype-4.1.0/0000775000175000017500000000000012447344143016220 5ustar tseavertseaver00000000000000zope.contenttype-4.1.0/setup.cfg0000664000175000017500000000007312447344143020041 0ustar tseavertseaver00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 zope.contenttype-4.1.0/buildout.cfg0000664000175000017500000000022712447264526020537 0ustar tseavertseaver00000000000000[buildout] develop = . parts = test find-links = http://download.zope.org/distribution/ [test] recipe = zc.recipe.testrunner eggs = zope.contenttype zope.contenttype-4.1.0/PKG-INFO0000664000175000017500000000751612447344143017326 0ustar tseavertseaver00000000000000Metadata-Version: 1.1 Name: zope.contenttype Version: 4.1.0 Summary: Zope contenttype Home-page: http://pypi.python.org/pypi/zope.contenttype Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: ``zope.contenttype`` ==================== .. image:: https://travis-ci.org/zopefoundation/zope.contenttype.png?branch=master :target: https://travis-ci.org/zopefoundation/zope.contenttype A utility module for content-type handling. Change History ============== 4.1.0 (2014-12-26) ------------------ - Add support for Python 3.4 and PyPy3. - Add support for testing on Travis. 4.0.1 (2013-02-20) ------------------ - Change the file contents argument of ``guess_content_type`` from string to bytes. This change has no effect on Python 2. 4.0.0 (2013-02-11) ------------------ - Add some tests for better coverage. - Add ``tox.ini`` and manifest. - Add support for Python 3.3 and PyPy. - Drop support for Python 2.4 and 2.5. 3.5.5 (2011-07-27) ------------------ - Properly restore the HTML snippet detection, by looking at the entire string and not just its start. 3.5.4 (2011-07-26) ------------------ - Restore detection of HTML snippets from 3.4 series. 3.5.3 (2011-03-18) ------------------ - Add new mime types for web fonts, cache manifest and new media formats. 3.5.2 (2011-02-11) ------------------ - LP #717289: add ``video/x-m4v`` mimetype for the ``.m4v`` extension. 3.5.1 (2010-03-23) ------------------ - LP #242321: fix IndexError raised when testing strings consisting solely of leading whitespace. 3.5.0 (2009-10-22) ------------------ - Move the implementation of ``zope.publisher.contenttype`` to ``zope.contenttype.parse``, moved tests along. 3.4.3 (2009-12-28) ------------------ - Update mime-type for ``.js`` to be application/javascript. 3.4.2 (2009-05-28) ------------------ - Add MS Office 12 types based on: http://www.therightstuff.de/2006/12/16/Office+2007+File+Icons+For+Windows+SharePoint+Services+20+And+SharePoint+Portal+Server+2003.aspx 3.4.1 (2009-02-04) ------------------ - Improve ``text_type()``. Based on the patch from http://www.zope.org/Collectors/Zope/2355/ - Add missing ``setuptools`` dependency to setup.py. - Add reference documentation. 3.4.0 (2007-09-13) ------------------ - First stable release as an independent package. Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Topic :: Software Development zope.contenttype-4.1.0/tox.ini0000664000175000017500000000111412447343723017533 0ustar tseavertseaver00000000000000[tox] envlist = py26,py27,py33,py34,pypy,pypy3 [testenv] commands = python setup.py test -q # without explicit deps, setup.py test will download a bunch of eggs into $PWD deps = [testenv:coverage] basepython = python2.7 commands = # The installed version messes up nose's test discovery / coverage reporting # So, we uninstall that from the environment, and then install the editable # version, before running nosetests. pip uninstall -y zope.contenttype pip install -e . nosetests --with-xunit --with-xcoverage deps = nose coverage nosexcover zope.contenttype-4.1.0/.gitignore0000664000175000017500000000002712447343577020221 0ustar tseavertseaver00000000000000*.egg-info *.pyc .tox/ zope.contenttype-4.1.0/setup.py0000664000175000017500000000476312447344114017742 0ustar tseavertseaver00000000000000############################################################################## # # Copyright (c) 2006 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. # ############################################################################## # This package is developed by the Zope Toolkit project, documented here: # http://docs.zope.org/zopetoolkit # When developing and releasing this package, please follow the documented # Zope Toolkit policies as described by this documentation. ############################################################################## """Setup for zope.contenttype package """ import os from setuptools import setup, find_packages def read(*rnames): with open(os.path.join(os.path.dirname(__file__), *rnames)) as f: return f.read() long_description = read('README.rst') + '\n' + read('CHANGES.rst') setup( name='zope.contenttype', version='4.1.0', url='http://pypi.python.org/pypi/zope.contenttype', author='Zope Foundation and Contributors', author_email='zope-dev@zope.org', license='ZPL 2.1', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: Zope Public License', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Operating System :: OS Independent', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Software Development', ], description='Zope contenttype', long_description=long_description, packages=find_packages('src'), package_dir={'': 'src'}, namespace_packages=['zope',], install_requires=['setuptools'], test_suite='zope.contenttype', include_package_data=True, zip_safe=False, ) zope.contenttype-4.1.0/bootstrap.py0000664000175000017500000001454512447264526020626 0ustar tseavertseaver00000000000000############################################################################## # # Copyright (c) 2006 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. # ############################################################################## """Bootstrap a buildout-based project Simply run this script in a directory containing a buildout.cfg. The script accepts buildout command-line options, so you can use the -c option to specify an alternate configuration file. """ import os import shutil import sys import tempfile from optparse import OptionParser tmpeggs = tempfile.mkdtemp() usage = '''\ [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] Bootstraps a buildout-based project. Simply run this script in a directory containing a buildout.cfg, using the Python that you want bin/buildout to use. Note that by using --find-links to point to local resources, you can keep this script from going over the network. ''' parser = OptionParser(usage=usage) parser.add_option("-v", "--version", help="use a specific zc.buildout version") parser.add_option("-t", "--accept-buildout-test-releases", dest='accept_buildout_test_releases', action="store_true", default=False, help=("Normally, if you do not specify a --version, the " "bootstrap script and buildout gets the newest " "*final* versions of zc.buildout and its recipes and " "extensions for you. If you use this flag, " "bootstrap and buildout will get the newest releases " "even if they are alphas or betas.")) parser.add_option("-c", "--config-file", help=("Specify the path to the buildout configuration " "file to be used.")) parser.add_option("-f", "--find-links", help=("Specify a URL to search for buildout releases")) parser.add_option("--allow-site-packages", action="store_true", default=False, help=("Let bootstrap.py use existing site packages")) parser.add_option("--setuptools-version", help="use a specific setuptools version") options, args = parser.parse_args() ###################################################################### # load/install setuptools try: if options.allow_site_packages: import setuptools import pkg_resources from urllib.request import urlopen except ImportError: from urllib2 import urlopen ez = {} exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) if not options.allow_site_packages: # ez_setup imports site, which adds site packages # this will remove them from the path to ensure that incompatible versions # of setuptools are not in the path import site # inside a virtualenv, there is no 'getsitepackages'. # We can't remove these reliably if hasattr(site, 'getsitepackages'): for sitepackage_path in site.getsitepackages(): sys.path[:] = [x for x in sys.path if sitepackage_path not in x] setup_args = dict(to_dir=tmpeggs, download_delay=0) if options.setuptools_version is not None: setup_args['version'] = options.setuptools_version ez['use_setuptools'](**setup_args) import setuptools import pkg_resources # This does not (always?) update the default working set. We will # do it. for path in sys.path: if path not in pkg_resources.working_set.entries: pkg_resources.working_set.add_entry(path) ###################################################################### # Install buildout ws = pkg_resources.working_set cmd = [sys.executable, '-c', 'from setuptools.command.easy_install import main; main()', '-mZqNxd', tmpeggs] find_links = os.environ.get( 'bootstrap-testing-find-links', options.find_links or ('http://downloads.buildout.org/' if options.accept_buildout_test_releases else None) ) if find_links: cmd.extend(['-f', find_links]) setuptools_path = ws.find( pkg_resources.Requirement.parse('setuptools')).location requirement = 'zc.buildout' version = options.version if version is None and not options.accept_buildout_test_releases: # Figure out the most recent final version of zc.buildout. import setuptools.package_index _final_parts = '*final-', '*final' def _final_version(parsed_version): try: return not parsed_version.is_prerelease except AttributeError: # Older setuptools for part in parsed_version: if (part[:1] == '*') and (part not in _final_parts): return False return True index = setuptools.package_index.PackageIndex( search_path=[setuptools_path]) if find_links: index.add_find_links((find_links,)) req = pkg_resources.Requirement.parse(requirement) if index.obtain(req) is not None: best = [] bestv = None for dist in index[req.project_name]: distv = dist.parsed_version if _final_version(distv): if bestv is None or distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) if best: best.sort() version = best[-1].version if version: requirement = '=='.join((requirement, version)) cmd.append(requirement) import subprocess if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0: raise Exception( "Failed to execute command:\n%s" % repr(cmd)[1:-1]) ###################################################################### # Import and run buildout ws.add_entry(tmpeggs) ws.require(requirement) import zc.buildout.buildout if not [a for a in args if '=' not in a]: args.append('bootstrap') # if -c was provided, we push it back into args for buildout' main function if options.config_file is not None: args[0:0] = ['-c', options.config_file] zc.buildout.buildout.main(args) shutil.rmtree(tmpeggs) zope.contenttype-4.1.0/.travis.yml0000664000175000017500000000030712447343750020334 0ustar tseavertseaver00000000000000language: python sudo: false python: - 2.6 - 2.7 - 3.3 - 3.4 - pypy - pypy3 install: - pip install . script: - python setup.py test -q notifications: email: false zope.contenttype-4.1.0/src/0000775000175000017500000000000012447344143017007 5ustar tseavertseaver00000000000000zope.contenttype-4.1.0/src/zope.contenttype.egg-info/0000775000175000017500000000000012447344143024031 5ustar tseavertseaver00000000000000zope.contenttype-4.1.0/src/zope.contenttype.egg-info/top_level.txt0000664000175000017500000000000512447344142026555 0ustar tseavertseaver00000000000000zope zope.contenttype-4.1.0/src/zope.contenttype.egg-info/SOURCES.txt0000664000175000017500000000137412447344143025722 0ustar tseavertseaver00000000000000.gitignore .travis.yml CHANGES.rst COPYRIGHT.txt LICENSE.txt MANIFEST.in README.rst bootstrap.py buildout.cfg setup.py tox.ini src/zope/__init__.py src/zope.contenttype.egg-info/PKG-INFO src/zope.contenttype.egg-info/SOURCES.txt src/zope.contenttype.egg-info/dependency_links.txt src/zope.contenttype.egg-info/namespace_packages.txt src/zope.contenttype.egg-info/not-zip-safe src/zope.contenttype.egg-info/requires.txt src/zope.contenttype.egg-info/top_level.txt src/zope/contenttype/__init__.py src/zope/contenttype/mime.types src/zope/contenttype/parse.py src/zope/contenttype/tests/__init__.py src/zope/contenttype/tests/mime.types-1 src/zope/contenttype/tests/mime.types-2 src/zope/contenttype/tests/testContentTypes.py src/zope/contenttype/tests/test_parse.pyzope.contenttype-4.1.0/src/zope.contenttype.egg-info/PKG-INFO0000664000175000017500000000751612447344142025136 0ustar tseavertseaver00000000000000Metadata-Version: 1.1 Name: zope.contenttype Version: 4.1.0 Summary: Zope contenttype Home-page: http://pypi.python.org/pypi/zope.contenttype Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: ``zope.contenttype`` ==================== .. image:: https://travis-ci.org/zopefoundation/zope.contenttype.png?branch=master :target: https://travis-ci.org/zopefoundation/zope.contenttype A utility module for content-type handling. Change History ============== 4.1.0 (2014-12-26) ------------------ - Add support for Python 3.4 and PyPy3. - Add support for testing on Travis. 4.0.1 (2013-02-20) ------------------ - Change the file contents argument of ``guess_content_type`` from string to bytes. This change has no effect on Python 2. 4.0.0 (2013-02-11) ------------------ - Add some tests for better coverage. - Add ``tox.ini`` and manifest. - Add support for Python 3.3 and PyPy. - Drop support for Python 2.4 and 2.5. 3.5.5 (2011-07-27) ------------------ - Properly restore the HTML snippet detection, by looking at the entire string and not just its start. 3.5.4 (2011-07-26) ------------------ - Restore detection of HTML snippets from 3.4 series. 3.5.3 (2011-03-18) ------------------ - Add new mime types for web fonts, cache manifest and new media formats. 3.5.2 (2011-02-11) ------------------ - LP #717289: add ``video/x-m4v`` mimetype for the ``.m4v`` extension. 3.5.1 (2010-03-23) ------------------ - LP #242321: fix IndexError raised when testing strings consisting solely of leading whitespace. 3.5.0 (2009-10-22) ------------------ - Move the implementation of ``zope.publisher.contenttype`` to ``zope.contenttype.parse``, moved tests along. 3.4.3 (2009-12-28) ------------------ - Update mime-type for ``.js`` to be application/javascript. 3.4.2 (2009-05-28) ------------------ - Add MS Office 12 types based on: http://www.therightstuff.de/2006/12/16/Office+2007+File+Icons+For+Windows+SharePoint+Services+20+And+SharePoint+Portal+Server+2003.aspx 3.4.1 (2009-02-04) ------------------ - Improve ``text_type()``. Based on the patch from http://www.zope.org/Collectors/Zope/2355/ - Add missing ``setuptools`` dependency to setup.py. - Add reference documentation. 3.4.0 (2007-09-13) ------------------ - First stable release as an independent package. Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Topic :: Software Development zope.contenttype-4.1.0/src/zope.contenttype.egg-info/dependency_links.txt0000664000175000017500000000000112447344142030076 0ustar tseavertseaver00000000000000 zope.contenttype-4.1.0/src/zope.contenttype.egg-info/not-zip-safe0000664000175000017500000000000112447264774026272 0ustar tseavertseaver00000000000000 zope.contenttype-4.1.0/src/zope.contenttype.egg-info/namespace_packages.txt0000664000175000017500000000000512447344142030356 0ustar tseavertseaver00000000000000zope zope.contenttype-4.1.0/src/zope.contenttype.egg-info/requires.txt0000664000175000017500000000001312447344142026422 0ustar tseavertseaver00000000000000setuptools zope.contenttype-4.1.0/src/zope/0000775000175000017500000000000012447344143017764 5ustar tseavertseaver00000000000000zope.contenttype-4.1.0/src/zope/contenttype/0000775000175000017500000000000012447344143022340 5ustar tseavertseaver00000000000000zope.contenttype-4.1.0/src/zope/contenttype/__init__.py0000664000175000017500000000747312447264526024472 0ustar tseavertseaver00000000000000############################################################################## # # Copyright (c) 2003 Zope Foundation and Contributors. # # 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 # ############################################################################## """A utility module for content-type handling. """ import re import os.path import mimetypes find_binary = re.compile(b'[\0-\7]').search def text_type(s): """Given an unnamed piece of text, try to guess its content type. Detects HTML, XML, and plain text. Returns a MIME type string such as 'text/html'. """ # at least the maximum length of any tags we look for max_tags = 14 s2 = s.strip()[:max_tags].lower() if len(s2) == max_tags: if s2.startswith(b''): return 'text/html' if s2.startswith(b'hello world' from zope.contenttype import text_type self.assertEqual(text_type(HTML), 'text/html') self.assertEqual(text_type(b''), 'text/xml') self.assertEqual(text_type(b''), 'text/xml') self.assertEqual(text_type(b'foo bar'), 'text/plain') self.assertEqual(text_type(b''), 'text/html') self.assertEqual(text_type(b'\n\n\n'), 'text/html') # we can also parse text snippets self.assertEqual(text_type(b'

Hello

'), 'text/html') longtext = b'abc ' * 100 self.assertEqual(text_type(b'

' + longtext + b'

'), '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) zope.contenttype-4.1.0/src/zope/contenttype/tests/mime.types-10000664000175000017500000000031312447264526025660 0ustar tseavertseaver00000000000000# This is a sample mime.types file. # It contains a single bogus MIME type and extention for testing # purposes. It is not loaded during normal Zope operation. text/x-vnd.zope.test-mime-type-1 ztmt-1 zope.contenttype-4.1.0/src/zope/contenttype/tests/test_parse.py0000664000175000017500000002056512447264526026243 0ustar tseavertseaver00000000000000############################################################################## # # Copyright (c) 2001, 2002 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 contenttype helpers. """ import unittest class ParseOrderedTestCase(unittest.TestCase): empty_params = [] def setUp(self): from zope.contenttype import parse self.parse = parse.parseOrdered def _callFUT(self, *args, **kw): from zope.contenttype.parse import parseOrdered return parseOrdered(*args, **kw) def oneParam(self, name, value): return [(name, value)] def test_without_params(self): self.assertEqual(self._callFUT("text/plain"), ("text", "plain", self.empty_params)) self.assertEqual(self._callFUT("TEXT/PLAIN"), ("text", "plain", self.empty_params)) self.assertEqual(self._callFUT("TeXt / PlaIN"), ("text", "plain", self.empty_params)) self.assertEqual(self._callFUT("text / vnd.wap.wml"), ("text", "vnd.wap.wml", self.empty_params)) def test_with_empty_params(self): self.assertEqual(self._callFUT("text/plain ; "), ("text", "plain", self.empty_params)) self.assertEqual(self._callFUT("TEXT/PLAIN ; "), ("text", "plain", self.empty_params)) self.assertEqual(self._callFUT("TeXt / PlaIN ; "), ("text", "plain", self.empty_params)) def test_bad_tokens(self): self.assertRaises(ValueError, self._callFUT, "text stuff/plain") self.assertRaises(ValueError, self._callFUT, "text/plain stuff") self.assertRaises(ValueError, self._callFUT, "text/plain;some stuff=foo") self.assertRaises(ValueError, self._callFUT, "text/plain;a=b;c d=e") def test_missing_parts(self): self.assertRaises(ValueError, self._callFUT, "text ; params") self.assertRaises(ValueError, self._callFUT, "text/ ; params") self.assertRaises(ValueError, self._callFUT, "/plain ; params") self.assertRaises(ValueError, self._callFUT, "text/plain ; params") self.assertRaises(ValueError, self._callFUT, "text/plain ; params=") self.assertRaises(ValueError, self._callFUT, "text/plain ; =params") self.assertRaises(ValueError, self._callFUT, "text/plain ; a=b; params") self.assertRaises(ValueError, self._callFUT, "text/plain ; a=b; params=") self.assertRaises(ValueError, self._callFUT, "text/plain ; a=b; =params") def test_single_parameter(self): self.assertEqual(self._callFUT("text/plain;charset=UTF-8"), ("text", "plain", self.oneParam("charset", "UTF-8"))) self.assertEqual(self._callFUT("text/plain ;\tcharset = UTF-8"), ("text", "plain", self.oneParam("charset", "UTF-8"))) # quoted-string parameter values self.assertEqual(self._callFUT('text/plain;charset="UTF-8"'), ("text", "plain", self.oneParam("charset", "UTF-8"))) self.assertEqual(self._callFUT('text/plain ;\tcharset = "UTF-8"'), ("text", "plain", self.oneParam("charset", "UTF-8"))) def test_multiple_parameters(self): self.assertEqual( self._callFUT("text/plain;charset=utf-8;format=flowed"), ("text", "plain", [("charset", "utf-8"), ("format", "flowed")])) self.assertEqual( self._callFUT('text/plain;charset=utf-8;format="flowed"'), ("text", "plain", [("charset", "utf-8"), ("format", "flowed")])) def test_quoted_strings(self): p = self.oneParam("c", " This [] has <> ? other () chars\t") self.assertEqual( self._callFUT('a/b;c= " This [] has <> ? other () chars\t" '), ("a", "b", p)) self.assertEqual( self._callFUT('a/b;c=""'), ("a", "b", self.oneParam("c", ""))) self.assertEqual( self._callFUT(r'a/b;c="\\\""'), ("a", "b", self.oneParam("c", r'\"'))) class ParseTestCase(ParseOrderedTestCase): empty_params = {} def _callFUT(self, *args, **kw): from zope.contenttype.parse import parse return parse(*args, **kw) def oneParam(self, name, value): return {name: value} def test_multiple_parameters(self): self.assertEqual( self._callFUT("text/plain;charset=utf-8;format=flowed"), ("text", "plain", {"charset": "utf-8", "format": "flowed"})) self.assertEqual( self._callFUT('text/plain;charset=utf-8;format="flowed"'), ("text", "plain", {"charset": "utf-8", "format": "flowed"})) class JoinTestCase(unittest.TestCase): def _callFUT(self, *args, **kw): from zope.contenttype.parse import join return join(*args, **kw) def test_without_params(self): self.assertEqual(self._callFUT(("text", "plain", [])), "text/plain") self.assertEqual(self._callFUT(("text", "plain", {})), "text/plain") def test_single_token_param(self): self.assertEqual( self._callFUT(("text", "plain", [("charset", "UTF-8")])), "text/plain;charset=UTF-8") self.assertEqual( self._callFUT(("text", "plain", {"charset": "UTF-8"})), "text/plain;charset=UTF-8") def test_multi_params_list_maintains_order(self): # multiple parameters given as a list maintain order: self.assertEqual( self._callFUT(("text", "plain", [("charset", "UTF-8"), ("format", "flowed")])), "text/plain;charset=UTF-8;format=flowed") self.assertEqual( self._callFUT(("text", "plain", [("format", "flowed"), ("charset", "UTF-8")])), "text/plain;format=flowed;charset=UTF-8") def test_multi_params_dict_sorted_order(self): # multiple parameters given as a dict are sorted by param name: self.assertEqual( self._callFUT(("text", "plain", {"charset": "UTF-8", "format": "flowed"})), "text/plain;charset=UTF-8;format=flowed") def test_params_list_quoted(self): # parameter values are quoted automatically: self.assertEqual(self._callFUT(("a", "b", [("c", "")])), 'a/b;c=""') self.assertEqual(self._callFUT(("a", "b", [("c", "ab cd")])), 'a/b;c="ab cd"') self.assertEqual(self._callFUT(("a", "b", [("c", " \t")])), 'a/b;c=" \t"') self.assertEqual(self._callFUT(("a", "b", [("c", '"')])), r'a/b;c="\""') self.assertEqual(self._callFUT(("a", "b", [("c", "\n")])), 'a/b;c="\\\n"') def test_params_dict_quoted(self): # parameter values are quoted automatically: self.assertEqual(self._callFUT(("a", "b", {"c": ""})), 'a/b;c=""') self.assertEqual(self._callFUT(("a", "b", {"c": "ab cd"})), 'a/b;c="ab cd"') self.assertEqual(self._callFUT(("a", "b", {"c": " \t"})), 'a/b;c=" \t"') self.assertEqual(self._callFUT(("a", "b", {"c": '"'})), r'a/b;c="\""') self.assertEqual(self._callFUT(("a", "b", {"c": "\n"})), 'a/b;c="\\\n"') def test_suite(): return unittest.TestSuite(( unittest.makeSuite(ParseOrderedTestCase), unittest.makeSuite(ParseTestCase), unittest.makeSuite(JoinTestCase), )) zope.contenttype-4.1.0/src/zope/contenttype/tests/__init__.py0000664000175000017500000000000012447264526025607 0ustar tseavertseaver00000000000000zope.contenttype-4.1.0/src/zope/contenttype/tests/mime.types-20000664000175000017500000000031312447264526025661 0ustar tseavertseaver00000000000000# This is a sample mime.types file. # It contains a single bogus MIME type and extention for testing # purposes. It is not loaded during normal Zope operation. text/x-vnd.zope.test-mime-type-2 ztmt-2 zope.contenttype-4.1.0/src/zope/contenttype/mime.types0000664000175000017500000000500112447264526024357 0ustar tseavertseaver00000000000000application-x-cdf cdf application/msword doc dot wiz application/pdf pdf application/pkcs7-mime p7c application/vnd.mozilla.xul+xml xul application/vnd.ms-excel xlb xls application/vnd.ms-fontobject eot application/vnd.ms-powerpoint pot ppa pps ppt pwz application/javascript js application/x-font-woff woff application/x-pkcs12 p12 pfx application/x-pn-realaudio ram audio/mpeg mp3 audio/x-pn-realaudio ra font/opentype otf font/truetype ttf image/pict pct pic pict image/svg+xml svg svgz image/vnd.microsoft.icon ico image/webp webp message/rfc822 eml nws mht mhtml text/cache-manifest manifest text/css css text/plain bat c h pl ksh text/x-vcard vcf text/xml xml xsl video/mp4 mp4 video/ogg ogv video/mpeg m1v mpa video/webm webm video/x-m4v m4v application/vnd.ms-word.document.macroEnabled.12 docm application/vnd.openxmlformats-officedocument.wordprocessingml.document docx application/vnd.ms-word.template.macroEnabled.12 dotm application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx application/vnd.ms-powerpoint.template.macroEnabled.12 potm application/vnd.openxmlformats-officedocument.presentationml.template potx application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm application/vnd.openxmlformats-officedocument.presentationml.presentation pptx application/vnd.ms-excel.addin.macroEnabled.12 xlam application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb application/vnd.ms-excel.sheet.macroEnabled.12 xlsm application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx application/vnd.ms-excel.template.macroEnabled.12 xltm application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx zope.contenttype-4.1.0/src/zope/contenttype/parse.py0000664000175000017500000000774212447264526024044 0ustar tseavertseaver00000000000000############################################################################## # # Copyright (c) 2001, 2002 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. # ############################################################################## """MIME Content-Type parsing helper functions. This supports parsing RFC 1341 Content-Type values, including quoted-string values as defined in RFC 822. """ __docformat__ = "reStructuredText" import re # TODO: This still needs to support comments in structured fields as # specified in RFC 2822. def parse(string): major, minor, params = parseOrdered(string) d = {} for (name, value) in params: d[name] = value return major, minor, d def parseOrdered(string): if ";" in string: type, params = string.split(";", 1) params = _parse_params(params) else: type = string params = [] if "/" not in type: raise ValueError("content type missing major/minor parts: %r" % type) type = type.strip() major, minor = type.lower().split("/", 1) return _check_token(major.strip()), _check_token(minor.strip()), params def _parse_params(string): result = [] string = string.strip() while string: if not "=" in string: raise ValueError("parameter values are not optional") name, rest = string.split("=", 1) name = _check_token(name.strip().lower()) rest = rest.strip() # rest is: value *[";" parameter] if rest[:1] == '"': # quoted-string, defined in RFC 822. m = _quoted_string_match(rest) if m is None: raise ValueError("invalid quoted-string in %r" % rest) value = m.group() rest = rest[m.end():].strip() #import pdb; pdb.set_trace() if rest[:1] not in ("", ";"): raise ValueError( "invalid token following quoted-string: %r" % rest) rest = rest[1:] value = _unescape(value) elif ";" in rest: value, rest = rest.split(";") value = _check_token(value.strip()) else: value = _check_token(rest.strip()) rest = "" result.append((name, value)) string = rest.strip() return result def _quoted_string_match(string): # This support RFC 822 quoted-string values. global _quoted_string_match _quoted_string_match = re.compile( '"(?:\\\\.|[^"\n\r\\\\])*"', re.DOTALL).match return _quoted_string_match(string) def _check_token(string): if _token_match(string) is None: raise ValueError('"%s" is not a valid token' % string) return string def _token_match(string): global _token_match _token_match = re.compile("[^][ \t\n\r()<>@,;:\"/?=\\\\]+$").match return _token_match(string) def _unescape(string): assert string[0] == '"' assert string[-1] == '"' string = string[1:-1] if "\\" in string: string = re.sub(r"\\(.)", r"\1", string) return string def join(spec): (major, minor, params) = spec pstr = "" try: params.items except AttributeError: pass else: params = params.items() # ensure a predictable order: params = sorted(params) for name, value in params: pstr += ";%s=%s" % (name, _escape(value)) return "%s/%s%s" % (major, minor, pstr) def _escape(string): try: return _check_token(string) except ValueError: # '\\' must be first for c in '\\"\n\r': string = string.replace(c, "\\" + c) return '"%s"' % string zope.contenttype-4.1.0/src/zope/__init__.py0000664000175000017500000000007012447264526022100 0ustar tseavertseaver00000000000000__import__('pkg_resources').declare_namespace(__name__) zope.contenttype-4.1.0/COPYRIGHT.txt0000664000175000017500000000004012447264526020331 0ustar tseavertseaver00000000000000Zope Foundation and Contributorszope.contenttype-4.1.0/CHANGES.rst0000664000175000017500000000354012447344107020024 0ustar tseavertseaver00000000000000Change History ============== 4.1.0 (2014-12-26) ------------------ - Add support for Python 3.4 and PyPy3. - Add support for testing on Travis. 4.0.1 (2013-02-20) ------------------ - Change the file contents argument of ``guess_content_type`` from string to bytes. This change has no effect on Python 2. 4.0.0 (2013-02-11) ------------------ - Add some tests for better coverage. - Add ``tox.ini`` and manifest. - Add support for Python 3.3 and PyPy. - Drop support for Python 2.4 and 2.5. 3.5.5 (2011-07-27) ------------------ - Properly restore the HTML snippet detection, by looking at the entire string and not just its start. 3.5.4 (2011-07-26) ------------------ - Restore detection of HTML snippets from 3.4 series. 3.5.3 (2011-03-18) ------------------ - Add new mime types for web fonts, cache manifest and new media formats. 3.5.2 (2011-02-11) ------------------ - LP #717289: add ``video/x-m4v`` mimetype for the ``.m4v`` extension. 3.5.1 (2010-03-23) ------------------ - LP #242321: fix IndexError raised when testing strings consisting solely of leading whitespace. 3.5.0 (2009-10-22) ------------------ - Move the implementation of ``zope.publisher.contenttype`` to ``zope.contenttype.parse``, moved tests along. 3.4.3 (2009-12-28) ------------------ - Update mime-type for ``.js`` to be application/javascript. 3.4.2 (2009-05-28) ------------------ - Add MS Office 12 types based on: http://www.therightstuff.de/2006/12/16/Office+2007+File+Icons+For+Windows+SharePoint+Services+20+And+SharePoint+Portal+Server+2003.aspx 3.4.1 (2009-02-04) ------------------ - Improve ``text_type()``. Based on the patch from http://www.zope.org/Collectors/Zope/2355/ - Add missing ``setuptools`` dependency to setup.py. - Add reference documentation. 3.4.0 (2007-09-13) ------------------ - First stable release as an independent package. zope.contenttype-4.1.0/LICENSE.txt0000664000175000017500000000402612447264526020053 0ustar tseavertseaver00000000000000Zope Public License (ZPL) Version 2.1 A copyright notice accompanies this license document that identifies the copyright holders. This license has been certified as open source. It has also been designated as GPL compatible by the Free Software Foundation (FSF). Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions in source code must retain the accompanying copyright notice, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the accompanying copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Names of the copyright holders must not be used to endorse or promote products derived from this software without prior written permission from the copyright holders. 4. The right to distribute this software or to use it for any purpose does not give you the right to use Servicemarks (sm) or Trademarks (tm) of the copyright holders. Use of them is covered by separate agreement with the copyright holders. 5. If any files are modified, you must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. Disclaimer THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. zope.contenttype-4.1.0/README.rst0000664000175000017500000000036312447343156017714 0ustar tseavertseaver00000000000000``zope.contenttype`` ==================== .. image:: https://travis-ci.org/zopefoundation/zope.contenttype.png?branch=master :target: https://travis-ci.org/zopefoundation/zope.contenttype A utility module for content-type handling. zope.contenttype-4.1.0/MANIFEST.in0000664000175000017500000000020512447264526017761 0ustar tseavertseaver00000000000000include *.rst include *.txt include tox.ini include bootstrap.py include buildout.cfg recursive-include src * global-exclude *.pyc