Commits

Anonymous committed 41d2e43

moved limiter out of the utils into a contrib package

Comments (0)

Files changed (5)

werkzeug/__init__.py

 import sys
 
 
-object_origins = {
-    'BaseRequest':          'werkzeug.wrappers',
-    'BaseResponse':         'werkzeug.wrappers',
-    'BaseReporterStream':   'werkzeug.wrappers',
-    'DebuggedApplication':  'werkzeug.debug',
-    'Template':             'werkzeug.minitmpl',
-    'Client':               'werkzeug.test',
-    'Local':                'werkzeug.locals',
-    'LocalManager':         'werkzeug.locals',
-    'run_simple':           'werkzeug.serving',
-    'SharedDataMiddleware': 'werkzeug.utils',
-    'ClosingIterator':      'werkzeug.utils',
-    'environ_property':     'werkzeug.utils',
-    'parse_accept_header':  'werkzeug.utils',
-    'url_decode':           'werkzeug.utils',
-    'url_encode':           'werkzeug.utils',
-    'url_quote':            'werkzeug.utils',
-    'url_unquote':          'werkzeug.utils',
-    'url_quote_plus':       'werkzeug.utils',
-    'url_unquote_plus':     'werkzeug.utils',
-    'escape':               'werkzeug.utils'
+all_by_module = {
+    'werkzeug.debug':       ['DebuggedApplication'],
+    'werkzeug.locals':      ['Local', 'LocalManager'],
+    'werkzeug.minitmpl':    ['Template'],
+    'werkzeug.serving':     ['run_simple'],
+    'werkzeug.test':        ['Client'],
+    'werkzeug.utils':       ['escape', 'create_environ', 'url_quote',
+                             'environ_property', 'cookie_date',
+                             'url_encode', 'url_quote_plus',
+                             'CombinedMultiDict', 'run_wsgi_app',
+                             'get_host', 'SharedDataMiddleware',
+                             'url_unquote_plus', 'ClosingIterator',
+                             'Headers', 'parse_accept_header',
+                             'url_unquote', 'get_current_url',
+                             'lazy_property', 'MultiDict', 'url_decode'],
+    'werkzeug.wrappers':    ['BaseResponse', 'BaseRequest',
+                             'BaseReporterStream']
 }
 
-all_by_module = {}
-for name, module in object_origins.iteritems():
-    all_by_module.setdefault(module, []).append(name)
+
+object_origins = {}
+for module, items in all_by_module.iteritems():
+    for item in items:
+        object_origins[item] = module
 
 
 class _AutoModule(ModuleType):

werkzeug/contrib/__init__.py

 
     Contains user-submitted code that other users may find useful,
     but which are not part of Werkzeug core. Anyone can write
-    code for inclusion in the `contrib` package, which may be
-    included in future releases if it proves useful.
+    code for inclusion in the `contrib` package.  All the modules
+    in this package are distributed as an addon library and thus not
+    part of `werkzeug` itself.
 
     This file itself is mostly for informational purposes and to
     tell the Python interpreter that `contrib` is a package.
 
-    :copyright: 2007 by Marek Kubica
+
+    :copyright: 2007 by Marek Kubica.
     :license: BSD, see LICENSE for more details.
 """

werkzeug/contrib/limiter.py

+# -*- coding: utf-8 -*-
+"""
+    werkzeug.contrib.limiter
+    ~~~~~~~~~~~~~~~~~~~~~~~~
+
+    A middleware that limits incoming data.  This works around problems
+    with trac or django because those stream into the memory directly.
+
+
+    :copyright: 2007 by Armin Ronacher.
+    :license: BSD, see LICENSE for more details.
+"""
+
+
+class LimitedStream(object):
+    """
+    Wraps a stream and doesn't read more than n bytes.
+    """
+
+    def __init__(self, environ, limit):
+        self._environ = environ
+        self._stream = environ['wsgi.input']
+        self._limit = min(limit, int(environ.get('CONTENT_LENGTH') or 0))
+        self._pos = 0
+
+    def read(self, size=None):
+        if self._pos >= self._limit:
+            return ''
+        if size is None:
+            size = self._limit
+        read = self._stream.read(min(self._limit - self._pos, size))
+        self._pos += len(read)
+        return read
+
+    def readline(self, *args):
+        if self._pos >= self._limit:
+            return ''
+        line = self._stream.readline(*args)
+        self.pos += len(line)
+        self.processed()
+        return line
+
+    def readlines(self, hint=None):
+        result = []
+        while self.pos < self._limit:
+            result.append(self.readline())
+        return result
+
+
+class StreamLimitMiddleware(object):
+    """
+    Limits the input stream to a given number of bytes.  This is useful if
+    you have a WSGI application that reads form data into memory (django for
+    example) and you don't want users to harm the server by uploading tons of
+    data.
+
+    Default is 10MB
+    """
+
+    def __init__(self, app, maximum_size=1024 * 1024 * 10):
+        self.app = app
+        self.maximum_size = maximum_size
+
+    def __call__(self, environ, start_response):
+        environ['wsgi.input'] = LimitedStream(environ, self.maximum_size)
+        return self.app(environ, start_response)

werkzeug/contrib/sessions.py

             self.should_save and '*' or ''
         )
 
-    @property
     def should_save(self):
         """True if the session should be saved."""
         return self.modified or self.new
+    should_save = property(should_save)
 
     def copy(self):
         """Create a flat copy of the session."""

werkzeug/utils.py

             callback()
 
 
-class LimitedStream(object):
-    """
-    Wraps a stream and doesn't read more than n bytes.
-    """
-
-    def __init__(self, environ, limit):
-        self._environ = environ
-        self._stream = environ['wsgi.input']
-        self._limit = min(limit, int(environ.get('CONTENT_LENGTH') or 0))
-        self._pos = 0
-
-    def read(self, size=None):
-        if self._pos >= self._limit:
-            return ''
-        if size is None:
-            size = self._limit
-        read = self._stream.read(min(self._limit - self._pos, size))
-        self._pos += len(read)
-        return read
-
-    def readline(self, *args):
-        if self._pos >= self._limit:
-            return ''
-        line = self._stream.readline(*args)
-        self.pos += len(line)
-        self.processed()
-        return line
-
-    def readlines(self, hint=None):
-        result = []
-        while self.pos < self._limit:
-            result.append(self.readline())
-        return result
-
-
-class StreamLimitMiddleware(object):
-    """
-    Limits the input stream to a given number of bytes.  This is useful if
-    you have a WSGI application that reads form data into memory (django for
-    example) and you don't want users to harm the server by uploading tons of
-    data.
-
-    Default is 10MB
-    """
-
-    def __init__(self, app, maximum_size=1024 * 1024 * 10):
-        self.app = app
-        self.maximum_size = maximum_size
-
-    def __call__(self, environ, start_response):
-        environ['wsgi.input'] = LimitedStream(environ, self.maximum_size)
-        return self.app(environ, start_response)
-
-
 class lazy_property(object):
     """
     Descriptor implementing a "lazy property", i.e. the function