Example #1
0
 def getCharacterCodesAndNames(self):
     input = h.NFD(dict(request.params)['input'])
     response.headers['Content-Type'] = 'application/json'
     return json.dumps(
         (h.getUnicodeCodePoints(input), h.getUnicodeNames(input)))
Example #2
0
            result = schema.to_python(values)
        except Invalid, e:
            result = {'valid': False, 'errors': e.unpack_errors()}
        else:
            # Count all the characters tokens by type
            result = {}
            forms = meta.Session.query(model.Form).all()
            field = values['field']
            fieldBag = ''.join([getattr(f, field) for f in forms
                                if getattr(f, field)])
            for c in fieldBag:
                try:
                    result[c] += 1
                except KeyError:
                    result[c] = 1

            # Sort the tokens by count in descending order
            result = [[k, result[k]] for k in result]
            result = sorted(result, key=lambda x: x[1], reverse=True)

            # Add some character information
            result = [[c[0], c[1], h.getUnicodeNames(c[0]),
                       h.getUnicodeCodePoints(c[0]), ud.normalize('NFC', c[0]),
                       h.getUnicodeCodePoints(ud.normalize('NFC', c[0]))]
                     for c in result]

            result = {'valid': True, 'response': result}

        response.headers['Content-Type'] = 'application/json'
        return json.dumps(result)
Example #3
0
 def getCharacterCodesAndNames(self):
     input = h.NFD(dict(request.params)['input'])
     response.headers['Content-Type'] = 'application/json'
     return json.dumps(
         (h.getUnicodeCodePoints(input), h.getUnicodeNames(input)))
Example #4
0
        else:
            # Count all the characters tokens by type
            result = {}
            forms = meta.Session.query(model.Form).all()
            field = values['field']
            fieldBag = ''.join(
                [getattr(f, field) for f in forms if getattr(f, field)])
            for c in fieldBag:
                try:
                    result[c] += 1
                except KeyError:
                    result[c] = 1

            # Sort the tokens by count in descending order
            result = [[k, result[k]] for k in result]
            result = sorted(result, key=lambda x: x[1], reverse=True)

            # Add some character information
            result = [[
                c[0], c[1],
                h.getUnicodeNames(c[0]),
                h.getUnicodeCodePoints(c[0]),
                ud.normalize('NFC', c[0]),
                h.getUnicodeCodePoints(ud.normalize('NFC', c[0]))
            ] for c in result]

            result = {'valid': True, 'response': result}

        response.headers['Content-Type'] = 'application/json'
        return json.dumps(result)