Commits

Anonymous committed 901b6c1

Renamed "foo_class" -> cls. This are new features in 0.5 and it's not a backwards compatible fix from release version to release version.

Comments (0)

Files changed (4)

werkzeug/contrib/fixers.py

 
 class InternetExplorerFix(object):
     """This middleware fixes a couple of bugs with Microsoft Internet
-    Explorer.
-
-    Currently the following fixes are applied:
+    Explorer.  Currently the following fixes are applied:
 
     -   removing of `Vary` headers for unsupported mimetypes which
         causes troubles with caching.  Can be disabled by passing
                 headers['Pragma'] = pragma
             header = headers.get('cache-control', '')
             if header:
-                cc = parse_cache_control_header(header, None,
-                                                ResponseCacheControl)
+                cc = parse_cache_control_header(header,
+                                                cls=ResponseCacheControl)
                 cc.no_cache = cc.no_store = False
                 header = cc.to_header()
                 if not header:
     return name, extra
 
 
-def parse_accept_header(value, accept_class=None):
+def parse_accept_header(value, cls=None):
     """Parses an HTTP Accept-* header.  This does not implement a complete
     valid algorithm but one that supports at least value and quality
     extraction.
     with the parsed values and returned.
 
     :param value: the accept header string to be parsed.
-    :param accept_class: the wrapper class for the return value (can be
+    :param cls: the wrapper class for the return value (can be
                          :class:`Accept` or a subclass thereof)
     :return: an instance of `cls`.
     """
-    if accept_class is None:
-        accept_class = Accept
+    if cls is None:
+        cls = Accept
 
     if not value:
-        return accept_class(None)
+        return cls(None)
 
     result = []
     for match in _accept_re.finditer(value):
         else:
             quality = max(min(float(quality), 1), 0)
         result.append((match.group(1), quality))
-    return accept_class(result)
+    return cls(result)
 
 
-def parse_cache_control_header(value, on_update=None, cache_control_class=None):
+def parse_cache_control_header(value, on_update=None, cls=None):
     """Parse a cache control header.  The RFC differs between response and
     request cache control, this method does not.  It's your responsibility
     to not use the wrong control statements.
 
     .. versionadded:: 0.5
-       The `cache_control_class` was added.  If not specified an immutable
+       The `cls` was added.  If not specified an immutable
        :class:`RequestCacheControl` is returned.
 
     :param value: a cache control header to be parsed.
     :param on_update: an optional callable that is called every time a
                       value on the :class:`CacheControl` object is changed.
-    :param cache_control_class: the class for the returned object.  By default
+    :param cls: the class for the returned object.  By default
                                 :class:`RequestCacheControl` is used.
-    :return: a `cache_control_class` object.
+    :return: a `cls` object.
     """
-    if cache_control_class is None:
-        cache_control_class = RequestCacheControl
+    if cls is None:
+        cls = RequestCacheControl
     if not value:
-        return cache_control_class(None, on_update)
-    return cache_control_class(parse_dict_header(value), on_update)
+        return cls(None, on_update)
+    return cls(parse_dict_header(value), on_update)
 
 
 def parse_set_header(value, on_update=None):

werkzeug/utils.py

 
 def parse_form_data(environ, stream_factory=None, charset='utf-8',
                     errors='ignore', max_form_memory_size=None,
-                    max_content_length=None, dict_class=None):
+                    max_content_length=None, cls=None):
     """Parse the form data in the environ and return it as tuple in the form
     ``(stream, form, files)``.  You should only call this method if the
     transport method is `POST` or `PUT`.
 
     .. versionadded:: 0.5
        The `max_form_memory_size`, `max_content_length` and
-       `dict_class` parameters were added.
+       `cls` parameters were added.
 
     :param environ: the WSGI environment to be used for parsing.
     :param stream_factory: An optional callable that returns a new read and
                                is longer than this value an
                                :exc:`~exceptions.RequestEntityTooLarge`
                                exception is raised.
-    :param dict_class: an optional dict class to use.  If this is not specified
+    :param cls: an optional dict class to use.  If this is not specified
                        or `None` the default :class:`MultiDict` is used.
     :return: A tuple in the form ``(stream, form, files)``.
     """
     except (KeyError, ValueError):
         content_length = 0
 
-    if dict_class is None:
-        dict_class = MultiDict
+    if cls is None:
+        cls = MultiDict
 
     if max_content_length is not None and content_length > max_content_length:
         raise RequestEntityTooLarge()
                                           charset, errors,
                                           max_form_memory_size=max_form_memory_size)
         except ValueError, e:
-            form = dict_class()
+            form = cls()
         else:
-            form = dict_class(form)
+            form = cls(form)
     elif content_type == 'application/x-www-form-urlencoded' or \
          content_type == 'application/x-url-encoded':
         if max_form_memory_size is not None and \
            content_length > max_form_memory_size:
             raise RequestEntityTooLarge()
         form = url_decode(environ['wsgi.input'].read(content_length),
-                          charset, errors=errors, dict_class=dict_class)
+                          charset, errors=errors, cls=cls)
     else:
-        form = dict_class()
+        form = cls()
         stream = LimitedStream(environ['wsgi.input'], content_length)
 
-    return stream, form, dict_class(files)
+    return stream, form, cls(files)
 
 
 def get_content_type(mimetype, charset):
 
 
 def url_decode(s, charset='utf-8', decode_keys=False, include_empty=True,
-               errors='ignore', separator='&', dict_class=None):
+               errors='ignore', separator='&', cls=None):
     """Parse a querystring and return it as :class:`MultiDict`.  Per default
     only values are decoded into unicode strings.  If `decode_keys` is set to
     `True` the same will happen for keys.
        This changed in 0.5 where only "&" is supported.  If you want to
        use ";" instead a different `separator` can be provided.
 
-       The `dict_class` parameter was added.
+       The `cls` parameter was added.
 
     :param s: a string with the query string to decode.
     :param charset: the charset of the query string.
                           appear in the dict.
     :param errors: the decoding error behavior.
     :param separator: the pair separator to be used, defaults to ``&``
-    :param dict_class: an optional dict class to use.  If this is not specified
+    :param cls: an optional dict class to use.  If this is not specified
                        or `None` the default :class:`MultiDict` is used.
     """
-    if dict_class is None:
-        dict_class = MultiDict
+    if cls is None:
+        cls = MultiDict
     result = []
     for pair in str(s).split(separator):
         if not pair:
         if decode_keys:
             key = _decode_unicode(key, charset, errors)
         result.append((key, url_unquote_plus(value, charset, errors)))
-    return dict_class(result)
+    return cls(result)
 
 
 def url_encode(obj, charset='utf-8', encode_keys=False, sort=False, key=None,
 
 
 def parse_cookie(header, charset='utf-8', errors='ignore',
-                 dict_class=None):
+                 cls=None):
     """Parse a cookie.  Either from a string or WSGI environ.
 
     Per default encoding errors are ignored.  If you want a different behavior
 
     .. versionchanged:: 0.5
        This function now returns a :class:`TypeConversionDict` instead of a
-       regular dict.  The `dict_class` parameter was added.
+       regular dict.  The `cls` parameter was added.
 
     :param header: the header to be used to parse the cookie.  Alternatively
                    this can be a WSGI environment.
     :param charset: the charset for the cookie values.
     :param errors: the error behavior for the charset decoding.
-    :param dict_class: an optional dict class to use.  If this is not specified
+    :param cls: an optional dict class to use.  If this is not specified
                        or `None` the default :class:`TypeConversionDict` is
                        used.
     """
     if isinstance(header, dict):
         header = header.get('HTTP_COOKIE', '')
-    if dict_class is None:
-        dict_class = TypeConversionDict
+    if cls is None:
+        cls = TypeConversionDict
     cookie = _ExtendedCookie()
     cookie.load(header)
     result = {}
         if value.value is not None:
             result[key] = _decode_unicode(value.value, charset, errors)
 
-    return dict_class(result)
+    return cls(result)
 
 
 def dump_cookie(key, value='', max_age=None, expires=None, path='/',

werkzeug/wrappers.py

                                        self.charset, self.encoding_errors,
                                        self.max_form_memory_size,
                                        self.max_content_length,
-                                       dict_class=ImmutableMultiDict)
+                                       cls=ImmutableMultiDict)
             else:
                 data = (_empty_stream, ImmutableMultiDict(),
                         ImmutableMultiDict())
         """The parsed URL parameters as :class:`MultiDict`."""
         return url_decode(self.environ.get('QUERY_STRING', ''), self.charset,
                           errors=self.encoding_errors,
-                          dict_class=ImmutableMultiDict)
+                          cls=ImmutableMultiDict)
 
     @cached_property
     def data(self):
     def cookies(self):
         """The retrieved cookie values as regular dictionary."""
         return parse_cookie(self.environ, self.charset,
-                            dict_class=ImmutableTypeConversionDict)
+                            cls=ImmutableTypeConversionDict)
 
     @cached_property
     def headers(self):