tests/hgweberror.py
author Yuya Nishihara <yuya@tcha.org>
Sat, 06 Feb 2016 19:09:10 +0900
changeset 28175 c25e3fd38ff1
parent 27299 74e6de99ce7f
child 36865 3d60a22e27f5
permissions -rw-r--r--
demandimport: enforce ignore list while processing modules in fromlist If a module is loaded as "from . import x" form, there has been no way to disable demand loading for that module because name is ''. This patch makes it possible to prevent demand loading by '<package-name>.x'. We don't use _hgextimport(_origimport) here since attr is known to be a sub-module name. Adding hgext_ to attr wouldn't make sense.

# A dummy extension that installs an hgweb command that throws an Exception.

from __future__ import absolute_import

from mercurial.hgweb import (
    webcommands,
)

def raiseerror(web, req, tmpl):
    '''Dummy web command that raises an uncaught Exception.'''

    # Simulate an error after partial response.
    if 'partialresponse' in req.form:
        req.respond(200, 'text/plain')
        req.write('partial content\n')

    raise AttributeError('I am an uncaught error!')

def extsetup(ui):
    setattr(webcommands, 'raiseerror', raiseerror)
    webcommands.__all__.append('raiseerror')