~launchpad-pqm/launchpad/devel

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0211,E0213

"""XML-RPC API to the application roots."""

__metaclass__ = type

__all__ = [
    'ISelfTest',
    'PrivateApplication',
    'SelfTest',
    ]

import xmlrpclib

from zope.component import getUtility
from zope.interface import (
    implements,
    Interface,
    )

from lp.bugs.interfaces.malone import IPrivateMaloneApplication
from lp.code.interfaces.codehosting import ICodehostingApplication
from lp.code.interfaces.codeimportscheduler import (
    ICodeImportSchedulerApplication,
    )
from lp.registry.interfaces.mailinglist import IMailingListApplication
from lp.registry.interfaces.person import ISoftwareCenterAgentApplication
from lp.services.authserver.interfaces import IAuthServerApplication
from lp.services.features.xmlrpc import IFeatureFlagApplication
from lp.services.webapp import LaunchpadXMLRPCView
from lp.services.webapp.interfaces import ILaunchBag
from lp.xmlrpc.interfaces import IPrivateApplication

# NOTE: If you add a traversal here, you should update
# the regular expression in utilities/page-performance-report.ini
class PrivateApplication:
    implements(IPrivateApplication)

    @property
    def mailinglists(self):
        """See `IPrivateApplication`."""
        return getUtility(IMailingListApplication)

    @property
    def authserver(self):
        """See `IPrivateApplication`."""
        return getUtility(IAuthServerApplication)

    @property
    def codehosting(self):
        """See `IPrivateApplication`."""
        return getUtility(ICodehostingApplication)

    @property
    def codeimportscheduler(self):
        """See `IPrivateApplication`."""
        return getUtility(ICodeImportSchedulerApplication)

    @property
    def bugs(self):
        """See `IPrivateApplication`."""
        return getUtility(IPrivateMaloneApplication)

    @property
    def softwarecenteragent(self):
        """See `IPrivateApplication`."""
        return getUtility(ISoftwareCenterAgentApplication)

    @property
    def featureflags(self):
        """See `IPrivateApplication`."""
        return getUtility(IFeatureFlagApplication)


class ISelfTest(Interface):
    """XMLRPC external interface for testing the XMLRPC external interface."""

    def make_fault():
        """Returns an xmlrpc fault."""

    def concatenate(string1, string2):
        """Return the concatenation of the two given strings."""

    def hello():
        """Return a greeting to the one calling the method."""

    def raise_exception():
        """Raise an exception."""


class SelfTest(LaunchpadXMLRPCView):

    implements(ISelfTest)

    def make_fault(self):
        """Returns an xmlrpc fault."""
        return xmlrpclib.Fault(666, "Yoghurt and spanners.")

    def concatenate(self, string1, string2):
        """Return the concatenation of the two given strings."""
        return u'%s %s' % (string1, string2)

    def hello(self):
        """Return a greeting to the logged in user."""
        caller = getUtility(ILaunchBag).user
        if caller is not None:
            caller_name = caller.displayname
        else:
            caller_name = "Anonymous"
        return "Hello %s." % caller_name

    def raise_exception(self):
        raise RuntimeError("selftest exception")