def create_page(req_path, content): fixed_req_path = urllib.unquote(req_path.strip()).replace(" ", "-").lower() content = web.utils.safestr(content) content = tracwiki2markdown.tracwiki2markdown(content) fixed_req_path = web.utils.safestr(fixed_req_path) params = urllib.urlencode({'content': content}) conn = httplib.HTTPConnection(conf.zwiki_host) conn.request("POST", "/%s?action=edit" % fixed_req_path, params) response = conn.getresponse() if response.status == httplib.NOT_FOUND: print 'response.status: NOT_FOUND' exit(-1) try: assert response.status == httplib.MOVED_PERMANENTLY assert response.reason == "Moved Permanently" except AssertionError: print "create `%s` failed" % req_path raise AssertionError data = response.read() assert data == 'None' conn.close()
def create_page(req_path, content): fixed_req_path = urllib.unquote(req_path.strip()).replace(" ", "-").lower() content = web.utils.safestr(content) content = tracwiki2markdown.tracwiki2markdown(content) fixed_req_path = web.utils.safestr(fixed_req_path) params = urllib.urlencode({'content': content}) conn = httplib.HTTPConnection(conf.zwiki_host) conn.request("POST", "/%s?action=update" % fixed_req_path, params) response = conn.getresponse() if response.status == httplib.NOT_FOUND: print 'response.status: NOT_FOUND' exit(-1) try: assert response.status == httplib.MOVED_PERMANENTLY assert response.reason == "Moved Permanently" except AssertionError: print "create `%s` failed" % req_path raise AssertionError data = response.read() assert data == 'None' conn.close()
def test2(): name = 'note/系统管理/代理' print "page_name:", name page = get_page_latest_rev_by_name(name) content = page["text"] content = tracwiki2markdown.tracwiki2markdown(content) with open('/tmp/t.html', 'w') as f: f.write(web.utils.safestr(content))