Debian Codegraph @

src/launchpadlib/apps.py

raw
1 # Copyright 2009 Canonical Ltd.
2
3 # This file is part of launchpadlib.
4 #
5 # launchpadlib is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by the
7 # Free Software Foundation, version 3 of the License.
8 #
9 # launchpadlib is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 # for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
16
17 """Command-line applications for Launchpadlib.
18
19 This module contains the code for various applications. The applications
20 themselves are kept in bin/.
21 """
22
23 __all__ = [
24 "RequestTokenApp",
25 ]
26
27 import json
28
29 from launchpadlib.credentials import Credentials
30 from launchpadlib.uris import lookup_web_root
31
32
33 class RequestTokenApp:
34 """An application that creates request tokens."""
35
36 def __init__(self, web_root, consumer_name, context):
37 """Initialize."""
38 self.web_root = lookup_web_root(web_root)
39 self.credentials = Credentials(consumer_name)
40 self.context = context
41
42 def run(self):
43 """Get a request token and return JSON information about it."""
44 token = self.credentials.get_request_token(
45 self.context,
46 self.web_root,
47 token_format=Credentials.DICT_TOKEN_FORMAT,
48 )
49 return json.dumps(token)