[Checkins] SVN: zope.publisher/trunk/ documented moving contenttype parsing to zope.contenttype, turned implementation into BBB imports, adapted imports, added dependency
Thomas Lotze
tl at gocept.com
Thu Oct 8 11:28:41 EDT 2009
Log message for revision 104936:
documented moving contenttype parsing to zope.contenttype, turned implementation into BBB imports, adapted imports, added dependency
Changed:
U zope.publisher/trunk/CHANGES.txt
U zope.publisher/trunk/setup.py
U zope.publisher/trunk/src/zope/publisher/contenttype.py
U zope.publisher/trunk/src/zope/publisher/http.py
-=-
Modified: zope.publisher/trunk/CHANGES.txt
===================================================================
--- zope.publisher/trunk/CHANGES.txt 2009-10-08 15:25:56 UTC (rev 104935)
+++ zope.publisher/trunk/CHANGES.txt 2009-10-08 15:28:41 UTC (rev 104936)
@@ -1,12 +1,13 @@
CHANGES
=======
-3.9.4 (unreleased)
-------------------
+3.10.0 (unreleased)
+-------------------
-- Nothing changed yet.
+- Moved the implementation of zope.publisher.contenttype to
+ zope.contenttype.parse, leaving BBB imports and moving tests along.
+ zope.contenttype is a new but light-weight dependency of this package.
-
3.9.3 (2009-10-08)
------------------
Modified: zope.publisher/trunk/setup.py
===================================================================
--- zope.publisher/trunk/setup.py 2009-10-08 15:25:56 UTC (rev 104935)
+++ zope.publisher/trunk/setup.py 2009-10-08 15:28:41 UTC (rev 104936)
@@ -28,7 +28,7 @@
"""
setup(name='zope.publisher',
- version = '3.9.4dev',
+ version = '3.10.0dev',
url='http://pypi.python.org/pypi/zope.publisher',
license='ZPL 2.1',
author='Zope Corporation and Contributors',
@@ -50,6 +50,7 @@
'zope.browser',
'zope.component',
'zope.configuration',
+ 'zope.contenttype',
'zope.event',
'zope.exceptions',
'zope.i18n',
Modified: zope.publisher/trunk/src/zope/publisher/contenttype.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/contenttype.py 2009-10-08 15:25:56 UTC (rev 104935)
+++ zope.publisher/trunk/src/zope/publisher/contenttype.py 2009-10-08 15:28:41 UTC (rev 104936)
@@ -19,118 +19,5 @@
"""
__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((major, minor, params)):
- pstr = ""
- try:
- params.items
- except AttributeError:
- pass
- else:
- params = params.items()
- # ensure a predictable order:
- params.sort()
- 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
+# BBB
+from zope.contenttype.parse import parse, parseOrdered, join
Modified: zope.publisher/trunk/src/zope/publisher/http.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/http.py 2009-10-08 15:25:56 UTC (rev 104935)
+++ zope.publisher/trunk/src/zope/publisher/http.py 2009-10-08 15:28:41 UTC (rev 104936)
@@ -20,7 +20,6 @@
from zope.i18n.interfaces import IUserPreferredCharsets
from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.locales import locales, LoadLocaleError
-from zope.publisher import contenttype
from zope.publisher.base import BaseRequest, BaseResponse
from zope.publisher.base import RequestDataGetter
from zope.publisher.base import RequestDataProperty, RequestDataMapper
@@ -43,6 +42,7 @@
import urllib
import urlparse
import zope.component
+import zope.contenttype.parse
import zope.event
import zope.interface
@@ -804,9 +804,8 @@
raise ValueError(
'Unicode results must have a text content type.')
+ major, minor, params = zope.contenttype.parse.parse(content_type)
- major, minor, params = contenttype.parse(content_type)
-
if 'charset' in params:
encoding = params['charset']
More information about the checkins
mailing list