def POST(self, service): username = authenticate_user(web) # If username is None: return wsse_auth error for DIR in [RAWPOSTDATA_DIR, CACHE_DIR]: if os.path.isdir(DIR) == False: os.makedirs(DIR) post_file = shareonline._save_post_data(web.data(), RAWPOSTDATA_DIR, username + '-request') contentfile_name = os.path.basename(post_file) #contentfile_body = os.path.splitext(post_file)[0] data = shareonline._parse_request_xml(web.data()) if 'filedata' in data: if 'filetype' in data: content_filepath = get_filename(post_file, data) with open(content_filepath, 'wb') as f: f.write(data['filedata']) del data['filedata'] print data else: # read original post print data post = os.path.join(RAWPOSTDATA_DIR, data['uid']) with open(post, 'rb') as f: postdata = f.read() data = shareonline._parse_request_xml(postdata) del data['filedata'] web.header('Content-Type', 'application/atom+xml; charset=UTF-8') data['id'] = contentfile_name data['link'] = "/entry/" + contentfile_name #print data entry_xml = shareonline.create_entry(data) #print entry_xml web.Created() shareonline._save_post_data(entry_xml, RAWPOSTDATA_DIR, username + '-response') return entry_xml
def GET(self, postfile): post = os.path.join(RAWPOSTDATA_DIR, postfile) with open(post, 'rb') as f: postdata = f.read() data = shareonline._parse_request_xml(postdata) web.header('Content-Type', data['filetype']) return data['filedata']
def GET(self, postfile): post = os.path.join(RAWPOSTDATA_DIR, postfile) with open(post, 'rb') as f: postdata = f.read() data = shareonline._parse_request_xml(postdata) html = [] html.append(u"""<h1>%(summary)s</h1>""" % (data)) if data['filetype'].startswith('image'): html.append(u"""<img src="/file/%s" width="400" alt=""/>""" % (postfile)) web.header('Content-Type', 'text/html; charset=UTF-8') return u"\n".join(html)
def GET(self): posts = [] for post in glob.glob(RAWPOSTDATA_DIR + '/*.xml'): with open(post, 'rb') as f: postdata = f.read() data = shareonline._parse_request_xml(postdata) if 'filetype' in data: posts.append(u"<a href='/entry/%s'>%s</a>" % (os.path.basename(post), data['summary'])) if 'filetype' in data and data['filetype'].startswith('image'): posts.append(u"""<img src="/file/%s" width="100" alt=""/>""" % (os.path.basename(post))) #posts.append(u"<a href='/entry/%s'>%s</a>" % (os.path.basename(post), data['summary'])) web.header('Content-Type', 'text/html; charset=UTF-8') return u"<br/>".join(posts)
def GET(self): host = _get_host(web) posts = ['<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">'] # Read all raw posts to a list postfiles = glob.glob(RAWPOSTDATA_DIR + '/*.xml') postfiles.sort() postfiles.reverse() for post in postfiles: with open(post, 'rb') as f: postdata = f.read() data = shareonline._parse_request_xml(postdata) data['host'] = host data['id'] = os.path.basename(post) if 'filedata' not in data: continue # this was not a post containing filedata posts.append(u"""<entry><title>%(summary)s</title> <link href="%(host)s/entry/%(id)s" rel="alternate"></link> <updated>%(issued)s</updated> <author><name>demo</name><uri>http://www.example.com/</uri></author> <id>%(host)s/entry/%(id)s</id> <summary type="html"></summary></entry>""" % (data)) posts.append(u"</feed>") web.header('Content-Type', 'application/atom+xml; charset=UTF-8') return u"\n".join(posts)