def spellcheck(request):
try:<EOL><INDENT>raw = request.raw_post_data<EOL>input = json.loads(raw)<EOL>id = input['<STR_LIT:id>']<EOL>method = input['<STR_LIT>']<EOL>params = input['<STR_LIT>']<EOL>lang = params[<NUM_LIT:0>]<EOL>arg = params[<NUM_LIT:1>]<EOL>if not enchant.dict_exists(str(lang)):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % lang)<EOL><DEDENT>checker = enchant.Dict(str(lang))<EOL>if method == '<STR_LIT>':<EOL><INDENT>result = [word for word in arg if word and not checker.check(word)]<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>result = checker.suggest(arg)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % method)<EOL><DEDENT>output = {<EOL>'<STR_LIT:id>': id,<EOL>'<STR_LIT:result>': result,<EOL>'<STR_LIT:error>': None,<EOL>}<EOL><DEDENT>except Exception:<EOL><INDENT>return HttpResponse("<STR_LIT>")<EOL><DEDENT>return HttpResponse(json.dumps(output),<EOL>content_type='<STR_LIT:application/json>')<EOL>
Returns a HttpResponse that implements the TinyMCE spellchecker protocol.