This file is indexed.

/usr/share/pyshared/zope/publisher/defaultview.py is in python-zope.publisher 3.12.6-2ubuntu1.

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Default view name API
"""
from zope.component.interfaces import ComponentLookupError
from zope.component import getSiteManager

import zope.interface
from zope.publisher.interfaces import IDefaultViewName


class IDefaultViewNameAPI(zope.interface.Interface):

    def getDefaultViewName(object, request, context=None):
        """Get the name of the default view for the object and request.

        If a matching default view name cannot be found, raises
        ComponentLookupError.

        If context is not specified, attempts to use
        object to specify a context.
        """

    def queryDefaultViewName(object, request, default=None, context=None):
        """Look for the name of the default view for the object and request.

        If a matching default view name cannot be found, returns the default.

        If context is not specified, attempts to use object to specify
        a context.
        """

def getDefaultViewName(object, request, context=None):
    name = queryDefaultViewName(object, request, context=context)
    if name is not None:
        return name
    raise ComponentLookupError("Couldn't find default view name",
                               context, request)

def queryDefaultViewName(object, request, default=None, context=None):
    """
    query the default view for a given object and request.

      >>> from zope.publisher.defaultview import queryDefaultViewName

    lets create an object with a default view.

      >>> import zope.interface
      >>> class IMyObject(zope.interface.Interface):
      ...   pass
      >>> class MyObject(object):
      ...   zope.interface.implements(IMyObject)
      >>> queryDefaultViewName(MyObject(), object()) is None
      True

    Now we can will set a default view.

      >>> import zope.component
      >>> import zope.publisher.interfaces
      >>> zope.component.provideAdapter('name',
      ...     adapts=(IMyObject, zope.interface.Interface),
      ...     provides=zope.publisher.interfaces.IDefaultViewName)
      >>> queryDefaultViewName(MyObject(), object())
      'name'

    This also works if the name is empty

      >>> zope.component.provideAdapter('',
      ...     adapts=(IMyObject, zope.interface.Interface),
      ...     provides=zope.publisher.interfaces.IDefaultViewName)
      >>> queryDefaultViewName(MyObject(), object())
      ''
    """
    name = getSiteManager(context).adapters.lookup(
        map(zope.interface.providedBy, (object, request)), IDefaultViewName)
    if name is None:
        return default
    return name