Пример #1
0
    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()
Пример #2
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()
Пример #3
0
    def GET(self, selector):
        
        args = web.input()
        locale = str(args.get('locale'))
        if locale not in cc.license.locales():
            locale = 'en'
        
        try:
            assert selector != 'software'
            if selector == 'publicdomain': selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        except:
            return api_exceptions.invalidclass()

        answers = support.build_answers_xml(lclass, args)
        
        try:
            support.validate_answers(lclass, answers)
        except AssertionError, e:
            return api_exceptions.invalidanswer()
Пример #4
0
    def GET(self, selector):

        args = web.input()
        locale = str(args.get('locale'))
        if locale not in cc.license.locales():
            locale = 'en'

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

        answers = support.build_answers_xml(lclass, args)

        try:
            support.validate_answers(lclass, answers)
        except AssertionError, e:
            return api_exceptions.invalidanswer()
Пример #5
0
class issue:
    @render_as('xml')
    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()

        # converts the answer tree into a dictionary
        # this will trim off any superfluous args in answers
        # it will also perform validation to ensure that the required
        # questions are answered with acceptable value

        try:
            support.validate_answers(lclass, answers)
        except AssertionError, e:
            return api_exceptions.invalidanswer()