blob: 4ff96615ed2e21d4414582d689c5a26899f99896 [file] [log] [blame]
Marcin Juszkiewicz25ba61f2013-04-02 14:37:54 +02001#!/usr/bin/python
2#
3# (C) 2013 Linaro Ltd.
4#
5# Based on scripts/download.py from lp:linaro-licence-protection
6#
7# This program is free software: you can redistribute it and/or modify it under
8# the terms of the GNU Affero General Public License as published by the Free
9# Software Foundation, either version 3 of the License, or (at your option) any
10# later version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
15# details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import json
21import urlparse
22
23class ApiUrls():
24 """Since we want to manipulate URLS, but urlsplit returns an immutable
25 object this is a convenience object to perform the manipulations for us"""
26 def __init__(self, input_url):
27 self.parsed_url = [c for c in urlparse.urlsplit(input_url)]
28 self.path = self.parsed_url[2]
29
30 def ls(self, path=None):
31 if not path:
32 path = self.path
33 self.parsed_url[2] = "/api/ls" + path
34 return urlparse.urlunsplit(self.parsed_url)
35
36 def license(self, path):
37 self.parsed_url[2] = "/api/license" + path
38 return urlparse.urlunsplit(self.parsed_url)
39
40 def file(self, path):
41 self.parsed_url[2] = path
42 return urlparse.urlunsplit(self.parsed_url)