def GET(self): triples = self._triples(web.input().get('url','')) callback = web.input().get('callback') if callback: return "%s(%s)" % (callback, renderer.response(triples)) else: return renderer.response(triples)
class DeedReferer(RefererHandler): def GET(self): """ Scrape and process the referer's metadata. """ try: self.scrape_referer('deed') except Exception, e: return renderer.response(dict(_exception=str(e))) # if there's a callback specified, wrap the results as a js function call callback = web.input().get('callback') if callback: return "%s(%s)" % (callback, renderer.response(self.results())) else: return renderer.response(self.results())
class PublicDomainReferer(RefererHandler): """ Request handler for the PD Mark deeds and CC0. The PD Mark makes a single GET on its page load, requesting the deedscraper to scrape the referring URI for any RDFa metadata relevant to the marking of a public domain or CC0 work. """ def GET(self): """ Scrape and process the referer's metadata. """ try: self.scrape_referer('pddeed') except Exception, e: return renderer.response(dict(_exception=str(e))) callback = web.input().get('callback') if callback: return "%s(%s)" % (callback, renderer.response(self.results())) else: return renderer.response(self.results())
def GET(self): # this is required argument url = web.input().get('url') license_uri = web.input().get('license_uri') or \ web.ctx.env.get('HTTP_REFERER') # fail on missing arguments - TODO -- FAIL, REALLY? if license_uri is None or url is None or \ not license_uri.startswith('http://creativecommons.org/'): return renderer.response(dict( _exception='A license URI and a subject URI must be provided.')) # get a cc license object # cclicense = metadata.LicenseFactory.from_uri(license_uri) try: if 'deed' in license_uri: stripped_uri = license_uri[:(license_uri.rindex('/')+1)] cclicense = cc.license.by_uri(str(stripped_uri)) else: cclicense = cc.license.by_uri(str(license_uri)) except cc.license.CCLicenseError, e: return renderer.response(dict(_exception=unicode(e)))
def GET(self): """ Scrape and process the referer's metadata. """ try: self.scrape_referer('pddeed') except Exception, e: return renderer.response(dict(_exception=str(e)))
class Referer(ScrapeRequestHandler): # maintain a cache of the deeds' lang codes deed_langs = {} def GET(self): # this is required argument url = web.input().get('url') license_uri = web.input().get('license_uri') or \ web.ctx.env.get('HTTP_REFERER') # fail on missing arguments - TODO -- FAIL, REALLY? if license_uri is None or url is None or \ not license_uri.startswith('http://creativecommons.org/'): return renderer.response(dict( _exception='A license URI and a subject URI must be provided.')) # get a cc license object # cclicense = metadata.LicenseFactory.from_uri(license_uri) try: if 'deed' in license_uri: stripped_uri = license_uri[:(license_uri.rindex('/')+1)] cclicense = cc.license.by_uri(str(stripped_uri)) else: cclicense = cc.license.by_uri(str(license_uri)) except cc.license.CCLicenseError, e: return renderer.response(dict(_exception=unicode(e))) triples = self._first_pass(url, 'deed') subject = metadata.extract_licensed_subject(url, license_uri, triples) triples = self._triples(url=url, action='deed', depth=1, sink=triples['sink'], subjects=triples['subjects'], redirects=triples['redirects']) if '_exception' in triples['subjects']: # should probably report the error but for now... return renderer.response(dict( _exception=triples['triples']['_exception'])) # deeds include a lang attribute in <html> if license_uri not in self.deed_langs.keys(): lang = support.get_document_locale(license_uri) if lang is None: # didn't find a lang attribute in the html lang = web.input().get('lang', 'en') # cache the lang code based on the deed's uri self.deed_langs[license_uri] = lang # prepare to render messages for this lang renderer.set_locale(self.deed_langs[license_uri]) # returns dictionaries with values to cc-relevant triples attrib = metadata.attribution(subject, triples) regist = metadata.registration(subject, triples, license_uri) mPerms = metadata.more_permissions(subject, triples) # check if a dc:title exists title = metadata.get_title(subject, triples) results = { 'attribution': { 'details': renderer.render( 'attribution_details.html', { 'subject': subject, 'license': cclicense, 'title': title, 'attributionName': attrib['attributionName'], 'attributionURL': attrib['attributionURL'], }), 'marking': renderer.render( 'attribution_marking.html', { 'subject': subject, 'license': cclicense, 'title': title, 'attributionName': attrib['attributionName'], 'attributionURL': attrib['attributionURL'], }), }, 'registration': renderer.render('registration.html', regist), 'more_permissions': renderer.render('more_permissions.html', dict(subject=subject, **mPerms)), } return renderer.response(results)
def GET(self): triples = self._triples(web.input().get('url','')) return renderer.response(triples)