• 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

maintaince tools for sfjp magazine


Commit MetaInfo

Revisiona29d230f341c57d8c633d59860f696654c24a854 (tree)
Time2016-11-01 18:25:16
Authorhylom <hylom@hylo...>
Commiterhylom

Log Message

Merge branch 'master' of https://pf.osdn.jp/gitroot/h/hy/hylom/sfjpmag2ools

Conflicts:
sfjpmagclient/sfjpmagclient.py

Change Summary

Incremental Difference

--- a/sfjpmagclient/sfjpmagclient.py
+++ b/sfjpmagclient/sfjpmagclient.py
@@ -42,9 +42,12 @@ class CookieTransport(xmlrpclib.SafeTransport):
4242 return self.parse_response(response)
4343
4444 class MagClient(object):
45- def __init__(self, username, password, auth_user="", auth_pass=""):
45+ def __init__(self, username, password, auth_user="", auth_pass="", endpoint=None):
4646 self.username = username
4747 self.password = password
48+ if endpoint == None:
49+ endpoint = HOST_PATH
50+
4851 if auth_user and auth_pass:
4952 # self.uri = "http://{username}:{password}@{url}".format(username=auth_user, password=auth_pass, url=HOST_PATH)
5053 self.uri = "https://%s:%s@%s" % (auth_user, auth_pass, HOST_PATH)
@@ -80,6 +83,23 @@ class MagClient(object):
8083 self.password,
8184 content)
8285
86+ def upload_media(self, filename, data, mimetype, overwrite=True, parent=None):
87+ proxy = self._get_proxy()
88+ post_data = {
89+ "name": filename,
90+ "type": mimetype,
91+ "bits": xmlrpclib.Binary(data),
92+ "overwrite": overwrite
93+ }
94+
95+ if parent != None:
96+ post_data["post_id"] = parent
97+
98+ return proxy.wp.uploadFile(self._get_blog_id(),
99+ self.username,
100+ self.password,
101+ post_data)
102+
83103 def get_users_blogs(self):
84104 proxy = self._get_proxy()
85105 return proxy.wp.getUsersBlogs(self.username, self.password)
Binary files /dev/null and b/test/sample.png differ
--- a/test/test_sfjpmagclient.py
+++ b/test/test_sfjpmagclient.py
@@ -9,10 +9,11 @@ from sfjpmagclient import MagClient
99
1010 username = config["username"]
1111 password = config["password"]
12-auth_user = config["auth_user"]
13-auth_pass = config["auth_pass"]
12+auth_user = config.get("auth_user", "")
13+auth_pass = config.get("auth_pass", "")
14+endpoint = config["endpoint"]
1415
15-c = MagClient(username, password, auth_user, auth_pass)
16+c = MagClient(username, password, auth_user, auth_pass, endpoint)
1617 ret = c.get_users_blogs()
1718 print ret
1819
--- /dev/null
+++ b/test/test_upload_media.py
@@ -0,0 +1,36 @@
1+#!/usr/bin/python
2+# -*- coding: utf-8 -*-
3+
4+import json
5+import sys
6+import xmlrpclib
7+sys.path.append('.')
8+
9+from testconfig import config
10+from sfjpmagclient import MagClient
11+
12+username = config["username"]
13+password = config["password"]
14+auth_user = config.get("auth_user", "")
15+auth_pass = config.get("auth_pass", "")
16+endpoint = config["endpoint"]
17+
18+POST_ID = 1
19+TEST_FILE = "test/sample.png"
20+
21+c = MagClient(username, password, auth_user, auth_pass, endpoint)
22+
23+f = open(TEST_FILE, "r")
24+test_data = f.read()
25+f.close()
26+
27+try:
28+ ret = c.upload_media("This_is_test.png", test_data, "image/png",
29+ True, 1)
30+except xmlrpclib.Fault, e:
31+ for k in e.__dict__:
32+ print k, e.__getattribute__(k)
33+ sys.exit(-1)
34+print ret
35+
36+