~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp_sitecustomize.py

  • Committer: Curtis Hovey
  • Date: 2011-06-21 14:04:50 UTC
  • mfrom: (13270 devel)
  • mto: This revision was merged to the branch mainline in revision 13272.
  • Revision ID: curtis.hovey@canonical.com-20110621140450-sx2v4584sla4urfc
Merged devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    )
17
17
 
18
18
from bzrlib.branch import Branch
 
19
from canonical.launchpad.webapp.interfaces import IUnloggedException
19
20
from lp.services.log import loglevels
20
21
from lp.services.log.logger import LaunchpadLogger
21
22
from lp.services.log.mappingfilter import MappingFilter
22
23
from lp.services.log.nullhandler import NullHandler
23
24
from lp.services.mime import customizeMimetypes
 
25
from zope.interface import alsoProvides
24
26
from zope.security import checker
 
27
import zope.publisher.browser
25
28
 
26
29
 
27
30
def add_custom_loglevels():
136
139
    silence_transaction_logger()
137
140
 
138
141
 
 
142
def customize_get_converter(zope_publisher_browser=zope.publisher.browser):
 
143
    """URL parameter conversion errors shouldn't generate an OOPS report.
 
144
 
 
145
    This injects (monkey patches) our wrapper around get_converter so improper
 
146
    use of parameter type converters (like http://...?foo=bar:int) won't
 
147
    generate OOPS reports.
 
148
    """
 
149
    original_get_converter = zope_publisher_browser.get_converter
 
150
 
 
151
    def get_converter(*args, **kws):
 
152
        """Get a type converter but turn off OOPS reporting if it fails."""
 
153
        converter = original_get_converter(*args, **kws)
 
154
 
 
155
        def wrapped_converter(v):
 
156
            try:
 
157
                return converter(v)
 
158
            except ValueError, e:
 
159
                # Mark the exception as not being OOPS-worthy.
 
160
                alsoProvides(e, IUnloggedException)
 
161
                raise
 
162
 
 
163
        # The converter can be None, in which case wrapping it makes no sense,
 
164
        # otherwise it is a function which we wrap.
 
165
        if converter is None:
 
166
            return None
 
167
        else:
 
168
            return wrapped_converter
 
169
 
 
170
    zope_publisher_browser.get_converter = get_converter
 
171
 
 
172
 
139
173
def main(instance_name):
140
174
    # This is called by our custom buildout-generated sitecustomize.py
141
175
    # in parts/scripts/sitecustomize.py. The instance name is sent to
161
195
    checker.BasicTypes[grouper] = checker._iteratorChecker
162
196
    silence_warnings()
163
197
    customize_logger()
 
198
    customize_get_converter()