示例#1
0
    def POST(self, selector):

        lclass = None
        if selector != 'software':
            if selector == 'publicdomain':
                selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        if not lclass:
            return api_exceptions.invalidclass()

        answers_xml = web.input().get('answers')
        if not answers_xml:
            return api_exceptions.missingparam('answers')

        try:
            if selector == 'zero':
                answers_xml = answers_xml.replace(
                    '<license-publicdomain>',
                    '<license-zero>').replace('</license-publicdomain>',
                                              '</license-zero>')

            # parse the answers argument into an xml tree
            answers = ET.parse(StringIO(answers_xml))

        except ET.XMLSyntaxError, e:
            return api_exceptions.invalidanswer()
示例#2
0
文件: license.py 项目: doigoid/cc.api
    def POST(self, selector):

        try:
            assert selector != 'software'
            if selector == 'publicdomain':
                lclass = cc.license.selectors.choose('zero')
            else:
                lclass = cc.license.selectors.choose(selector)
        except:
            return api_exceptions.invalidclass()

        if not web.input().get('answers'):
            return api_exceptions.missingparam('answers')

        try:
            answers_xml = web.input().get('answers')
            if selector == 'publicdomain':
                answers_xml = answers_xml.replace(
                    '<license-publicdomain>',
                    '<license-zero>').replace(
                    '</license-publicdomain>',
                    '</license-zero>')
            
            # parse the answers argument into an xml tree
            answers = ET.parse(StringIO(answers_xml))
            
        except ET.XMLSyntaxError, e:
            return api_exceptions.invalidanswer()
示例#3
0
    def GET(self, locale=None, license_uri=None):
        """ Accepts a license uri as an argument and will return
        the RDF and RDFa of a licnsee """
        locale = locale or web.input().get('locale', 'en')
        license_uri = license_uri or web.input().get('license-uri')
        
        if not license_uri:
            return api_exceptions.missingparam('license-uri')

        license = cc.license.by_uri(str(license_uri))    
        if not license:
            return api_exceptions.invaliduri()
        
        return support.build_results_tree(license, locale=locale)
示例#4
0
文件: details.py 项目: doigoid/cc.api
    def GET(self, locale=None, license_uri=None):
        """ Accepts a license uri as an argument and will return
        the RDF and RDFa of a licnsee """
        locale = locale or web.input().get('locale', 'en')
        license_uri = license_uri or web.input().get('license-uri')
        
        if not license_uri:
            return api_exceptions.missingparam('license-uri')

        try:
            l = cc.license.by_uri(str(license_uri))
        except cc.license.CCLicenseError:
            return api_exceptions.invaliduri()
        
        return support.build_results_tree(l, locale=locale)