|
8 | 8 | # Fall back to Python 2's urllib2 |
9 | 9 | from urllib2 import urlopen |
10 | 10 | try: |
11 | | - # For Python 3.0 and later |
12 | | - from urllib import parse as urlparse |
| 11 | + # For Python 3.0 and later |
| 12 | + from urllib import parse as urlparse |
13 | 13 | except ImportError: |
14 | | - # Fall back to Python 2 |
15 | | - from urlparse import urlparse |
| 14 | + # Fall back to Python 2 |
| 15 | + from urlparse import urlparse |
16 | 16 |
|
17 | 17 |
|
18 | 18 | """ |
19 | 19 | APICONNECTOR Connection |
20 | 20 |
|
21 | 21 | """ |
| 22 | + |
| 23 | + |
22 | 24 | class Connection: |
23 | | - def __init__(self, config): |
24 | | - """ |
25 | | - Constructor |
26 | | - """ |
27 | | - self._config = config |
28 | | - |
29 | | - def call_raw_http(self, command, config = None): |
30 | | - |
31 | | - """ |
32 | | - Make a curl API call over HTTP(S) and returns the response as a string |
33 | | - """ |
34 | | - post = {} |
35 | | - if ('login' in self._config): |
36 | | - post['s_login'] = self._config['login'] |
37 | | - if ('password' in self._config): |
38 | | - post['s_pw'] = self._config['password'] |
39 | | - if ('entity' in self._config): |
40 | | - post['s_entity'] = self._config['entity'] |
41 | | - if ('user' in self._config): |
42 | | - post['s_user'] = self._config['user'] |
43 | | - if ('role' in self._config): |
44 | | - post['s_login'] = self._config['login'] + "!" + self._config['role'] |
45 | | - |
46 | | - post['s_command'] = apiconnector.util.command_encode(command) |
47 | | - post = urlparse.urlencode(post) |
48 | | - response = urlopen(self._config['url'], post.encode('UTF-8')) |
49 | | - content = response.read() |
50 | | - return content |
51 | | - |
52 | | - def call_raw(self, command, config = None): |
53 | | - """ |
54 | | - Make a curl API call and returns the response as a string |
55 | | - """ |
56 | | - return self.call_raw_http(command, config) |
57 | | - |
58 | | - def call(self, command, config = None): |
59 | | - """ |
60 | | - Make a curl API call and returns the response as a response object |
61 | | - """ |
62 | | - return Response(self.call_raw(command, config)) |
| 25 | + def __init__(self, config): |
| 26 | + """ |
| 27 | + Constructor |
| 28 | + """ |
| 29 | + self._config = config |
| 30 | + |
| 31 | + def call_raw_http(self, command, config=None): |
| 32 | + """ |
| 33 | + Make a curl API call over HTTP(S) and returns the response as a string |
| 34 | + """ |
| 35 | + post = {} |
| 36 | + if ('login' in self._config): |
| 37 | + post['s_login'] = self._config['login'] |
| 38 | + if ('password' in self._config): |
| 39 | + post['s_pw'] = self._config['password'] |
| 40 | + if ('entity' in self._config): |
| 41 | + post['s_entity'] = self._config['entity'] |
| 42 | + if ('user' in self._config): |
| 43 | + post['s_user'] = self._config['user'] |
| 44 | + if ('role' in self._config): |
| 45 | + post['s_login'] = self._config['login'] + "!" + self._config['role'] |
| 46 | + |
| 47 | + post['s_command'] = apiconnector.util.command_encode(command) |
| 48 | + post = urlparse.urlencode(post) |
| 49 | + response = urlopen(self._config['url'], post.encode('UTF-8')) |
| 50 | + content = response.read() |
| 51 | + return content |
| 52 | + |
| 53 | + def call_raw(self, command, config=None): |
| 54 | + """ |
| 55 | + Make a curl API call and returns the response as a string |
| 56 | + """ |
| 57 | + return self.call_raw_http(command, config) |
| 58 | + |
| 59 | + def call(self, command, config=None): |
| 60 | + """ |
| 61 | + Make a curl API call and returns the response as a response object |
| 62 | + """ |
| 63 | + return Response(self.call_raw(command, config)) |
0 commit comments