Skip to content

Commit 38b5ffb

Browse files
committed
Added comments.
1 parent 99a2497 commit 38b5ffb

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

python/chapter-9/user_manager.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
###############################################
1515
import sys, json, httplib, base64
1616

17-
base_path = "/api/users"
18-
1917
#/(um.1) Assign arguments
2018
if len(sys.argv) < 5:
21-
print "USAGE: user_vhost_manager.py server_name:port auth_user auth_pass",
22-
print "ACTION RESOURCE [PARAMS...]"
19+
print "USAGE: user_manager.py server_name:port auth_user auth_pass",
20+
print "ACTION [PARAMS...]"
2321
sys.exit(1)
2422

2523
server, port = sys.argv[1].split(":")
@@ -32,10 +30,9 @@
3230
else:
3331
res_params = []
3432

35-
#/(um.2) Connect to server
36-
conn = httplib.HTTPConnection(server, port)
33+
#/(um.2) Build API path
34+
base_path = "/api/users"
3735

38-
#/(um.3) Build API path
3936
if action == "list":
4037
path = base_path
4138
method = "GET"
@@ -50,14 +47,15 @@
5047
method = "GET"
5148

5249

53-
#/(um.4) Build JSON arguments
50+
#/(um.3) Build JSON arguments
5451
json_args = ""
5552
if action == "create":
5653
json_args = {"password" : res_params[1],
5754
"administrator" : json.loads(res_params[2])}
5855
json_args = json.dumps(json_args)
5956

60-
#/(um.5) Issue API request
57+
#/(um.4) Issue API request
58+
conn = httplib.HTTPConnection(server, port)
6159
credentials = base64.b64encode("%s:%s" % (username, password))
6260
conn.request(method, path, json_args,
6361
{"Content-Type" : "application/json",
@@ -68,24 +66,25 @@
6866
response.read())
6967
sys.exit(2)
7068

71-
#/(um.6) Parse and display response
69+
#/(um.5) Parse and display response
7270
resp_payload = response.read()
7371
if action in ["list", "show"]:
7472
resp_payload = json.loads(resp_payload)
7573

76-
#/(um.7) Process 'list' results
74+
#/(um.6) Process 'list' results
7775
if action == "list":
7876
print "Count: %d" % len(resp_payload)
7977
for user in resp_payload:
8078
print "User: %(name)s" % user
8179
print "\tPassword: %(password_hash)s" % user
8280
print "\tAdministrator: %(administrator)s\n" % user
8381

84-
#/(um.8) Process 'show' results
82+
#/(um.7) Process 'show' results
8583
if action == "show":
8684
print "User: %(name)s" % resp_payload
8785
print "\tPassword: %(password_hash)s" % resp_payload
8886
print "\tAdministrator: %(administrator)s\n" % resp_payload
87+
#/(um.8) Create and delete requests have no result.
8988
else:
9089
print "Completed request!"
9190

0 commit comments

Comments
 (0)