Skip to content

Commit 95e0199

Browse files
added pep8 scripts and code refactoring
1 parent 01fe1e0 commit 95e0199

File tree

7 files changed

+464
-440
lines changed

7 files changed

+464
-440
lines changed

hexonet/apiconnector/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
__version__ = '1.0.0'
55
name = "apiconnector"
66

7-
def connect(login=None, password=None, url=None, entity=None, user=None, role=None, config=None):
8-
"""
9-
Returns an instance of apiconnector.Connection
10-
"""
117

12-
if config == None:
13-
config = {}
14-
if login != None:
15-
config['login'] = login
16-
if password != None:
17-
config['password'] = password
18-
if url != None:
19-
config['url'] = url
20-
if entity != None:
21-
config['entity'] = entity
22-
if user != None:
23-
config['user'] = user
24-
if role != None:
25-
config['role'] = role
26-
return Connection(config)
8+
def connect(login=None, password=None, url=None, entity=None, user=None, role=None, config=None):
9+
"""
10+
Returns an instance of apiconnector.Connection
11+
"""
2712

13+
if config is None:
14+
config = {}
15+
if login is not None:
16+
config['login'] = login
17+
if password is not None:
18+
config['password'] = password
19+
if url is not None:
20+
config['url'] = url
21+
if entity is not None:
22+
config['entity'] = entity
23+
if user is not None:
24+
config['user'] = user
25+
if role is not None:
26+
config['role'] = role
27+
return Connection(config)

hexonet/apiconnector/connection.py

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,56 @@
88
# Fall back to Python 2's urllib2
99
from urllib2 import urlopen
1010
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
1313
except ImportError:
14-
# Fall back to Python 2
15-
from urlparse import urlparse
14+
# Fall back to Python 2
15+
from urlparse import urlparse
1616

1717

1818
"""
1919
APICONNECTOR Connection
2020
2121
"""
22+
23+
2224
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

Comments
 (0)