This file is indexed.

/usr/share/pyshared/zope/formlib/errors.txt is in python-zope.formlib 4.0.5-0ubuntu5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
==============
Error handling
==============

These are a couple of functional tests that were written on-the-go ... In the
future this might become more extensive ...

Displaying invalidation errors
==============================

Validation errors, e.g. cause by invariants, are converted into readable text
by adapting them to IWidgetInputErrorView:

    >>> from zope.publisher.browser import TestRequest
    >>> from zope.interface.exceptions import Invalid
    >>> from zope.component import getMultiAdapter
    >>> from zope.formlib.interfaces import IWidgetInputErrorView
    >>> error = Invalid("You are wrong!")
    >>> message = getMultiAdapter((error, TestRequest()),
    ...         IWidgetInputErrorView).snippet()
    >>> message
    u'<span class="error">You are wrong!</span>'

Interface invariant methods raise zope.interface.Invalid exception. Test if
this exception gets handled by the error_views.

    >>> myError = Invalid('My error message')
    >>> import zope.formlib.form
    >>> mybase = zope.formlib.form.FormBase(None, TestRequest())
    >>> mybase.errors = (myError,)
    >>> save = mybase.error_views()
    >>> save.next()
    u'<span class="error">My error message</span>'

Now we need to set up the translation framework:

    >>> from zope import component, interface
    >>> from zope.i18n.interfaces import INegotiator
    >>> class Negotiator:
    ...     interface.implements(INegotiator)
    ...     def getLanguage(*ignored): return 'test'
    >>> component.provideUtility(Negotiator())
    >>> from zope.i18n.testmessagecatalog import TestMessageFallbackDomain
    >>> component.provideUtility(TestMessageFallbackDomain)

And yes, we can even handle an i18n message in an Invalid exception:

    >>> from zope.i18nmessageid import MessageFactory
    >>> _ = MessageFactory('my.domain')
    >>> myError = Invalid(_('My i18n error message'))
    >>> mybase = zope.formlib.form.FormBase(None, TestRequest())
    >>> mybase.errors = (myError,)
    >>> save = mybase.error_views()
    >>> save.next()
    u'<span class="error">[[my.domain][My i18n error message]]</span>'

Displaying widget input errors
==============================

WidgetInputError exceptions also work with i18n messages:

    >>> from zope.formlib.interfaces import WidgetInputError
    >>> myError = WidgetInputError(
    ...     field_name='summary',
    ...     widget_title=_(u'Summary'),
    ...     errors=_(u'Foo'))
    >>> mybase = zope.formlib.form.FormBase(None, TestRequest())
    >>> mybase.errors = (myError,)
    >>> save = mybase.error_views()
    >>> save.next()
    u'[[my.domain][Summary]]: <span class="error">[[my.domain][Foo]]</span>'