• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

PythonからElixir Reportのレポートサーバーにアクセスするサンプルコード


Commit MetaInfo

Revisiond3b1da552d30f2c903820f7ebbd8bccf486b63f8 (tree)
Time2014-12-03 01:19:27
AuthorHiromichi Matsushima <hylom@Hiro...>
CommiterHiromichi Matsushima

Log Message

code cleaning

Change Summary

Incremental Difference

--- a/report_server.py
+++ b/report_server.py
@@ -17,6 +17,7 @@ class ReportServer:
1717 self.opener = None
1818
1919 def open_path(self, path, param=None):
20+ "指定したパスにリクエストを投げる"
2021 if self.opener == None:
2122 self.login()
2223
@@ -28,6 +29,7 @@ class ReportServer:
2829 return resp
2930
3031 def repository(self):
32+ "リポジトリ一覧を取得する"
3133 path = '/repository?mode=xml'
3234 resp = self.open_path(path)
3335 if resp.code == 200:
@@ -36,6 +38,7 @@ class ReportServer:
3638 return None
3739
3840 def data(self, path, params={}):
41+ "データソースからデータをXML形式で取得する"
3942 param = params.copy()
4043 param["mime-type"] = "text/xml"
4144 resp = self.open_path(path, param)
@@ -45,6 +48,7 @@ class ReportServer:
4548 return None
4649
4750 def login(self):
51+ "ログイン処理を行う"
4852 # 初めにCookieを取得する
4953 if self.opener == None:
5054 path = '/'
@@ -55,21 +59,20 @@ class ReportServer:
5559 cookies.extract_cookies(resp, req)
5660 self.cookies = cookies
5761
58- # set to use cookies
62+ # 取得したCookieを使用する
5963 self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookies))
6064
61- # request with session cookie
65+ # ログインリクエストを投げる
6266 path = '/login.html'
6367 param = {
6468 "username": self.user,
6569 "password": self.password
6670 }
67- # url = self.path_to_url(path)
68- # resp = self.opener.open(url, urllib.urlencode(param))
6971 resp = self.open_path(path, param)
7072 return resp.code
7173
7274 def logout(self):
75+ "ログアウト処理を行う"
7376 if self.opener == None:
7477 return 200
7578
@@ -78,6 +81,7 @@ class ReportServer:
7881 return resp.code
7982
8083 def path_to_url(self, path):
84+ "パスをURLに変換する"
8185 t = (self.scheme,
8286 '{0}:{1}'.format(self.host, self.port),
8387 path,