def json_response(serializable, _disable_cors=False, *args, **kw): ''' Serializes a json objects and returns a werkzeug Response object with the serialized value as the response body and Content-Type: application/json. :param serializable: A json-serializable object Any extra arguments and keyword arguments are passed to the Response.__init__ method. ''' response = wz_Response(json.dumps(serializable), *args, content_type='application/json', **kw) if not _disable_cors: cors_headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With' } for key, value in cors_headers.iteritems(): response.headers.set(key, value) return response
def form_response(data, *args, **kwargs): """ Responds using application/x-www-form-urlencoded and returns a werkzeug Response object with the data argument as the body and 'application/x-www-form-urlencoded' as the Content-Type. Any extra arguments and keyword arguments are passed to the Response.__init__ method. """ response = wz_Response(data, content_type="application/x-www-form-urlencoded", *args, **kwargs) return response
def form_response(data, *args, **kwargs): """ Responds using application/x-www-form-urlencoded and returns a werkzeug Response object with the data argument as the body and 'application/x-www-form-urlencoded' as the Content-Type. Any extra arguments and keyword arguments are passed to the Response.__init__ method. """ response = wz_Response( data, content_type="application/x-www-form-urlencoded", *args, **kwargs ) return response
def json_response(serializable, _disable_cors=False, *args, **kw): ''' Serializes a json objects and returns a werkzeug Response object with the serialized value as the response body and Content-Type: application/json. :param serializable: A json-serializable object Any extra arguments and keyword arguments are passed to the Response.__init__ method. ''' response = wz_Response(json.dumps(serializable), *args, content_type='application/json', **kw) if not _disable_cors: cors_headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'} for key, value in cors_headers.iteritems(): response.headers.set(key, value) return response
def get_podcasts(request): _log.info(request.url) username = request.url[request.url.find("u/")+2:request.url.rfind("/podcast")] _log.info(username) #all according to a rss feed for a itunes podcast NSMAP = {"atom":"http://www.w3.org/2005/Atom", "itunes":"http://www.itunes.com/dtds/podcast-1.0.dtd", "cc":"http://web.resource.org/cc/", "media":"http://search.yahoo.com/mrss/", "rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns"} xml = etree.Element("rss", version="2.0",nsmap=NSMAP) channel = etree.Element("channel") atom = etree.Element("{%s}link"%NSMAP['atom'],href="s", rel="self", type="application/rss+xml") channel.append(atom) title = etree.Element("title") title.text = "SAM's Podcast" channel.append(title) #not sure what these times are actually supposed to be pubdate = etree.Element("pubDate") lastBuildDate = etree.Element("lastBuildDate") t = datetime.datetime.fromtimestamp(time.time()).strftime('%a, %d %b %Y %T')+'+0000' pubdate.text = t lastBuildDate.text = t channel.append(pubdate) channel.append(lastBuildDate) generator = etree.Element("generator") generator.text = "GNU MediaGoblin" channel.append(generator) link = etree.Element("link") link.text = "http://google.com"#hostname of the instance channel.append(link) language = etree.Element("language") language.text = "en" channel.append(language) copyright = etree.Element("copyright")#some CDATA nonsense going on here copyright.text = "GPL" channel.append(copyright) docs = etree.Element("docs") docs.text = ""#hostname goes here channel.append(docs) managingEditor = etree.Element("managingEditor") managingEditor.text = "ss" #email for user or similar channel.append(managingEditor) description = etree.Element("description") description.text = "Description" #description goes here channel.append(description) image = etree.Element("image") url = etree.Element("url") url.text = "URL" #url goes here img_title = etree.Element("title") img_title.text = "TITLE" #title goes here link = etree.Element("link") link.text = "URL" #same as link? image.append(url) image.append(img_title) image.append(link) channel.append(image) author = etree.Element("{%s}author"%NSMAP['itunes']) author.text = "AUTHOR" #author/user here channel.append(author) keywords = etree.Element("{%s}keywords"%NSMAP['itunes']) keywords.text = "" #use tags maybe? channel.append(keywords) category = etree.Element("{%s}category"%NSMAP['itunes'],text="Cats") channel.append(category) ituneimage = etree.Element("{%s}image"%NSMAP['itunes'], href="")#image url channel.append(ituneimage) #explicit = etree.Element("{%s}explicit xml.append(channel) # _log.info(tostring(xml,xml_declaration=True)) return wz_Response(tostring(xml, xml_declaration=True, pretty_print=True))