Best JavaScript code snippet using argos
views.py
Source:views.py
1# Create your views here.2from django.shortcuts import render_to_response, get_object_or_4043from django.core.context_processors import csrf4from django.utils.encoding import smart_str5from django.template import RequestContext, loader,Context6from django.forms.formsets import formset_factory, BaseFormSet7from django.core.management.base import BaseCommand, CommandError8from django.forms.models import inlineformset_factory, BaseInlineFormSet9from django.http import HttpResponse, HttpResponseRedirect10from django.contrib.auth.decorators import login_required11from qbank.forms import *12from qbank.models import *13import mimetypes14from django.core.servers.basehttp import FileWrapper15import csv16import os17#@login_required18def index(request):19 # This class is used to make empty formset forms required20 class RequiredFormSet(BaseFormSet):21 def __init__(self, *args, **kwargs):22 super(RequiredFormSet, self).__init__(*args, **kwargs)23 for form in self.forms:24 form.empty_permitted = True25 HintFormSet = formset_factory(HintForm, max_num = 10, formset = RequiredFormSet)26 VariableFormSet = formset_factory(VariableForm, max_num = 10, formset = RequiredFormSet)27 ChoiceFormSet = formset_factory(ChoiceForm, max_num = 10, formset = RequiredFormSet)28 ScriptFormSet = formset_factory(ScriptForm, max_num = 10, formset = RequiredFormSet)29 if request.method == 'POST': # If the form has been submitted...30 problem_form = ProblemForm(request.POST)31 problem_template_form = ProblemTemplateForm(request.POST, prefix='template')32 answer_form = AnswerForm(request.POST, prefix='answer')33 hint_formset = HintFormSet(request.POST, request.FILES, prefix='hints')34 variable_formset = VariableFormSet(request.POST, request.FILES, prefix='variables')35 choice_formset = ChoiceFormSet(request.POST, request.FILES, prefix='choices')36 script_formset = ScriptFormSet(request.POST, request.FILES, prefix='scripts')37 if problem_form.is_valid() and problem_template_form.is_valid() and choice_formset.is_valid() and hint_formset.is_valid() and variable_formset.is_valid() and answer_form.is_valid() and script_formset.is_valid():38 problem = problem_form.save()39 problem_template = problem_template_form.save(commit = False)40 problem_template.problem = problem41 problem_template.save()42 answer = answer_form.save(commit = False)43 answer.problem = problem44 answer.save()45 for form in hint_formset.forms:46 hint = form.save(commit = False)47 hint.problem = problem48 hint.save()49 for form in variable_formset.forms:50 variable = form.save(commit = False)51 variable.problem = problem52 variable.save()53 for form in script_formset.forms:54 script = form.save(commit = False)55 script.problem = problem56 script.save()57 for form in choice_formset.forms:58 choice = form.save(commit = False)59 choice.problem = problem60 choice.save() # Redirect to a 'success' page61 return HttpResponseRedirect('/qbank/problems/')62 else: 63 problem_form = ProblemForm()64 choice_formset = ChoiceFormSet(prefix='choices')65 problem_template_form = ProblemTemplateForm(prefix='template')66 answer_form = AnswerForm(prefix='answer')67 script_formset = ScriptFormSet(prefix='scripts')68 variable_formset = VariableFormSet(prefix='variables')69 hint_formset = HintFormSet(prefix='hints')70 c = {'problem_form' : problem_form,71 'choice_formset' : choice_formset,72 'problem_template_form' : problem_template_form,73 'answer_form': answer_form,74 'variable_formset' : variable_formset,75 'script_formset' : script_formset,76 'hint_formset' : hint_formset,77 }78 c.update(csrf(request))79 return render_to_response('add.html', c)80#@login_required81def edit(request, problem_id):82 problem = get_object_or_404(Problem, id=problem_id)83 class RequiredFormSet(BaseFormSet):84 def __init__(self, *args, **kwargs):85 super(RequiredFormSet, self).__init__(*args, **kwargs)86 for form in self.forms:87 form.empty_permitted = True88 class MyInline(BaseInlineFormSet): 89 def __init__(self, *args, **kwargs): 90 super(MyInline, self).__init__(*args, **kwargs) 91 self.can_delete = False 92 93 94 maxpt = max(0, len(ProblemTemplate.objects.filter(problem=problem)))95 ProblemTemplateInlineFormSet = inlineformset_factory(Problem, ProblemTemplate, max_num=maxpt)96 maxa = max(0, len(Answer.objects.filter(problem=problem)))97 AnswerInlineFormSet = inlineformset_factory(Problem, Answer, max_num =maxa)98 maxv = max(0, len(Variable.objects.filter(problem=problem)))99 VariableInlineFormSet = inlineformset_factory(Problem, Variable, max_num=maxv)100 maxc = max(0, len(CommonIntroduction.objects.filter(problem=problem)))101 CommonIntroductionFormSet = inlineformset_factory(Problem, CommonIntroduction, max_num =maxc )102 maxch = max(0, len(Choice.objects.filter(problem=problem)))103 ChoiceInlineFormSet = inlineformset_factory(Problem, Choice, max_num=maxch, formset=MyInline)104 maxh = max(0, len(Hint.objects.filter(problem=problem)))105 HintInlineFormSet = inlineformset_factory(Problem, Hint, max_num=maxh)106 maxs = max(0, len(Script.objects.filter(problem=problem)))107 ScriptInlineFormSet = inlineformset_factory(Problem, Script, max_num=maxs)108 if request.method == 'POST':109 problem_form =ProblemForm(request.POST, instance=problem)110 problem_template_formset = ProblemTemplateInlineFormSet(request.POST,request.FILES, instance=problem, prefix='templates')111 common_introduction_formset = CommonIntroductionForm(request.POST, request.FILES, prefix='common_intro', instance =problem)112 answer_formset = AnswerInlineFormSet(request.POST, instance=problem, prefix='answer')113 hint_formset = HintInlineFormSet(request.POST, request.FILES, instance=problem, prefix='hints')114 choice_formset = ChoiceInlineFormSet(request.POST, request.FILES, instance=problem, prefix='choices')115 script_formset = ScriptInlineFormSet(request.POST, request.FILES, instance=problem, prefix='scripts')116 variable_formset = VariableInlineFormSet(request.POST, request.FILES,instance=problem, prefix='variables')117 118 if problem_form.is_valid() and variable_formset.is_valid() and problem_template_formset.is_valid() and choice_formset.is_valid() and hint_formset.is_valid() and answer_formset.is_valid() and script_formset.is_valid() and common_introduction_formset.is_valid() :119 problem = problem_form.save()120 answer_formset.save(commit = False)121 common_introduction_formset.save(commit = False)122 problem_template_formset.save(commit =False)123 variable_formset.save(commit = False)124 for form in hint_formset.forms:125 hint = form.save(commit = False)126 hint.problem = problem127 hint.save()128 for form in script_formset.forms:129 script = form.save(commit = False)130 script.problem = problem131 script.save()132 for form in choice_formset.forms:133 choice = form.save(commit = False)134 choice.problem = problem135 choice.save()136 return HttpResponseRedirect('/qbank/problems/')137 else:138 problem_form = ProblemForm(instance=problem)139 140 problem_template_formset = ProblemTemplateInlineFormSet( instance=problem, prefix='templates')141 choice_formset = ChoiceInlineFormSet(instance=problem, prefix='choices')142 143 answer_formset = AnswerInlineFormSet(instance=problem, prefix='answer')144 145 script_formset = ScriptInlineFormSet(instance=problem, prefix='scripts')146 variable_formset = VariableInlineFormSet(instance=problem, prefix='variables')147 common_introduction_formset = CommonIntroductionFormSet(instance=problem, prefix='common_intro')148 hint_formset = HintInlineFormSet( instance=problem, prefix='hints')149 150 c = {151 'problem_form' : problem_form,152 'choice_formset' : choice_formset,153 'problem_template_formset' :problem_template_formset,154 'answer_formset': answer_formset,155 'variable_formset' : variable_formset,156 'script_formset' : script_formset,157 'common_introduction_formset' : common_introduction_formset,158 'hint_formset' : hint_formset, 159 }160 c.update(csrf(request))161 return render_to_response('edit.html', c)162def splashpage(request):163 return HttpResponseRedirect('splashpage')164def problems(request):165 problems = Problem.objects.all()166 context = Context({'problems':problems})167 return render_to_response('problems.html', context, context_instance=RequestContext(request))168def ka_error(request, problem_id):169 problems = Problem.objects.all()170 p = get_object_or_404(Problem, id=problem_id)171 context = Context({'p':p})172 return render_to_response('ka_error.html', context)173def export(request):174 problems = Problem.objects.all()175 context = Context({'problems':problems})176 return render_to_response('export.html', context)177def problems_Summary(request):178 problems = Problem.objects.all()179 context = Context({'problems':problems})180 return render_to_response('problems_Summary.html', context)181def ka_details(request, problem_id):182 p = get_object_or_404(Problem, id=problem_id)183 q = ProblemTemplate.objects.get(problem = p)184# v = Variable.objects.get(problem = p)185 s = Answer.objects.get(problem = p)186# c = Choice.objects.get(problem = p)187 h = p.hint_set.all()188 189 destination = open('/home/OpenDSA/exercises/'+p.title+'.html', 'wb+')190 str ="<!DOCTYPE html>"+"\n"+"<html data-require=\"math math-format word-problems spin\"><head>"+"\n"+"<title>"+"\n"+p.title+"\n"+"</title>"+"\n"+"<script src=\"../../lib/jquery.min.js\">"+"\n"+"</script>"+"\n"+"<script src=\"../../lib/jquery-ui.min.js\">"+"\n"+"</script>"+"\n"+"<script>urlBaseOverride = \"../../ODSAkhan-exercises/\";</script>"+"\n"+"<script src=\"../../lib/khan-exercise-min.js\">"+"\n"+"</script>"+"\n"+"<script type=\"text/javascript\"src=\"http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=http://algoviz.org/OpenDSA/ODSAkhan-exercises/KAthJax-77111459c7d82564a705f9c5480e2c88.js\">"+"\n"+"</script>"+"\n"191 for scr in p.script_set.all():192 str += "<p>"193 str += scr.script194 str += "</p>"195 str += "\n"196 str += "</head>"+"\n"+"<body>"+"\n"+"<div class=\"exercise\">"+"\n"+"<div class=\"vars\">"+"\n"197 for t in p.variable_set.all():198 str +="<var id=\""199 str += t.var_id200 str += "\">" 201 str += t.var_value202 str += "</var>"203 str += "\n"204 str += "</div>"+"\n"+" <div class=\"problems\">"+"\n"205 if "spin" in q.question:206 str += "<div id =\"problem\">"207 str += q.question208 str += "</div>"+"\n"209 str += "<div class=\"solution\""210 if "spin" not in q.question:211 str += "data-type=\"custom\""212 str += ">"+"\n"213 str += s.solution214 str += "</div>"215 str += "\n"216 217 for c in p.choice_set.all():218 if c.choice == "":219 break220 else:221 str += "<ul class =\"choices\">"222 break223 224 for c in p.choice_set.all():225 if not c.choice == "":226 str += "<li><var>"227 str += c.choice228 str += "</var></li>"229 str += "\n"230 for c in p.choice_set.all():231 if c.choice == "":232 break233 else:234 str += "</ul>"235 break236 str += "<div class=\"hints\">"237 str += "\n"238 for h in p.hint_set.all():239 str += "<p>"240 str += h.hint241 str += "</p>"242 str += "\n"243 str += "</div>"+"\n"244 if "spin" in q.question:245 str += "</div>"246 str += "</div>"+"\n"+"</div>"+"\n"+"</body>"+"\n"+"</html>"+"\n" 247 destination.write(bytes(str))248 destination.close()249 context = Context({250 'p':p,251 'title':p.title, 252 'question':q,253 'solution':s,254 # 'choice':c,255# 'hint':h256 })257 return render_to_response('ka_details.html', context)258#@login_required259def simple_details(request, problem_id):260 p = get_object_or_404(Problem, id=problem_id)261 q = ProblemTemplate.objects.get(problem = p)262# v = Variable.objects.get(problem = p)263 s = Answer.objects.get(problem = p)264# c = Choice.objects.get(problem = p)265 h = p.hint_set.all()266 destination = open("/home/OpenDSA/exercises/"+p.title+".html", 'wb+')267 268 str ="<!DOCTYPE html><html data-require=\"math math-format word-problems spin\"><head>"+"\n"+"<title>"+"\n"+p.title+"</title>"+"\n"+"<script src=\"../../lib/jquery.min.js\">"+"\n"+"</script>"+"\n"+"<script src=\"../../lib/jquery-ui.min.js\">"+"\n"+"</script>"+"\n"+"<script>urlBaseOverride = \"../../ODSAkhan-exercises/\";</script>"+"\n"+"<script src=\"../../lib/khan-exercise-min.js\">"+"\n"+"</script>"+"\n"+"</head><body><div class=\"exercise\"><div class=\"vars\"></div><div class=\"problems\"><div id=\"problem-type-or-description\"><p class=\"question\">"269 str += q.question270 str += "</p>"271 str += "<div class=\"solution\"><var>\""272 str += s.solution273 str += "\"</var></div>"274 str += "<ul class =\"choices\">"275 for c in p.choice_set.all():276 str += "<li><var>\""277 str += c.choice278 str += "\"</var></li>"279 str += "</ul>"280 str += "<div class=\"hints\">"281 for h in p.hint_set.all():282 str += "<p>\""283 str += h.hint284 str += "\"</p>"285 str += "</div>"286 str += "</div></div></div></body>"+"\n"+"<script type=\"text/javascript\"src=\"http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=http://algoviz.org/OpenDSA/ODSAkhan-exercises/KAthJax-77111459c7d82564a705f9c5480e2c88.js\">"+"\n"+"</script>"+"</html>" 287 destination.write(bytes(str))288 destination.close()289 context = Context({290 'p':p,291 'title':p.title, 292 'question':q,293 'solution':s,294 # 'choice':c,295# 'hint':h296 })297 return render_to_response('simple_details.html', context)298def edit_ka(request, problem_id):299 problem = get_object_or_404(Problem, id=problem_id)300 class RequiredFormSet(BaseFormSet):301 def __init__(self, *args, **kwargs):302 super(RequiredFormSet, self).__init__(*args, **kwargs)303 for form in self.forms:304 form.empty_permitted = True305 class MyInline(BaseInlineFormSet): 306 def __init__(self, *args, **kwargs): 307 super(MyInline, self).__init__(*args, **kwargs) 308 self.can_delete = False 309 310 311 maxpt = max(0, len(ProblemTemplate.objects.filter(problem=problem)))312 ProblemTemplateInlineFormSet = inlineformset_factory(Problem, ProblemTemplate, max_num=maxpt)313 maxa = max(0, len(Answer.objects.filter(problem=problem)))314 AnswerInlineFormSet = inlineformset_factory(Problem, Answer, max_num =maxa)315 maxv = max(0, len(Variable.objects.filter(problem=problem)))316 VariableInlineFormSet = inlineformset_factory(Problem, Variable, max_num=maxv)317 maxc = max(0, len(CommonIntroduction.objects.filter(problem=problem)))318 CommonIntroductionFormSet = inlineformset_factory(Problem, CommonIntroduction, max_num =maxc )319 maxch = max(0, len(Choice.objects.filter(problem=problem)))320 ChoiceInlineFormSet = inlineformset_factory(Problem, Choice, max_num=maxch, formset=MyInline)321 maxh = max(0, len(Hint.objects.filter(problem=problem)))322 HintInlineFormSet = inlineformset_factory(Problem, Hint, max_num=maxh)323 maxs = max(0, len(Script.objects.filter(problem=problem)))324 ScriptInlineFormSet = inlineformset_factory(Problem, Script, max_num=maxs)325 if request.method == 'POST':326 problem_form =ProblemForm(request.POST, instance=problem)327 problem_template_formset = ProblemTemplateInlineFormSet(request.POST,request.FILES, instance=problem, prefix='templates')328 common_introduction_formset = CommonIntroductionForm(request.POST, request.FILES, prefix='common_intro', instance =problem)329 answer_formset = AnswerInlineFormSet(request.POST, instance=problem, prefix='answer')330 hint_formset = HintInlineFormSet(request.POST, request.FILES, instance=problem, prefix='hints')331 choice_formset = ChoiceInlineFormSet(request.POST, request.FILES, instance=problem, prefix='choices')332 script_formset = ScriptInlineFormSet(request.POST, request.FILES, instance=problem, prefix='scripts')333 variable_formset = VariableInlineFormSet(request.POST, request.FILES,instance=problem, prefix='variables')334 335 if problem_form.is_valid() and variable_formset.is_valid() and problem_template_formset.is_valid() and choice_formset.is_valid() and hint_formset.is_valid() and answer_formset.is_valid() and script_formset.is_valid() and common_introduction_formset.is_valid() :336 problem = problem_form.save()337 answer_formset.save(commit = False)338 common_introduction_formset.save(commit = False)339 problem_template_formset.save(commit =False)340 variable_formset.save(commit = False)341 for form in hint_formset.forms:342 hint = form.save(commit = False)343 hint.problem = problem344 hint.save()345 for form in script_formset.forms:346 script = form.save(commit = False)347 script.problem = problem348 script.save()349 for form in choice_formset.forms:350 choice = form.save(commit = False)351 choice.problem = problem352 choice.save()353 return HttpResponseRedirect('/qbank/problems/')354 else:355 problem_form = ProblemForm(instance=problem)356 357 problem_template_formset = ProblemTemplateInlineFormSet( instance=problem, prefix='templates')358 choice_formset = ChoiceInlineFormSet(instance=problem, prefix='choices')359 360 answer_formset = AnswerInlineFormSet(instance=problem, prefix='answer')361 362 script_formset = ScriptInlineFormSet(instance=problem, prefix='scripts')363 variable_formset = VariableInlineFormSet(instance=problem, prefix='variables')364 common_introduction_formset = CommonIntroductionFormSet(instance=problem, prefix='common_intro')365 hint_formset = HintInlineFormSet( instance=problem, prefix='hints')366 367 c = {368 'problem_form' : problem_form,369 'choice_formset' : choice_formset,370 'problem_template_formset' :problem_template_formset,371 'answer_formset': answer_formset,372 'variable_formset' : variable_formset,373 'script_formset' : script_formset,374 'common_introduction_formset' : common_introduction_formset,375 'hint_formset' : hint_formset, 376 }377 c.update(csrf(request))378 return render_to_response('edit.html', c)379def edit_simple(request, problem_id):380 problem = get_object_or_404(Problem, id=problem_id)381 class RequiredFormSet(BaseFormSet):382 def __init__(self, *args, **kwargs):383 super(RequiredFormSet, self).__init__(*args, **kwargs)384 for form in self.forms:385 form.empty_permitted = True386 387 class MyInline(BaseInlineFormSet): 388 def __init__(self, *args, **kwargs): 389 super(MyInline, self).__init__(*args, **kwargs) 390 self.can_delete = False 391 392 393 maxpt = max(0, len(ProblemTemplate.objects.filter(problem=problem)))394 ProblemTemplateInlineFormSet = inlineformset_factory(Problem, ProblemTemplate, max_num=maxpt)395 396 maxa = max(0, len(Answer.objects.filter(problem=problem)))397 AnswerInlineFormSet = inlineformset_factory(Problem, Answer, max_num =maxa)398 maxch = max(0, len(Choice.objects.filter(problem=problem)))399 ChoiceInlineFormSet = inlineformset_factory(Problem, Choice, max_num=maxch, formset=MyInline)400 401 maxh = max(0, len(Hint.objects.filter(problem=problem)))402 HintInlineFormSet = inlineformset_factory(Problem, Hint, max_num=maxh)403 404 if request.method == 'POST':405 problem_form =ProblemForm(request.POST, instance=problem)406 problem_template_formset = ProblemTemplateInlineFormSet(request.POST,request.FILES, instance=problem, prefix='templates')407 408 answer_formset = AnswerInlineFormSet(request.POST, instance=problem, prefix='answer')409 hint_formset = HintInlineFormSet(request.POST, request.FILES, instance=problem, prefix='hints')410 choice_formset = ChoiceInlineFormSet(request.POST, request.FILES, instance=problem, prefix='choices')411 412 if problem_form.is_valid() and problem_template_formset.is_valid() and choice_formset.is_valid() and hint_formset.is_valid() and answer_formset.is_valid():413 problem = problem_form.save()414 answer_formset.save(commit = False)415 problem_template_formset.save(commit =False)416 for form in hint_formset.forms:417 hint = form.save(commit = False)418 hint.problem = problem419 hint.save()420 for form in choice_formset.forms:421 choice = form.save(commit = False)422 choice.problem = problem423 choice.save()424 return HttpResponseRedirect('/qbank/problems/')425 else:426 problem_form = ProblemForm(instance=problem)427 428 problem_template_formset = ProblemTemplateInlineFormSet( instance=problem, prefix='templates')429 choice_formset = ChoiceInlineFormSet(instance=problem, prefix='choices')430 431 answer_formset = AnswerInlineFormSet(instance=problem, prefix='answer')432 hint_formset = HintInlineFormSet( instance=problem, prefix='hints')433 434 c = {435 'problem_form' : problem_form,436 'choice_formset' : choice_formset,437 'problem_template_formset' :problem_template_formset,438 'answer_formset': answer_formset,439 'hint_formset' : hint_formset, 440 }441 c.update(csrf(request))442 return render_to_response('simple.html', c)443def edit_list(request, problem_id):444 problem = get_object_or_404(Problem, id=problem_id)445 class RequiredFormSet(BaseFormSet):446 def __init__(self, *args, **kwargs):447 super(RequiredFormSet, self).__init__(*args, **kwargs)448 for form in self.forms:449 form.empty_permitted = True450 class MyInline(BaseInlineFormSet): 451 def __init__(self, *args, **kwargs): 452 super(MyInline, self).__init__(*args, **kwargs) 453 self.can_delete = False 454 455 456 maxpt = max(0, len(ProblemTemplate.objects.filter(problem=problem)))457 ProblemTemplateInlineFormSet = inlineformset_factory(Problem, ProblemTemplate, max_num=maxpt)458 maxa = max(0, len(Answer.objects.filter(problem=problem)))459 AnswerInlineFormSet = inlineformset_factory(Problem, Answer, max_num =maxa)460 maxv = max(0, len(Variable.objects.filter(problem=problem)))461 VariableInlineFormSet = inlineformset_factory(Problem, Variable, max_num=maxv)462 463 maxh = max(0, len(Hint.objects.filter(problem=problem)))464 HintInlineFormSet = inlineformset_factory(Problem, Hint, max_num=maxh)465 if request.method == 'POST':466 problem_form =ProblemForm(request.POST, instance=problem)467 problem_template_formset = ProblemTemplateInlineFormSet(request.POST,request.FILES, instance=problem, prefix='templates')468 answer_formset = AnswerInlineFormSet(request.POST, instance=problem, prefix='answer')469 hint_formset = HintInlineFormSet(request.POST, request.FILES, instance=problem, prefix='hints')470 variable_formset = VariableInlineFormSet(request.POST, request.FILES,instance=problem, prefix='variables')471 472 if problem_form.is_valid() and variable_formset.is_valid() and problem_template_formset.is_valid() and hint_formset.is_valid() and answer_formset.is_valid():473 problem = problem_form.save()474 answer_formset.save(commit = False)475 problem_template_formset.save(commit =False)476 variable_formset.save(commit = False)477 for form in hint_formset.forms:478 hint = form.save(commit = False)479 hint.problem = problem480 hint.save()481 return HttpResponseRedirect('/qbank/problems/')482 else:483 problem_form = ProblemForm(instance=problem)484 485 problem_template_formset = ProblemTemplateInlineFormSet( instance=problem, prefix='templates')486 answer_formset = AnswerInlineFormSet(instance=problem, prefix='answer')487 488 variable_formset = VariableInlineFormSet(instance=problem, prefix='variables')489 hint_formset = HintInlineFormSet( instance=problem, prefix='hints')490 491 c = {492 'problem_form' : problem_form,493 'problem_template_formset' :problem_template_formset,494 'answer_formset': answer_formset,495 'variable_formset' : variable_formset,496 'hint_formset' : hint_formset, 497 }498 c.update(csrf(request))499 return render_to_response('list.html', c, context_instance=RequestContext(request))500def edit_range(request, problem_id):501 problem = get_object_or_404(Problem, id=problem_id)502 class RequiredFormSet(BaseFormSet):503 def __init__(self, *args, **kwargs):504 super(RequiredFormSet, self).__init__(*args, **kwargs)505 for form in self.forms:506 form.empty_permitted = True507 class MyInline(BaseInlineFormSet): 508 def __init__(self, *args, **kwargs): 509 super(MyInline, self).__init__(*args, **kwargs) 510 self.can_delete = False 511 512 513 maxpt = max(0, len(ProblemTemplate.objects.filter(problem=problem)))514 ProblemTemplateInlineFormSet = inlineformset_factory(Problem, ProblemTemplate, max_num=maxpt)515 maxa = max(0, len(Answer.objects.filter(problem=problem)))516 AnswerInlineFormSet = inlineformset_factory(Problem, Answer, max_num =maxa)517 maxv = max(0, len(Variable.objects.filter(problem=problem)))518 VariableInlineFormSet = inlineformset_factory(Problem, Variable, max_num=maxv)519 520 521 if request.method == 'POST':522 problem_form =ProblemForm(request.POST, instance=problem)523 problem_template_formset = ProblemTemplateInlineFormSet(request.POST,request.FILES, instance=problem, prefix='templates')524 answer_formset = AnswerInlineFormSet(request.POST, instance=problem, prefix='answer')525 variable_formset = VariableInlineFormSet(request.POST, request.FILES, prefix='variables', instance=problem)526 527 if problem_form.is_valid() and variable_formset.is_valid() and problem_template_formset.is_valid() and answer_formset.is_valid():528 problem = problem_form.save()529 answer_formset.save(commit = False)530 problem_template_formset.save(commit =False)531 for form in variable_formset.forms:532 variable = form.save(commit = False)533 variable.problem = problem534 variable.save()535 return HttpResponseRedirect('/qbank/problems/')536 else:537 problem_form = ProblemForm(instance=problem)538 539 problem_template_formset = ProblemTemplateInlineFormSet(instance=problem, prefix='templates')540 answer_formset = AnswerInlineFormSet(instance=problem, prefix='answer')541 542 variable_formset = VariableInlineFormSet(instance=problem, prefix='variables')543 544 c = {545 'problem_form' : problem_form,546 'problem_template_formset' :problem_template_formset,547 'answer_formset': answer_formset,548 'variable_formset' : variable_formset,549 }550 c.update(csrf(request))551 return render_to_response('range.html', c)552def edit_summative(request, problem_id):553 problem = get_object_or_404(Problem, id=problem_id)554 class RequiredFormSet(BaseFormSet):555 def __init__(self, *args, **kwargs):556 super(RequiredFormSet, self).__init__(*args, **kwargs)557 for form in self.forms:558 form.empty_permitted = True559 class MyInline(BaseInlineFormSet): 560 def __init__(self, *args, **kwargs): 561 super(MyInline, self).__init__(*args, **kwargs) 562 self.can_delete = False 563 564 problems = Problem.objects.all()565 maxpt = max(0, len(ProblemTemplate.objects.filter(problem=problem)))566 ProblemTemplateInlineFormSet = inlineformset_factory(Problem, ProblemTemplate, max_num=maxpt)567 maxc = max(0, len(CommonIntroduction.objects.filter(problem=problem)))568 CommonIntroductionFormSet = inlineformset_factory(Problem, CommonIntroduction, max_num =maxc )569 if request.method == 'POST':570 problem_form =ProblemForm(request.POST, instance=problem)571 problem_template_formset = ProblemTemplateInlineFormSet(request.POST,request.FILES, prefix='templates', instance=problem )572 common_introduction_formset = CommonIntroductionFormSet(request.POST, request.FILES, prefix='common_intro', instance =problem)573 574 if problem_form.is_valid() and problem_template_formset.is_valid() and common_introduction_formset.is_valid() :575 problem = problem_form.save()576 577 common_introduction_formset.save(commit = False)578 579 for form in problem_template_formset.forms:580 problem_template = form.save(commit = False)581 problem_template.problem = problem582 problem_template.save()583 584 return HttpResponseRedirect('/qbank/problems/')585 else:586 problem_form = ProblemForm(instance=problem)587 588 problem_template_formset = ProblemTemplateInlineFormSet(instance=problem, prefix='templates')589 common_introduction_formset = CommonIntroductionFormSet(instance=problem, prefix='common_intro')590 591 c = {592 'problem_form' : problem_form,593 'problem_template_formset' :problem_template_formset,594 'common_introduction_formset' : common_introduction_formset,595 'problems' : problems,596 }597 c.update(csrf(request))598 return render_to_response('summative.html', c)599#@login_required600def summative_details(request, problem_id):601 p = get_object_or_404(Problem, id=problem_id)602 q = ProblemTemplate.objects.filter(problem = p)603# v = Variable.objects.get(problem = p)604# s = Answer.objects.get(problem = p)605# c = Choice.objects.get(problem = p)606# h = p.hint_set.all()607 destination = open('/home/OpenDSA/exercises/'+p.title+'.html', 'wb+')608 str ="<!DOCTYPE html>"+"\n"+"<html data-require=\"math math-format word-problems spin\">"+"\n"+"<head>"+"\n"+"<title>"+"\n"+p.title+"</title>"+"\n"+"<script src=\"../../lib/jquery.min.js\">"+"\n"+"</script>"+"\n"+"<script src=\"../../lib/jquery-ui.min.js\">"+"\n"+"</script>"+"\n"+"<script>urlBaseOverride = \"../../ODSAkhan-exercises/\";</script>"+"\n"+"<script src=\"../../lib/khan-exercise-min.js\">"+"\n"+"</script>"+"\n"+"</head>"+"\n"+"<body>"+"\n"609 610 for c in p.problemtemplate_set.all():611 str += "<div class=\"exercise\" data-name=\"/qbank/exercises/"612 str += c.question613 str += "\">"614 str += "</div>"+"\n"615 str += "</body>"+"\n"+"<script type=\"text/javascript\"src=\"http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=http://algoviz.org/OpenDSA/ODSAkhan-exercises/KAthJax-77111459c7d82564a705f9c5480e2c88.js\">"+"\n"+"</script>"+"</html>"616 destination.write(bytes(str))617 destination.close()618 context = Context({619 'p':p,620 'title':p.title, 621 'question':q,622 # 'solution':s,623 # 'choice':c,624# 'hint':h625 })626 return render_to_response('summative_details.html', context)627#@login_required628def ka_gen(request, problem_id):629 p = get_object_or_404(Problem, id=problem_id)630 q = ProblemTemplate.objects.filter(problem = p)631# v = Variable.objects.get(problem = p)632# s = Answer.objects.get(problem = p)633# c = Choice.objects.get(problem = p)634# h = p.hint_set.all()635 destination = open('/home/OpenDSA/temp/'+p.title+'_View.html', 'wb+')636 str ="<!DOCTYPE html>"+"\n"+"<html data-require=\"math math-format word-problems spin\">"+"\n"+"<head>"+"\n"+"<title>"+"\n"+p.title+"</title>"+"\n"+"<script src=\"../../lib/jquery.min.js\">"+"\n"+"</script>"+"\n"+"<script src=\"../../lib/jquery-ui.min.js\">"+"\n"+"</script>"+"\n"+"<script>urlBaseOverride = \"../../ODSAkhan-exercises/\";</script>"+"\n"+"<script src=\"../../lib/khan-exercise-min.js\">"+"\n"+"</script>"+"\n"+"</head>"+"\n"+"<body>"+"\n"637 638 639 str += "<div class=\"exercise\" data-name=\"/qbank/exercises/"640 str += p.title641 str += "\">"642 str += "\n"+"</div>"643 str +="</body>"+"\n"+"<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=http://algoviz.org/OpenDSA/ODSAkhan-exercises/KAthJax-77111459c7d82564a705f9c5480e2c88.js\">"+"</script>"+"</html>"644 destination.write(bytes(str))645 destination.close()646 context = Context({647 'p':p,648 'title':p.title, 649 'question':q,650 # 'solution':s,651 # 'choice':c,652# 'hint':h653 })654 return render_to_response('ka_gen.html', context)655#@login_required656def range_details(request, problem_id):657 p = get_object_or_404(Problem, id=problem_id)658 q = ProblemTemplate.objects.get(problem = p)659# v = Variable.objects.get(problem = p)660 s = Answer.objects.get(problem = p)661# c = Choice.objects.get(problem = p)662 h = p.hint_set.all()663 destination = open('/home/OpenDSA/exercises/'+p.title+'.html', 'wb+')664 str ="<!DOCTYPE html>"+"\n"+"<html data-require=\"math math-format word-problems spin\">"+"\n"+"<head>"+"\n"+"<title>"+"\n"+p.title+"</title>"+"\n"+"<script src=\"../../lib/jquery.min.js\">"+"\n"+"</script>"+"\n"+"<script src=\"../../lib/jquery-ui.min.js\">"+"\n"+"</script>"+"\n"+"<script>urlBaseOverride = \"../../ODSAkhan-exercises/\";</script>"+"\n"+"<script src=\"../../lib/khan-exercise-min.js\">"+"\n"+"</script>"+"\n"+"</head>"+"\n"+"<body>"+"\n"+"<div class=\"exercise\"><div class=\"vars\">" 665 for t in p.variable_set.all():666 str +="<var id=\""667 str += t.var_id668 str += "\">" 669 str += t.var_value670 str += "</var>"+"\n"671 str += "</div>"+"\n"+"<div class=\"problems\"> "+"\n"+"<div id=\"problem-type-or-description\">"+"\n"+"<p class=\"problem\">"+"\n"+"<p class=\"question\">"672 str += q.question673 str += "</p>"+"\n"+"<div class=\"solution\""674 if "log" in q.question:675 str += "data-forms=\"log\""676 str += ">"+"\n"+"<var>"677 str += s.solution678 str += "</var>"+"\n"+"</div>"+"\n"+"</div>"+"\n"+"</div>"+"\n"+"</div>"+"\n"+"</body>"+"\n"+"<script type=\"text/javascript\"src=\"http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=http://algoviz.org/OpenDSA/ODSAkhan-exercises/KAthJax-77111459c7d82564a705f9c5480e2c88.js\">"+"\n"+"</script>"+"</html>"679 destination.write(bytes(str))680 destination.close()681 context = Context({682 'p':p,683 'title':p.title, 684 'question':q,685 'solution':s,686 # 'choice':c,687# 'hint':h688 })689 return render_to_response('range_details.html', context)690#@login_required691def list_details(request, problem_id):692 p = get_object_or_404(Problem, id=problem_id)693 q = ProblemTemplate.objects.get(problem = p)694# v = Variable.objects.get(problem = p)695 s = Answer.objects.get(problem = p)696# c = Choice.objects.get(problem = p)697 h = p.hint_set.all()698 destination = open('/home/OpenDSA/exercises/'+p.title+'.html', 'wb+')699 str ="<!DOCTYPE html>"+"\n"+"<html data-require=\"math math-format word-problems spin\">"+"\n"+"<head>"+"\n"+"<title>"+"\n"+p.title+"</title>"+"\n"+"<script src=\"../../lib/jquery.min.js\">"+"\n"+"</script>"+"\n"+"<script src=\"../../lib/jquery-ui.min.js\">"+"\n"+"</script>"+"\n"+"<script>urlBaseOverride = \"../../ODSAkhan-exercises/\";</script>"+"\n"+"<script src=\"../../lib/khan-exercise-min.js\">"+"\n"+"</script>"+"\n"+"</head>"+"\n"+"<body>"+"\n"+"<div class=\"exercise\">"+"\n"+"<div class=\"vars\">"+"\n"700 solution_list = (s.solution).split(",")701 index = 1702 ans_uniq = []703 for t in solution_list:704 if t not in ans_uniq:705 ans_uniq.append(t)706 j = "A%d" %index707 str += "<var id=\""708 str += j709 str += "\">"+t710 str += "</var>"+"\n"711 index = index +1712 count = 0713 var_count_array = []714 for t in p.variable_set.all():715 str +="<var id=\""716 str += t.var_id717 str += "\">[" 718 str += t.var_value719 str += "]</var>"+"\n"720 j = "x%d" %(count+1)721 var_elements = (t.var_value).split(",")722 var_count_array.append(len(var_elements))723 str += "<var id=\""724 str += j725 str += "\">randRange(0,%d" %(len(var_elements) -1)726 str += ")</var>"+"\n"727 count = count+1728 eq = "x%d" % len(var_count_array)729 var_count = count -1730 coef = 1731 while (var_count>0):732 coef = coef * var_count_array[var_count]733 var = "%d" %coef734 var += "*x"735 var += "%d" %var_count736 eq = var +"+"+eq 737 var_count = var_count-1 738 739 740 741 str += "<var id =\"INDEX\">"742 str += eq743 str += "</var>"+"\n"744 str += "<var id=\"ANSWER\">[" 745 746 str += s.solution747 str += "]</var>"+"\n"748 str += "</div>"+"\n"+"<div class=\"problems\"> "+"\n"+"<div id=\"problem-type-or-description\">"+"\n"+"<p class=\"problem\">"+"\n"+"<p class=\"question\">"749 str += q.question750 str += "</p>"+"\n"+"<div class=\"solution\"><var>ANSWER[INDEX]</var>"+"\n"+"</div>"+"\n"+"<ul class =\"choices\" data-category=\"true\">"751 num=1752 answer_unique = []753 for t in solution_list:754 if t not in answer_unique:755 answer_unique.append(t) 756 str += "<li><var>"757 str += "A%d" %num758 num = num +1759 str += "</var></li>"760 str += "</ul>"761 str += "<div class=\"hints\">"762 for h in p.hint_set.all():763 str += "<p>\""764 str += h.hint765 str += "\"</p>"766 str += "</div>"767 str += "</div>"+"\n"+"</div>"+"\n"+"</div>"+"\n"+"</body>"+"\n"+"<script type=\"text/javascript\"src=\"http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=http://algoviz.org/OpenDSA/ODSAkhan-exercises/KAthJax-77111459c7d82564a705f9c5480e2c88.js\">"+"\n"+"</script>"+"</html>"768 769 destination.write(bytes(str))770 destination.close()771 context = Context({772 'p':p,773 'title':p.title, 774 'question':q,775 'solution':s,776 # 'choice':c,777# 'hint':h778 })779 return render_to_response('list_details.html', context, context_instance=RequestContext(request))780#@login_required781def write_file(request, problem_id):782 response = HttpResponse( content_type = 'text/csv')783 p = get_object_or_404(Problem, id=problem_id)784 response['Content-Disposition'] = 'attachment; filename="'+p.title+'.csv"'785 writer = csv.writer(response)786 problems = Problem.objects.filter(id = problem_id)787 788 for p in problems:789 writer.writerow(['TITLE',p.title])790 writer.writerow(['DIFFICULTY',p.difficulty_level])791 q = ProblemTemplate.objects.filter(problem = p)792 for t in q:793 writer.writerow(['QUESTION', t.question])794 for t in p.variable_set.all():795 writer.writerow(['VAR_NAME', t.var_id])796 writer.writerow(['VAR_VALUE', t.var_value])797 writer.writerow(['ATTR_INFO',t.attribute])798 for t in p.script_set.all():799 writer.writerow(['SCRIPT',t.script])800 for t in p.choice_set.all():801 writer.writerow(['CHOICE', t.choice])802 for t in p.hint_set.all():803 writer.writerow(['HINT', t.hint])804 try:805 c = CommonIntroduction.objects.get(problem = p)806 writer.writerow(['COMMON_INTRO', c.common_intro])807 except CommonIntroduction.DoesNotExist:808 c = None809 try:810 s = Answer.objects.get(problem = p)811 writer.writerow(['SOLUTION', s.solution])812 except Answer.DoesNotExist:813 s = None814 815 return response816#@login_required817def delete(request, problem_id):818 p= Problem.objects.get(id = problem_id)819 p.delete()820 return HttpResponseRedirect('/qbank/problems/')821#@login_required822def simple(request):823 # This class is used to make empty formset forms required824 # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032825 class RequiredFormSet(BaseFormSet):826 def __init__(self, *args, **kwargs):827 super(RequiredFormSet, self).__init__(*args, **kwargs)828 for form in self.forms:829 form.empty_permitted = True830 HintFormSet = formset_factory(HintForm, max_num = 10, formset = RequiredFormSet)831 ChoiceFormSet = formset_factory(ChoiceForm, max_num = 10, formset = RequiredFormSet)832 if request.method == 'POST': # If the form has been submitted...833 problem_form = SimpleProblemForm(request.POST)834 problem_template_form = ProblemTemplateForm(request.POST, prefix='template')835 answer_form = AnswerForm(request.POST, prefix='answer')836 hint_formset = HintFormSet(request.POST, request.FILES, prefix='hints')837 838 choice_formset = ChoiceFormSet(request.POST, request.FILES, prefix='choices')839 if problem_form.is_valid() and problem_template_form.is_valid() and choice_formset.is_valid() and hint_formset.is_valid() and answer_form.is_valid():840 problem = problem_form.save()841 problem_template = problem_template_form.save(commit = False)842 problem_template.problem = problem843 problem_template.save()844 answer = answer_form.save(commit = False)845 answer.problem = problem846 answer.save()847 for form in hint_formset.forms:848 hint = form.save(commit = False)849 hint.problem = problem850 hint.save()851 for form in choice_formset.forms:852 choice = form.save(commit = False)853 choice.problem = problem854 choice.save() # Redirect to a 'success' page855 return HttpResponseRedirect('/qbank/problems/')856 else:857 problem_form = SimpleProblemForm()858 choice_formset = ChoiceFormSet(prefix='choices')859 problem_template_form = ProblemTemplateForm(prefix='template')860 answer_form = AnswerForm(prefix='answer')861 hint_formset = HintFormSet(prefix='hints')862 c = {'problem_form' : problem_form,863 'choice_formset' : choice_formset,864 'problem_template_form' : problem_template_form,865 'answer_form': answer_form,866 'hint_formset' : hint_formset,867 }868 c.update(csrf(request))869 return render_to_response('simple.html', c)870#@login_required871def list(request):872 # This class is used to make empty formset forms required873 # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032874 class RequiredFormSet(BaseFormSet):875 def __init__(self, *args, **kwargs):876 super(RequiredFormSet, self).__init__(*args, **kwargs)877 for form in self.forms:878 form.empty_permitted = True879 VariableFormSet = formset_factory(VariableForm, max_num = 10, formset = RequiredFormSet)880 HintFormSet = formset_factory(HintForm, max_num = 10, formset = RequiredFormSet)881 #ChoiceFormSet = formset_factory(ChoiceForm, max_num = 10, formset = RequiredFormSet)882 if request.method == 'POST': # If the form has been submitted...883 problem_form = ListProblemForm(request.POST)884 problem_template_form = ProblemTemplateForm(request.POST, prefix='template')885 answer_form = AnswerForm(request.POST, prefix='answer')886 variable_formset = VariableFormSet(request.POST,request.FILES, prefix='variables')887 hint_formset = HintFormSet(request.POST, request.FILES, prefix='hints')888 #choice_formset = ChoiceFormSet(request.POST, request.FILES, prefix='choices')889 if problem_form.is_valid() and problem_template_form.is_valid() and variable_formset.is_valid() and hint_formset.is_valid() and answer_form.is_valid():890 problem = problem_form.save()891 problem_template = problem_template_form.save(commit = False)892 problem_template.problem = problem893 problem_template.save()894 answer = answer_form.save(commit = False)895 answer.problem = problem896 answer.save()897 898 for form in variable_formset.forms:899 variable = form.save(commit = False)900 variable.problem = problem901 variable.save() # Redirect to a 'success' page902 for form in hint_formset.forms:903 hint = form.save(commit = False)904 hint.problem = problem905 hint.save()906 907 return HttpResponseRedirect('/qbank/problems/')908 else:909 problem_form = ListProblemForm()910 problem_template_form = ProblemTemplateForm(prefix='template')911 answer_form = AnswerForm(prefix='answer') 912 variable_formset = VariableFormSet(prefix='variables')913 #choice_formset = ChoiceFormSet(prefix='choices')914 hint_formset = HintFormSet(prefix='hints')915 c = {'problem_form' : problem_form,916 'problem_template_form' : problem_template_form,917 'answer_form': answer_form,918 'variable_formset' : variable_formset,919 #'choice_formset': choice_formset,920 'hint_formset' : hint_formset,921 }922 c.update(csrf(request))923 return render_to_response('list.html', c)924#@login_required925def range(request):926 # This class is used to make empty formset forms required927 # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032928 class RequiredFormSet(BaseFormSet):929 def __init__(self, *args, **kwargs):930 super(RequiredFormSet, self).__init__(*args, **kwargs)931 for form in self.forms:932 form.empty_permitted = True933 VariableFormSet = formset_factory(VariableForm, max_num = 10, formset = RequiredFormSet)934 if request.method == 'POST': # If the form has been submitted...935 problem_form = RangeProblemForm(request.POST)936 problem_template_form = ProblemTemplateForm(request.POST, prefix='template')937 answer_form = AnswerForm(request.POST, prefix='answer')938 variable_formset = VariableFormSet(request.POST,request.FILES, prefix='variables')939 if problem_form.is_valid() and problem_template_form.is_valid() and variable_formset.is_valid() and answer_form.is_valid():940 problem = problem_form.save()941 problem_template = problem_template_form.save(commit = False)942 problem_template.problem = problem943 problem_template.save()944 answer = answer_form.save(commit = False)945 answer.problem = problem946 answer.save()947 948 for form in variable_formset.forms:949 variable = form.save(commit = False)950 variable.problem = problem951 variable.save() # Redirect to a 'success' page952 return HttpResponseRedirect('/qbank/problems/')953 else:954 problem_form = RangeProblemForm()955 problem_template_form = ProblemTemplateForm(prefix='template')956 answer_form = AnswerForm(prefix='answer') 957 variable_formset = VariableFormSet(prefix='variables')958 c = {'problem_form' : problem_form,959 'problem_template_form' : problem_template_form,960 'answer_form': answer_form,961 'variable_formset' : variable_formset,962 }963 c.update(csrf(request))964 return render_to_response('range.html', c)965def summative(request):966 # This class is used to make empty formset forms required967 # See http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032968 class RequiredFormSet(BaseFormSet):969 def __init__(self, *args, **kwargs):970 super(RequiredFormSet, self).__init__(*args, **kwargs)971 for form in self.forms:972 form.empty_permitted = True973 problems = Problem.objects.all()974 ProblemTemplateFormSet = formset_factory(ProblemTemplateForm, max_num = 10, formset = RequiredFormSet)975 if request.method == 'POST': # If the form has been submitted...976 problem_form = SummativeProblemForm(request.POST)977 common_introduction_form = CommonIntroductionForm(request.POST, prefix='common_intro')978 problem_template_formset = ProblemTemplateFormSet(request.POST, request.FILES, prefix='templates')979 if problem_form.is_valid() and common_introduction_form.is_valid() and problem_template_formset.is_valid():980 problem = problem_form.save()981 common_intro = common_introduction_form.save(commit=False)982 common_intro.problem = problem983 common_intro.save()984 for form in problem_template_formset.forms:985 problem_template = form.save(commit=False)986 problem_template.problem = problem987 problem_template.save() # Redirect to a 'success' page988 return HttpResponseRedirect('/qbank/problems/')989 else:990 problem_form = SummativeProblemForm()991 common_introduction_form = CommonIntroductionForm(prefix='common_intro')992 problem_template_formset = ProblemTemplateFormSet(prefix='templates')993 c = {'problem_form' : problem_form,994 'common_introduction_form' : common_introduction_form,995 'problem_template_formset' : problem_template_formset,996 'problems':problems,997 }998 c.update(csrf(request))999 return render_to_response('summative.html', c)1000def d(request, problem_id):1001 p = get_object_or_404(Problem, id=problem_id)1002 file_path = "/home/OpenDSA/exercises/"+p.title+".html"1003 try:1004 file_wrapper = FileWrapper(file(file_path,'rb'))1005 except:1006 return HttpResponseRedirect('ka_error/')1007 file_mimetype = mimetypes.guess_type(file_path)1008 response = HttpResponse(file_wrapper, content_type=file_mimetype)1009 response['X-Sendfile'] = file_path1010 response['Content-Length'] = os.stat(file_path).st_size1011 response['Content-Disposition'] = 'attachment; filename=%s/' % smart_str(p.title) 1012 return response1013def server_error(request, template_name = '500.html'):...
cp864.py
Source:cp864.py
1""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP864.TXT' with gencodec.py.2"""#"3import codecs4### Codec APIs5class Codec(codecs.Codec):6 def encode(self,input,errors='strict'):7 return codecs.charmap_encode(input,errors,encoding_map)8 def decode(self,input,errors='strict'):9 return codecs.charmap_decode(input,errors,decoding_table)10class IncrementalEncoder(codecs.IncrementalEncoder):11 def encode(self, input, final=False):12 return codecs.charmap_encode(input,self.errors,encoding_map)[0]13class IncrementalDecoder(codecs.IncrementalDecoder):14 def decode(self, input, final=False):15 return codecs.charmap_decode(input,self.errors,decoding_table)[0]16class StreamWriter(Codec,codecs.StreamWriter):17 pass18class StreamReader(Codec,codecs.StreamReader):19 pass20### encodings module API21def getregentry():22 return codecs.CodecInfo(23 name='cp864',24 encode=Codec().encode,25 decode=Codec().decode,26 incrementalencoder=IncrementalEncoder,27 incrementaldecoder=IncrementalDecoder,28 streamreader=StreamReader,29 streamwriter=StreamWriter,30 )31### Decoding Map32decoding_map = codecs.make_identity_dict(range(256))33decoding_map.update({34 0x0025: 0x066a, # ARABIC PERCENT SIGN35 0x0080: 0x00b0, # DEGREE SIGN36 0x0081: 0x00b7, # MIDDLE DOT37 0x0082: 0x2219, # BULLET OPERATOR38 0x0083: 0x221a, # SQUARE ROOT39 0x0084: 0x2592, # MEDIUM SHADE40 0x0085: 0x2500, # FORMS LIGHT HORIZONTAL41 0x0086: 0x2502, # FORMS LIGHT VERTICAL42 0x0087: 0x253c, # FORMS LIGHT VERTICAL AND HORIZONTAL43 0x0088: 0x2524, # FORMS LIGHT VERTICAL AND LEFT44 0x0089: 0x252c, # FORMS LIGHT DOWN AND HORIZONTAL45 0x008a: 0x251c, # FORMS LIGHT VERTICAL AND RIGHT46 0x008b: 0x2534, # FORMS LIGHT UP AND HORIZONTAL47 0x008c: 0x2510, # FORMS LIGHT DOWN AND LEFT48 0x008d: 0x250c, # FORMS LIGHT DOWN AND RIGHT49 0x008e: 0x2514, # FORMS LIGHT UP AND RIGHT50 0x008f: 0x2518, # FORMS LIGHT UP AND LEFT51 0x0090: 0x03b2, # GREEK SMALL BETA52 0x0091: 0x221e, # INFINITY53 0x0092: 0x03c6, # GREEK SMALL PHI54 0x0093: 0x00b1, # PLUS-OR-MINUS SIGN55 0x0094: 0x00bd, # FRACTION 1/256 0x0095: 0x00bc, # FRACTION 1/457 0x0096: 0x2248, # ALMOST EQUAL TO58 0x0097: 0x00ab, # LEFT POINTING GUILLEMET59 0x0098: 0x00bb, # RIGHT POINTING GUILLEMET60 0x0099: 0xfef7, # ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE ISOLATED FORM61 0x009a: 0xfef8, # ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE FINAL FORM62 0x009b: None, # UNDEFINED63 0x009c: None, # UNDEFINED64 0x009d: 0xfefb, # ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM65 0x009e: 0xfefc, # ARABIC LIGATURE LAM WITH ALEF FINAL FORM66 0x009f: None, # UNDEFINED67 0x00a1: 0x00ad, # SOFT HYPHEN68 0x00a2: 0xfe82, # ARABIC LETTER ALEF WITH MADDA ABOVE FINAL FORM69 0x00a5: 0xfe84, # ARABIC LETTER ALEF WITH HAMZA ABOVE FINAL FORM70 0x00a6: None, # UNDEFINED71 0x00a7: None, # UNDEFINED72 0x00a8: 0xfe8e, # ARABIC LETTER ALEF FINAL FORM73 0x00a9: 0xfe8f, # ARABIC LETTER BEH ISOLATED FORM74 0x00aa: 0xfe95, # ARABIC LETTER TEH ISOLATED FORM75 0x00ab: 0xfe99, # ARABIC LETTER THEH ISOLATED FORM76 0x00ac: 0x060c, # ARABIC COMMA77 0x00ad: 0xfe9d, # ARABIC LETTER JEEM ISOLATED FORM78 0x00ae: 0xfea1, # ARABIC LETTER HAH ISOLATED FORM79 0x00af: 0xfea5, # ARABIC LETTER KHAH ISOLATED FORM80 0x00b0: 0x0660, # ARABIC-INDIC DIGIT ZERO81 0x00b1: 0x0661, # ARABIC-INDIC DIGIT ONE82 0x00b2: 0x0662, # ARABIC-INDIC DIGIT TWO83 0x00b3: 0x0663, # ARABIC-INDIC DIGIT THREE84 0x00b4: 0x0664, # ARABIC-INDIC DIGIT FOUR85 0x00b5: 0x0665, # ARABIC-INDIC DIGIT FIVE86 0x00b6: 0x0666, # ARABIC-INDIC DIGIT SIX87 0x00b7: 0x0667, # ARABIC-INDIC DIGIT SEVEN88 0x00b8: 0x0668, # ARABIC-INDIC DIGIT EIGHT89 0x00b9: 0x0669, # ARABIC-INDIC DIGIT NINE90 0x00ba: 0xfed1, # ARABIC LETTER FEH ISOLATED FORM91 0x00bb: 0x061b, # ARABIC SEMICOLON92 0x00bc: 0xfeb1, # ARABIC LETTER SEEN ISOLATED FORM93 0x00bd: 0xfeb5, # ARABIC LETTER SHEEN ISOLATED FORM94 0x00be: 0xfeb9, # ARABIC LETTER SAD ISOLATED FORM95 0x00bf: 0x061f, # ARABIC QUESTION MARK96 0x00c0: 0x00a2, # CENT SIGN97 0x00c1: 0xfe80, # ARABIC LETTER HAMZA ISOLATED FORM98 0x00c2: 0xfe81, # ARABIC LETTER ALEF WITH MADDA ABOVE ISOLATED FORM99 0x00c3: 0xfe83, # ARABIC LETTER ALEF WITH HAMZA ABOVE ISOLATED FORM100 0x00c4: 0xfe85, # ARABIC LETTER WAW WITH HAMZA ABOVE ISOLATED FORM101 0x00c5: 0xfeca, # ARABIC LETTER AIN FINAL FORM102 0x00c6: 0xfe8b, # ARABIC LETTER YEH WITH HAMZA ABOVE INITIAL FORM103 0x00c7: 0xfe8d, # ARABIC LETTER ALEF ISOLATED FORM104 0x00c8: 0xfe91, # ARABIC LETTER BEH INITIAL FORM105 0x00c9: 0xfe93, # ARABIC LETTER TEH MARBUTA ISOLATED FORM106 0x00ca: 0xfe97, # ARABIC LETTER TEH INITIAL FORM107 0x00cb: 0xfe9b, # ARABIC LETTER THEH INITIAL FORM108 0x00cc: 0xfe9f, # ARABIC LETTER JEEM INITIAL FORM109 0x00cd: 0xfea3, # ARABIC LETTER HAH INITIAL FORM110 0x00ce: 0xfea7, # ARABIC LETTER KHAH INITIAL FORM111 0x00cf: 0xfea9, # ARABIC LETTER DAL ISOLATED FORM112 0x00d0: 0xfeab, # ARABIC LETTER THAL ISOLATED FORM113 0x00d1: 0xfead, # ARABIC LETTER REH ISOLATED FORM114 0x00d2: 0xfeaf, # ARABIC LETTER ZAIN ISOLATED FORM115 0x00d3: 0xfeb3, # ARABIC LETTER SEEN INITIAL FORM116 0x00d4: 0xfeb7, # ARABIC LETTER SHEEN INITIAL FORM117 0x00d5: 0xfebb, # ARABIC LETTER SAD INITIAL FORM118 0x00d6: 0xfebf, # ARABIC LETTER DAD INITIAL FORM119 0x00d7: 0xfec1, # ARABIC LETTER TAH ISOLATED FORM120 0x00d8: 0xfec5, # ARABIC LETTER ZAH ISOLATED FORM121 0x00d9: 0xfecb, # ARABIC LETTER AIN INITIAL FORM122 0x00da: 0xfecf, # ARABIC LETTER GHAIN INITIAL FORM123 0x00db: 0x00a6, # BROKEN VERTICAL BAR124 0x00dc: 0x00ac, # NOT SIGN125 0x00dd: 0x00f7, # DIVISION SIGN126 0x00de: 0x00d7, # MULTIPLICATION SIGN127 0x00df: 0xfec9, # ARABIC LETTER AIN ISOLATED FORM128 0x00e0: 0x0640, # ARABIC TATWEEL129 0x00e1: 0xfed3, # ARABIC LETTER FEH INITIAL FORM130 0x00e2: 0xfed7, # ARABIC LETTER QAF INITIAL FORM131 0x00e3: 0xfedb, # ARABIC LETTER KAF INITIAL FORM132 0x00e4: 0xfedf, # ARABIC LETTER LAM INITIAL FORM133 0x00e5: 0xfee3, # ARABIC LETTER MEEM INITIAL FORM134 0x00e6: 0xfee7, # ARABIC LETTER NOON INITIAL FORM135 0x00e7: 0xfeeb, # ARABIC LETTER HEH INITIAL FORM136 0x00e8: 0xfeed, # ARABIC LETTER WAW ISOLATED FORM137 0x00e9: 0xfeef, # ARABIC LETTER ALEF MAKSURA ISOLATED FORM138 0x00ea: 0xfef3, # ARABIC LETTER YEH INITIAL FORM139 0x00eb: 0xfebd, # ARABIC LETTER DAD ISOLATED FORM140 0x00ec: 0xfecc, # ARABIC LETTER AIN MEDIAL FORM141 0x00ed: 0xfece, # ARABIC LETTER GHAIN FINAL FORM142 0x00ee: 0xfecd, # ARABIC LETTER GHAIN ISOLATED FORM143 0x00ef: 0xfee1, # ARABIC LETTER MEEM ISOLATED FORM144 0x00f0: 0xfe7d, # ARABIC SHADDA MEDIAL FORM145 0x00f1: 0x0651, # ARABIC SHADDAH146 0x00f2: 0xfee5, # ARABIC LETTER NOON ISOLATED FORM147 0x00f3: 0xfee9, # ARABIC LETTER HEH ISOLATED FORM148 0x00f4: 0xfeec, # ARABIC LETTER HEH MEDIAL FORM149 0x00f5: 0xfef0, # ARABIC LETTER ALEF MAKSURA FINAL FORM150 0x00f6: 0xfef2, # ARABIC LETTER YEH FINAL FORM151 0x00f7: 0xfed0, # ARABIC LETTER GHAIN MEDIAL FORM152 0x00f8: 0xfed5, # ARABIC LETTER QAF ISOLATED FORM153 0x00f9: 0xfef5, # ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE ISOLATED FORM154 0x00fa: 0xfef6, # ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE FINAL FORM155 0x00fb: 0xfedd, # ARABIC LETTER LAM ISOLATED FORM156 0x00fc: 0xfed9, # ARABIC LETTER KAF ISOLATED FORM157 0x00fd: 0xfef1, # ARABIC LETTER YEH ISOLATED FORM158 0x00fe: 0x25a0, # BLACK SQUARE159 0x00ff: None, # UNDEFINED160})161### Decoding Table162decoding_table = (163 u'\x00' # 0x0000 -> NULL164 u'\x01' # 0x0001 -> START OF HEADING165 u'\x02' # 0x0002 -> START OF TEXT166 u'\x03' # 0x0003 -> END OF TEXT167 u'\x04' # 0x0004 -> END OF TRANSMISSION168 u'\x05' # 0x0005 -> ENQUIRY169 u'\x06' # 0x0006 -> ACKNOWLEDGE170 u'\x07' # 0x0007 -> BELL171 u'\x08' # 0x0008 -> BACKSPACE172 u'\t' # 0x0009 -> HORIZONTAL TABULATION173 u'\n' # 0x000a -> LINE FEED174 u'\x0b' # 0x000b -> VERTICAL TABULATION175 u'\x0c' # 0x000c -> FORM FEED176 u'\r' # 0x000d -> CARRIAGE RETURN177 u'\x0e' # 0x000e -> SHIFT OUT178 u'\x0f' # 0x000f -> SHIFT IN179 u'\x10' # 0x0010 -> DATA LINK ESCAPE180 u'\x11' # 0x0011 -> DEVICE CONTROL ONE181 u'\x12' # 0x0012 -> DEVICE CONTROL TWO182 u'\x13' # 0x0013 -> DEVICE CONTROL THREE183 u'\x14' # 0x0014 -> DEVICE CONTROL FOUR184 u'\x15' # 0x0015 -> NEGATIVE ACKNOWLEDGE185 u'\x16' # 0x0016 -> SYNCHRONOUS IDLE186 u'\x17' # 0x0017 -> END OF TRANSMISSION BLOCK187 u'\x18' # 0x0018 -> CANCEL188 u'\x19' # 0x0019 -> END OF MEDIUM189 u'\x1a' # 0x001a -> SUBSTITUTE190 u'\x1b' # 0x001b -> ESCAPE191 u'\x1c' # 0x001c -> FILE SEPARATOR192 u'\x1d' # 0x001d -> GROUP SEPARATOR193 u'\x1e' # 0x001e -> RECORD SEPARATOR194 u'\x1f' # 0x001f -> UNIT SEPARATOR195 u' ' # 0x0020 -> SPACE196 u'!' # 0x0021 -> EXCLAMATION MARK197 u'"' # 0x0022 -> QUOTATION MARK198 u'#' # 0x0023 -> NUMBER SIGN199 u'$' # 0x0024 -> DOLLAR SIGN200 u'\u066a' # 0x0025 -> ARABIC PERCENT SIGN201 u'&' # 0x0026 -> AMPERSAND202 u"'" # 0x0027 -> APOSTROPHE203 u'(' # 0x0028 -> LEFT PARENTHESIS204 u')' # 0x0029 -> RIGHT PARENTHESIS205 u'*' # 0x002a -> ASTERISK206 u'+' # 0x002b -> PLUS SIGN207 u',' # 0x002c -> COMMA208 u'-' # 0x002d -> HYPHEN-MINUS209 u'.' # 0x002e -> FULL STOP210 u'/' # 0x002f -> SOLIDUS211 u'0' # 0x0030 -> DIGIT ZERO212 u'1' # 0x0031 -> DIGIT ONE213 u'2' # 0x0032 -> DIGIT TWO214 u'3' # 0x0033 -> DIGIT THREE215 u'4' # 0x0034 -> DIGIT FOUR216 u'5' # 0x0035 -> DIGIT FIVE217 u'6' # 0x0036 -> DIGIT SIX218 u'7' # 0x0037 -> DIGIT SEVEN219 u'8' # 0x0038 -> DIGIT EIGHT220 u'9' # 0x0039 -> DIGIT NINE221 u':' # 0x003a -> COLON222 u';' # 0x003b -> SEMICOLON223 u'<' # 0x003c -> LESS-THAN SIGN224 u'=' # 0x003d -> EQUALS SIGN225 u'>' # 0x003e -> GREATER-THAN SIGN226 u'?' # 0x003f -> QUESTION MARK227 u'@' # 0x0040 -> COMMERCIAL AT228 u'A' # 0x0041 -> LATIN CAPITAL LETTER A229 u'B' # 0x0042 -> LATIN CAPITAL LETTER B230 u'C' # 0x0043 -> LATIN CAPITAL LETTER C231 u'D' # 0x0044 -> LATIN CAPITAL LETTER D232 u'E' # 0x0045 -> LATIN CAPITAL LETTER E233 u'F' # 0x0046 -> LATIN CAPITAL LETTER F234 u'G' # 0x0047 -> LATIN CAPITAL LETTER G235 u'H' # 0x0048 -> LATIN CAPITAL LETTER H236 u'I' # 0x0049 -> LATIN CAPITAL LETTER I237 u'J' # 0x004a -> LATIN CAPITAL LETTER J238 u'K' # 0x004b -> LATIN CAPITAL LETTER K239 u'L' # 0x004c -> LATIN CAPITAL LETTER L240 u'M' # 0x004d -> LATIN CAPITAL LETTER M241 u'N' # 0x004e -> LATIN CAPITAL LETTER N242 u'O' # 0x004f -> LATIN CAPITAL LETTER O243 u'P' # 0x0050 -> LATIN CAPITAL LETTER P244 u'Q' # 0x0051 -> LATIN CAPITAL LETTER Q245 u'R' # 0x0052 -> LATIN CAPITAL LETTER R246 u'S' # 0x0053 -> LATIN CAPITAL LETTER S247 u'T' # 0x0054 -> LATIN CAPITAL LETTER T248 u'U' # 0x0055 -> LATIN CAPITAL LETTER U249 u'V' # 0x0056 -> LATIN CAPITAL LETTER V250 u'W' # 0x0057 -> LATIN CAPITAL LETTER W251 u'X' # 0x0058 -> LATIN CAPITAL LETTER X252 u'Y' # 0x0059 -> LATIN CAPITAL LETTER Y253 u'Z' # 0x005a -> LATIN CAPITAL LETTER Z254 u'[' # 0x005b -> LEFT SQUARE BRACKET255 u'\\' # 0x005c -> REVERSE SOLIDUS256 u']' # 0x005d -> RIGHT SQUARE BRACKET257 u'^' # 0x005e -> CIRCUMFLEX ACCENT258 u'_' # 0x005f -> LOW LINE259 u'`' # 0x0060 -> GRAVE ACCENT260 u'a' # 0x0061 -> LATIN SMALL LETTER A261 u'b' # 0x0062 -> LATIN SMALL LETTER B262 u'c' # 0x0063 -> LATIN SMALL LETTER C263 u'd' # 0x0064 -> LATIN SMALL LETTER D264 u'e' # 0x0065 -> LATIN SMALL LETTER E265 u'f' # 0x0066 -> LATIN SMALL LETTER F266 u'g' # 0x0067 -> LATIN SMALL LETTER G267 u'h' # 0x0068 -> LATIN SMALL LETTER H268 u'i' # 0x0069 -> LATIN SMALL LETTER I269 u'j' # 0x006a -> LATIN SMALL LETTER J270 u'k' # 0x006b -> LATIN SMALL LETTER K271 u'l' # 0x006c -> LATIN SMALL LETTER L272 u'm' # 0x006d -> LATIN SMALL LETTER M273 u'n' # 0x006e -> LATIN SMALL LETTER N274 u'o' # 0x006f -> LATIN SMALL LETTER O275 u'p' # 0x0070 -> LATIN SMALL LETTER P276 u'q' # 0x0071 -> LATIN SMALL LETTER Q277 u'r' # 0x0072 -> LATIN SMALL LETTER R278 u's' # 0x0073 -> LATIN SMALL LETTER S279 u't' # 0x0074 -> LATIN SMALL LETTER T280 u'u' # 0x0075 -> LATIN SMALL LETTER U281 u'v' # 0x0076 -> LATIN SMALL LETTER V282 u'w' # 0x0077 -> LATIN SMALL LETTER W283 u'x' # 0x0078 -> LATIN SMALL LETTER X284 u'y' # 0x0079 -> LATIN SMALL LETTER Y285 u'z' # 0x007a -> LATIN SMALL LETTER Z286 u'{' # 0x007b -> LEFT CURLY BRACKET287 u'|' # 0x007c -> VERTICAL LINE288 u'}' # 0x007d -> RIGHT CURLY BRACKET289 u'~' # 0x007e -> TILDE290 u'\x7f' # 0x007f -> DELETE291 u'\xb0' # 0x0080 -> DEGREE SIGN292 u'\xb7' # 0x0081 -> MIDDLE DOT293 u'\u2219' # 0x0082 -> BULLET OPERATOR294 u'\u221a' # 0x0083 -> SQUARE ROOT295 u'\u2592' # 0x0084 -> MEDIUM SHADE296 u'\u2500' # 0x0085 -> FORMS LIGHT HORIZONTAL297 u'\u2502' # 0x0086 -> FORMS LIGHT VERTICAL298 u'\u253c' # 0x0087 -> FORMS LIGHT VERTICAL AND HORIZONTAL299 u'\u2524' # 0x0088 -> FORMS LIGHT VERTICAL AND LEFT300 u'\u252c' # 0x0089 -> FORMS LIGHT DOWN AND HORIZONTAL301 u'\u251c' # 0x008a -> FORMS LIGHT VERTICAL AND RIGHT302 u'\u2534' # 0x008b -> FORMS LIGHT UP AND HORIZONTAL303 u'\u2510' # 0x008c -> FORMS LIGHT DOWN AND LEFT304 u'\u250c' # 0x008d -> FORMS LIGHT DOWN AND RIGHT305 u'\u2514' # 0x008e -> FORMS LIGHT UP AND RIGHT306 u'\u2518' # 0x008f -> FORMS LIGHT UP AND LEFT307 u'\u03b2' # 0x0090 -> GREEK SMALL BETA308 u'\u221e' # 0x0091 -> INFINITY309 u'\u03c6' # 0x0092 -> GREEK SMALL PHI310 u'\xb1' # 0x0093 -> PLUS-OR-MINUS SIGN311 u'\xbd' # 0x0094 -> FRACTION 1/2312 u'\xbc' # 0x0095 -> FRACTION 1/4313 u'\u2248' # 0x0096 -> ALMOST EQUAL TO314 u'\xab' # 0x0097 -> LEFT POINTING GUILLEMET315 u'\xbb' # 0x0098 -> RIGHT POINTING GUILLEMET316 u'\ufef7' # 0x0099 -> ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE ISOLATED FORM317 u'\ufef8' # 0x009a -> ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE FINAL FORM318 u'\ufffe' # 0x009b -> UNDEFINED319 u'\ufffe' # 0x009c -> UNDEFINED320 u'\ufefb' # 0x009d -> ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM321 u'\ufefc' # 0x009e -> ARABIC LIGATURE LAM WITH ALEF FINAL FORM322 u'\ufffe' # 0x009f -> UNDEFINED323 u'\xa0' # 0x00a0 -> NON-BREAKING SPACE324 u'\xad' # 0x00a1 -> SOFT HYPHEN325 u'\ufe82' # 0x00a2 -> ARABIC LETTER ALEF WITH MADDA ABOVE FINAL FORM326 u'\xa3' # 0x00a3 -> POUND SIGN327 u'\xa4' # 0x00a4 -> CURRENCY SIGN328 u'\ufe84' # 0x00a5 -> ARABIC LETTER ALEF WITH HAMZA ABOVE FINAL FORM329 u'\ufffe' # 0x00a6 -> UNDEFINED330 u'\ufffe' # 0x00a7 -> UNDEFINED331 u'\ufe8e' # 0x00a8 -> ARABIC LETTER ALEF FINAL FORM332 u'\ufe8f' # 0x00a9 -> ARABIC LETTER BEH ISOLATED FORM333 u'\ufe95' # 0x00aa -> ARABIC LETTER TEH ISOLATED FORM334 u'\ufe99' # 0x00ab -> ARABIC LETTER THEH ISOLATED FORM335 u'\u060c' # 0x00ac -> ARABIC COMMA336 u'\ufe9d' # 0x00ad -> ARABIC LETTER JEEM ISOLATED FORM337 u'\ufea1' # 0x00ae -> ARABIC LETTER HAH ISOLATED FORM338 u'\ufea5' # 0x00af -> ARABIC LETTER KHAH ISOLATED FORM339 u'\u0660' # 0x00b0 -> ARABIC-INDIC DIGIT ZERO340 u'\u0661' # 0x00b1 -> ARABIC-INDIC DIGIT ONE341 u'\u0662' # 0x00b2 -> ARABIC-INDIC DIGIT TWO342 u'\u0663' # 0x00b3 -> ARABIC-INDIC DIGIT THREE343 u'\u0664' # 0x00b4 -> ARABIC-INDIC DIGIT FOUR344 u'\u0665' # 0x00b5 -> ARABIC-INDIC DIGIT FIVE345 u'\u0666' # 0x00b6 -> ARABIC-INDIC DIGIT SIX346 u'\u0667' # 0x00b7 -> ARABIC-INDIC DIGIT SEVEN347 u'\u0668' # 0x00b8 -> ARABIC-INDIC DIGIT EIGHT348 u'\u0669' # 0x00b9 -> ARABIC-INDIC DIGIT NINE349 u'\ufed1' # 0x00ba -> ARABIC LETTER FEH ISOLATED FORM350 u'\u061b' # 0x00bb -> ARABIC SEMICOLON351 u'\ufeb1' # 0x00bc -> ARABIC LETTER SEEN ISOLATED FORM352 u'\ufeb5' # 0x00bd -> ARABIC LETTER SHEEN ISOLATED FORM353 u'\ufeb9' # 0x00be -> ARABIC LETTER SAD ISOLATED FORM354 u'\u061f' # 0x00bf -> ARABIC QUESTION MARK355 u'\xa2' # 0x00c0 -> CENT SIGN356 u'\ufe80' # 0x00c1 -> ARABIC LETTER HAMZA ISOLATED FORM357 u'\ufe81' # 0x00c2 -> ARABIC LETTER ALEF WITH MADDA ABOVE ISOLATED FORM358 u'\ufe83' # 0x00c3 -> ARABIC LETTER ALEF WITH HAMZA ABOVE ISOLATED FORM359 u'\ufe85' # 0x00c4 -> ARABIC LETTER WAW WITH HAMZA ABOVE ISOLATED FORM360 u'\ufeca' # 0x00c5 -> ARABIC LETTER AIN FINAL FORM361 u'\ufe8b' # 0x00c6 -> ARABIC LETTER YEH WITH HAMZA ABOVE INITIAL FORM362 u'\ufe8d' # 0x00c7 -> ARABIC LETTER ALEF ISOLATED FORM363 u'\ufe91' # 0x00c8 -> ARABIC LETTER BEH INITIAL FORM364 u'\ufe93' # 0x00c9 -> ARABIC LETTER TEH MARBUTA ISOLATED FORM365 u'\ufe97' # 0x00ca -> ARABIC LETTER TEH INITIAL FORM366 u'\ufe9b' # 0x00cb -> ARABIC LETTER THEH INITIAL FORM367 u'\ufe9f' # 0x00cc -> ARABIC LETTER JEEM INITIAL FORM368 u'\ufea3' # 0x00cd -> ARABIC LETTER HAH INITIAL FORM369 u'\ufea7' # 0x00ce -> ARABIC LETTER KHAH INITIAL FORM370 u'\ufea9' # 0x00cf -> ARABIC LETTER DAL ISOLATED FORM371 u'\ufeab' # 0x00d0 -> ARABIC LETTER THAL ISOLATED FORM372 u'\ufead' # 0x00d1 -> ARABIC LETTER REH ISOLATED FORM373 u'\ufeaf' # 0x00d2 -> ARABIC LETTER ZAIN ISOLATED FORM374 u'\ufeb3' # 0x00d3 -> ARABIC LETTER SEEN INITIAL FORM375 u'\ufeb7' # 0x00d4 -> ARABIC LETTER SHEEN INITIAL FORM376 u'\ufebb' # 0x00d5 -> ARABIC LETTER SAD INITIAL FORM377 u'\ufebf' # 0x00d6 -> ARABIC LETTER DAD INITIAL FORM378 u'\ufec1' # 0x00d7 -> ARABIC LETTER TAH ISOLATED FORM379 u'\ufec5' # 0x00d8 -> ARABIC LETTER ZAH ISOLATED FORM380 u'\ufecb' # 0x00d9 -> ARABIC LETTER AIN INITIAL FORM381 u'\ufecf' # 0x00da -> ARABIC LETTER GHAIN INITIAL FORM382 u'\xa6' # 0x00db -> BROKEN VERTICAL BAR383 u'\xac' # 0x00dc -> NOT SIGN384 u'\xf7' # 0x00dd -> DIVISION SIGN385 u'\xd7' # 0x00de -> MULTIPLICATION SIGN386 u'\ufec9' # 0x00df -> ARABIC LETTER AIN ISOLATED FORM387 u'\u0640' # 0x00e0 -> ARABIC TATWEEL388 u'\ufed3' # 0x00e1 -> ARABIC LETTER FEH INITIAL FORM389 u'\ufed7' # 0x00e2 -> ARABIC LETTER QAF INITIAL FORM390 u'\ufedb' # 0x00e3 -> ARABIC LETTER KAF INITIAL FORM391 u'\ufedf' # 0x00e4 -> ARABIC LETTER LAM INITIAL FORM392 u'\ufee3' # 0x00e5 -> ARABIC LETTER MEEM INITIAL FORM393 u'\ufee7' # 0x00e6 -> ARABIC LETTER NOON INITIAL FORM394 u'\ufeeb' # 0x00e7 -> ARABIC LETTER HEH INITIAL FORM395 u'\ufeed' # 0x00e8 -> ARABIC LETTER WAW ISOLATED FORM396 u'\ufeef' # 0x00e9 -> ARABIC LETTER ALEF MAKSURA ISOLATED FORM397 u'\ufef3' # 0x00ea -> ARABIC LETTER YEH INITIAL FORM398 u'\ufebd' # 0x00eb -> ARABIC LETTER DAD ISOLATED FORM399 u'\ufecc' # 0x00ec -> ARABIC LETTER AIN MEDIAL FORM400 u'\ufece' # 0x00ed -> ARABIC LETTER GHAIN FINAL FORM401 u'\ufecd' # 0x00ee -> ARABIC LETTER GHAIN ISOLATED FORM402 u'\ufee1' # 0x00ef -> ARABIC LETTER MEEM ISOLATED FORM403 u'\ufe7d' # 0x00f0 -> ARABIC SHADDA MEDIAL FORM404 u'\u0651' # 0x00f1 -> ARABIC SHADDAH405 u'\ufee5' # 0x00f2 -> ARABIC LETTER NOON ISOLATED FORM406 u'\ufee9' # 0x00f3 -> ARABIC LETTER HEH ISOLATED FORM407 u'\ufeec' # 0x00f4 -> ARABIC LETTER HEH MEDIAL FORM408 u'\ufef0' # 0x00f5 -> ARABIC LETTER ALEF MAKSURA FINAL FORM409 u'\ufef2' # 0x00f6 -> ARABIC LETTER YEH FINAL FORM410 u'\ufed0' # 0x00f7 -> ARABIC LETTER GHAIN MEDIAL FORM411 u'\ufed5' # 0x00f8 -> ARABIC LETTER QAF ISOLATED FORM412 u'\ufef5' # 0x00f9 -> ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE ISOLATED FORM413 u'\ufef6' # 0x00fa -> ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE FINAL FORM414 u'\ufedd' # 0x00fb -> ARABIC LETTER LAM ISOLATED FORM415 u'\ufed9' # 0x00fc -> ARABIC LETTER KAF ISOLATED FORM416 u'\ufef1' # 0x00fd -> ARABIC LETTER YEH ISOLATED FORM417 u'\u25a0' # 0x00fe -> BLACK SQUARE418 u'\ufffe' # 0x00ff -> UNDEFINED419)420### Encoding Map421encoding_map = {422 0x0000: 0x0000, # NULL423 0x0001: 0x0001, # START OF HEADING424 0x0002: 0x0002, # START OF TEXT425 0x0003: 0x0003, # END OF TEXT426 0x0004: 0x0004, # END OF TRANSMISSION427 0x0005: 0x0005, # ENQUIRY428 0x0006: 0x0006, # ACKNOWLEDGE429 0x0007: 0x0007, # BELL430 0x0008: 0x0008, # BACKSPACE431 0x0009: 0x0009, # HORIZONTAL TABULATION432 0x000a: 0x000a, # LINE FEED433 0x000b: 0x000b, # VERTICAL TABULATION434 0x000c: 0x000c, # FORM FEED435 0x000d: 0x000d, # CARRIAGE RETURN436 0x000e: 0x000e, # SHIFT OUT437 0x000f: 0x000f, # SHIFT IN438 0x0010: 0x0010, # DATA LINK ESCAPE439 0x0011: 0x0011, # DEVICE CONTROL ONE440 0x0012: 0x0012, # DEVICE CONTROL TWO441 0x0013: 0x0013, # DEVICE CONTROL THREE442 0x0014: 0x0014, # DEVICE CONTROL FOUR443 0x0015: 0x0015, # NEGATIVE ACKNOWLEDGE444 0x0016: 0x0016, # SYNCHRONOUS IDLE445 0x0017: 0x0017, # END OF TRANSMISSION BLOCK446 0x0018: 0x0018, # CANCEL447 0x0019: 0x0019, # END OF MEDIUM448 0x001a: 0x001a, # SUBSTITUTE449 0x001b: 0x001b, # ESCAPE450 0x001c: 0x001c, # FILE SEPARATOR451 0x001d: 0x001d, # GROUP SEPARATOR452 0x001e: 0x001e, # RECORD SEPARATOR453 0x001f: 0x001f, # UNIT SEPARATOR454 0x0020: 0x0020, # SPACE455 0x0021: 0x0021, # EXCLAMATION MARK456 0x0022: 0x0022, # QUOTATION MARK457 0x0023: 0x0023, # NUMBER SIGN458 0x0024: 0x0024, # DOLLAR SIGN459 0x0026: 0x0026, # AMPERSAND460 0x0027: 0x0027, # APOSTROPHE461 0x0028: 0x0028, # LEFT PARENTHESIS462 0x0029: 0x0029, # RIGHT PARENTHESIS463 0x002a: 0x002a, # ASTERISK464 0x002b: 0x002b, # PLUS SIGN465 0x002c: 0x002c, # COMMA466 0x002d: 0x002d, # HYPHEN-MINUS467 0x002e: 0x002e, # FULL STOP468 0x002f: 0x002f, # SOLIDUS469 0x0030: 0x0030, # DIGIT ZERO470 0x0031: 0x0031, # DIGIT ONE471 0x0032: 0x0032, # DIGIT TWO472 0x0033: 0x0033, # DIGIT THREE473 0x0034: 0x0034, # DIGIT FOUR474 0x0035: 0x0035, # DIGIT FIVE475 0x0036: 0x0036, # DIGIT SIX476 0x0037: 0x0037, # DIGIT SEVEN477 0x0038: 0x0038, # DIGIT EIGHT478 0x0039: 0x0039, # DIGIT NINE479 0x003a: 0x003a, # COLON480 0x003b: 0x003b, # SEMICOLON481 0x003c: 0x003c, # LESS-THAN SIGN482 0x003d: 0x003d, # EQUALS SIGN483 0x003e: 0x003e, # GREATER-THAN SIGN484 0x003f: 0x003f, # QUESTION MARK485 0x0040: 0x0040, # COMMERCIAL AT486 0x0041: 0x0041, # LATIN CAPITAL LETTER A487 0x0042: 0x0042, # LATIN CAPITAL LETTER B488 0x0043: 0x0043, # LATIN CAPITAL LETTER C489 0x0044: 0x0044, # LATIN CAPITAL LETTER D490 0x0045: 0x0045, # LATIN CAPITAL LETTER E491 0x0046: 0x0046, # LATIN CAPITAL LETTER F492 0x0047: 0x0047, # LATIN CAPITAL LETTER G493 0x0048: 0x0048, # LATIN CAPITAL LETTER H494 0x0049: 0x0049, # LATIN CAPITAL LETTER I495 0x004a: 0x004a, # LATIN CAPITAL LETTER J496 0x004b: 0x004b, # LATIN CAPITAL LETTER K497 0x004c: 0x004c, # LATIN CAPITAL LETTER L498 0x004d: 0x004d, # LATIN CAPITAL LETTER M499 0x004e: 0x004e, # LATIN CAPITAL LETTER N500 0x004f: 0x004f, # LATIN CAPITAL LETTER O501 0x0050: 0x0050, # LATIN CAPITAL LETTER P502 0x0051: 0x0051, # LATIN CAPITAL LETTER Q503 0x0052: 0x0052, # LATIN CAPITAL LETTER R504 0x0053: 0x0053, # LATIN CAPITAL LETTER S505 0x0054: 0x0054, # LATIN CAPITAL LETTER T506 0x0055: 0x0055, # LATIN CAPITAL LETTER U507 0x0056: 0x0056, # LATIN CAPITAL LETTER V508 0x0057: 0x0057, # LATIN CAPITAL LETTER W509 0x0058: 0x0058, # LATIN CAPITAL LETTER X510 0x0059: 0x0059, # LATIN CAPITAL LETTER Y511 0x005a: 0x005a, # LATIN CAPITAL LETTER Z512 0x005b: 0x005b, # LEFT SQUARE BRACKET513 0x005c: 0x005c, # REVERSE SOLIDUS514 0x005d: 0x005d, # RIGHT SQUARE BRACKET515 0x005e: 0x005e, # CIRCUMFLEX ACCENT516 0x005f: 0x005f, # LOW LINE517 0x0060: 0x0060, # GRAVE ACCENT518 0x0061: 0x0061, # LATIN SMALL LETTER A519 0x0062: 0x0062, # LATIN SMALL LETTER B520 0x0063: 0x0063, # LATIN SMALL LETTER C521 0x0064: 0x0064, # LATIN SMALL LETTER D522 0x0065: 0x0065, # LATIN SMALL LETTER E523 0x0066: 0x0066, # LATIN SMALL LETTER F524 0x0067: 0x0067, # LATIN SMALL LETTER G525 0x0068: 0x0068, # LATIN SMALL LETTER H526 0x0069: 0x0069, # LATIN SMALL LETTER I527 0x006a: 0x006a, # LATIN SMALL LETTER J528 0x006b: 0x006b, # LATIN SMALL LETTER K529 0x006c: 0x006c, # LATIN SMALL LETTER L530 0x006d: 0x006d, # LATIN SMALL LETTER M531 0x006e: 0x006e, # LATIN SMALL LETTER N532 0x006f: 0x006f, # LATIN SMALL LETTER O533 0x0070: 0x0070, # LATIN SMALL LETTER P534 0x0071: 0x0071, # LATIN SMALL LETTER Q535 0x0072: 0x0072, # LATIN SMALL LETTER R536 0x0073: 0x0073, # LATIN SMALL LETTER S537 0x0074: 0x0074, # LATIN SMALL LETTER T538 0x0075: 0x0075, # LATIN SMALL LETTER U539 0x0076: 0x0076, # LATIN SMALL LETTER V540 0x0077: 0x0077, # LATIN SMALL LETTER W541 0x0078: 0x0078, # LATIN SMALL LETTER X542 0x0079: 0x0079, # LATIN SMALL LETTER Y543 0x007a: 0x007a, # LATIN SMALL LETTER Z544 0x007b: 0x007b, # LEFT CURLY BRACKET545 0x007c: 0x007c, # VERTICAL LINE546 0x007d: 0x007d, # RIGHT CURLY BRACKET547 0x007e: 0x007e, # TILDE548 0x007f: 0x007f, # DELETE549 0x00a0: 0x00a0, # NON-BREAKING SPACE550 0x00a2: 0x00c0, # CENT SIGN551 0x00a3: 0x00a3, # POUND SIGN552 0x00a4: 0x00a4, # CURRENCY SIGN553 0x00a6: 0x00db, # BROKEN VERTICAL BAR554 0x00ab: 0x0097, # LEFT POINTING GUILLEMET555 0x00ac: 0x00dc, # NOT SIGN556 0x00ad: 0x00a1, # SOFT HYPHEN557 0x00b0: 0x0080, # DEGREE SIGN558 0x00b1: 0x0093, # PLUS-OR-MINUS SIGN559 0x00b7: 0x0081, # MIDDLE DOT560 0x00bb: 0x0098, # RIGHT POINTING GUILLEMET561 0x00bc: 0x0095, # FRACTION 1/4562 0x00bd: 0x0094, # FRACTION 1/2563 0x00d7: 0x00de, # MULTIPLICATION SIGN564 0x00f7: 0x00dd, # DIVISION SIGN565 0x03b2: 0x0090, # GREEK SMALL BETA566 0x03c6: 0x0092, # GREEK SMALL PHI567 0x060c: 0x00ac, # ARABIC COMMA568 0x061b: 0x00bb, # ARABIC SEMICOLON569 0x061f: 0x00bf, # ARABIC QUESTION MARK570 0x0640: 0x00e0, # ARABIC TATWEEL571 0x0651: 0x00f1, # ARABIC SHADDAH572 0x0660: 0x00b0, # ARABIC-INDIC DIGIT ZERO573 0x0661: 0x00b1, # ARABIC-INDIC DIGIT ONE574 0x0662: 0x00b2, # ARABIC-INDIC DIGIT TWO575 0x0663: 0x00b3, # ARABIC-INDIC DIGIT THREE576 0x0664: 0x00b4, # ARABIC-INDIC DIGIT FOUR577 0x0665: 0x00b5, # ARABIC-INDIC DIGIT FIVE578 0x0666: 0x00b6, # ARABIC-INDIC DIGIT SIX579 0x0667: 0x00b7, # ARABIC-INDIC DIGIT SEVEN580 0x0668: 0x00b8, # ARABIC-INDIC DIGIT EIGHT581 0x0669: 0x00b9, # ARABIC-INDIC DIGIT NINE582 0x066a: 0x0025, # ARABIC PERCENT SIGN583 0x2219: 0x0082, # BULLET OPERATOR584 0x221a: 0x0083, # SQUARE ROOT585 0x221e: 0x0091, # INFINITY586 0x2248: 0x0096, # ALMOST EQUAL TO587 0x2500: 0x0085, # FORMS LIGHT HORIZONTAL588 0x2502: 0x0086, # FORMS LIGHT VERTICAL589 0x250c: 0x008d, # FORMS LIGHT DOWN AND RIGHT590 0x2510: 0x008c, # FORMS LIGHT DOWN AND LEFT591 0x2514: 0x008e, # FORMS LIGHT UP AND RIGHT592 0x2518: 0x008f, # FORMS LIGHT UP AND LEFT593 0x251c: 0x008a, # FORMS LIGHT VERTICAL AND RIGHT594 0x2524: 0x0088, # FORMS LIGHT VERTICAL AND LEFT595 0x252c: 0x0089, # FORMS LIGHT DOWN AND HORIZONTAL596 0x2534: 0x008b, # FORMS LIGHT UP AND HORIZONTAL597 0x253c: 0x0087, # FORMS LIGHT VERTICAL AND HORIZONTAL598 0x2592: 0x0084, # MEDIUM SHADE599 0x25a0: 0x00fe, # BLACK SQUARE600 0xfe7d: 0x00f0, # ARABIC SHADDA MEDIAL FORM601 0xfe80: 0x00c1, # ARABIC LETTER HAMZA ISOLATED FORM602 0xfe81: 0x00c2, # ARABIC LETTER ALEF WITH MADDA ABOVE ISOLATED FORM603 0xfe82: 0x00a2, # ARABIC LETTER ALEF WITH MADDA ABOVE FINAL FORM604 0xfe83: 0x00c3, # ARABIC LETTER ALEF WITH HAMZA ABOVE ISOLATED FORM605 0xfe84: 0x00a5, # ARABIC LETTER ALEF WITH HAMZA ABOVE FINAL FORM606 0xfe85: 0x00c4, # ARABIC LETTER WAW WITH HAMZA ABOVE ISOLATED FORM607 0xfe8b: 0x00c6, # ARABIC LETTER YEH WITH HAMZA ABOVE INITIAL FORM608 0xfe8d: 0x00c7, # ARABIC LETTER ALEF ISOLATED FORM609 0xfe8e: 0x00a8, # ARABIC LETTER ALEF FINAL FORM610 0xfe8f: 0x00a9, # ARABIC LETTER BEH ISOLATED FORM611 0xfe91: 0x00c8, # ARABIC LETTER BEH INITIAL FORM612 0xfe93: 0x00c9, # ARABIC LETTER TEH MARBUTA ISOLATED FORM613 0xfe95: 0x00aa, # ARABIC LETTER TEH ISOLATED FORM614 0xfe97: 0x00ca, # ARABIC LETTER TEH INITIAL FORM615 0xfe99: 0x00ab, # ARABIC LETTER THEH ISOLATED FORM616 0xfe9b: 0x00cb, # ARABIC LETTER THEH INITIAL FORM617 0xfe9d: 0x00ad, # ARABIC LETTER JEEM ISOLATED FORM618 0xfe9f: 0x00cc, # ARABIC LETTER JEEM INITIAL FORM619 0xfea1: 0x00ae, # ARABIC LETTER HAH ISOLATED FORM620 0xfea3: 0x00cd, # ARABIC LETTER HAH INITIAL FORM621 0xfea5: 0x00af, # ARABIC LETTER KHAH ISOLATED FORM622 0xfea7: 0x00ce, # ARABIC LETTER KHAH INITIAL FORM623 0xfea9: 0x00cf, # ARABIC LETTER DAL ISOLATED FORM624 0xfeab: 0x00d0, # ARABIC LETTER THAL ISOLATED FORM625 0xfead: 0x00d1, # ARABIC LETTER REH ISOLATED FORM626 0xfeaf: 0x00d2, # ARABIC LETTER ZAIN ISOLATED FORM627 0xfeb1: 0x00bc, # ARABIC LETTER SEEN ISOLATED FORM628 0xfeb3: 0x00d3, # ARABIC LETTER SEEN INITIAL FORM629 0xfeb5: 0x00bd, # ARABIC LETTER SHEEN ISOLATED FORM630 0xfeb7: 0x00d4, # ARABIC LETTER SHEEN INITIAL FORM631 0xfeb9: 0x00be, # ARABIC LETTER SAD ISOLATED FORM632 0xfebb: 0x00d5, # ARABIC LETTER SAD INITIAL FORM633 0xfebd: 0x00eb, # ARABIC LETTER DAD ISOLATED FORM634 0xfebf: 0x00d6, # ARABIC LETTER DAD INITIAL FORM635 0xfec1: 0x00d7, # ARABIC LETTER TAH ISOLATED FORM636 0xfec5: 0x00d8, # ARABIC LETTER ZAH ISOLATED FORM637 0xfec9: 0x00df, # ARABIC LETTER AIN ISOLATED FORM638 0xfeca: 0x00c5, # ARABIC LETTER AIN FINAL FORM639 0xfecb: 0x00d9, # ARABIC LETTER AIN INITIAL FORM640 0xfecc: 0x00ec, # ARABIC LETTER AIN MEDIAL FORM641 0xfecd: 0x00ee, # ARABIC LETTER GHAIN ISOLATED FORM642 0xfece: 0x00ed, # ARABIC LETTER GHAIN FINAL FORM643 0xfecf: 0x00da, # ARABIC LETTER GHAIN INITIAL FORM644 0xfed0: 0x00f7, # ARABIC LETTER GHAIN MEDIAL FORM645 0xfed1: 0x00ba, # ARABIC LETTER FEH ISOLATED FORM646 0xfed3: 0x00e1, # ARABIC LETTER FEH INITIAL FORM647 0xfed5: 0x00f8, # ARABIC LETTER QAF ISOLATED FORM648 0xfed7: 0x00e2, # ARABIC LETTER QAF INITIAL FORM649 0xfed9: 0x00fc, # ARABIC LETTER KAF ISOLATED FORM650 0xfedb: 0x00e3, # ARABIC LETTER KAF INITIAL FORM651 0xfedd: 0x00fb, # ARABIC LETTER LAM ISOLATED FORM652 0xfedf: 0x00e4, # ARABIC LETTER LAM INITIAL FORM653 0xfee1: 0x00ef, # ARABIC LETTER MEEM ISOLATED FORM654 0xfee3: 0x00e5, # ARABIC LETTER MEEM INITIAL FORM655 0xfee5: 0x00f2, # ARABIC LETTER NOON ISOLATED FORM656 0xfee7: 0x00e6, # ARABIC LETTER NOON INITIAL FORM657 0xfee9: 0x00f3, # ARABIC LETTER HEH ISOLATED FORM658 0xfeeb: 0x00e7, # ARABIC LETTER HEH INITIAL FORM659 0xfeec: 0x00f4, # ARABIC LETTER HEH MEDIAL FORM660 0xfeed: 0x00e8, # ARABIC LETTER WAW ISOLATED FORM661 0xfeef: 0x00e9, # ARABIC LETTER ALEF MAKSURA ISOLATED FORM662 0xfef0: 0x00f5, # ARABIC LETTER ALEF MAKSURA FINAL FORM663 0xfef1: 0x00fd, # ARABIC LETTER YEH ISOLATED FORM664 0xfef2: 0x00f6, # ARABIC LETTER YEH FINAL FORM665 0xfef3: 0x00ea, # ARABIC LETTER YEH INITIAL FORM666 0xfef5: 0x00f9, # ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE ISOLATED FORM667 0xfef6: 0x00fa, # ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE FINAL FORM668 0xfef7: 0x0099, # ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE ISOLATED FORM669 0xfef8: 0x009a, # ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE FINAL FORM670 0xfefb: 0x009d, # ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM671 0xfefc: 0x009e, # ARABIC LIGATURE LAM WITH ALEF FINAL FORM...
form.test.js
Source:form.test.js
...25 afterEach(function () {26 $(elementId).remove();27 });28 it('check if form can be initialized', function () {29 var form = $(elementId).form();30 expect(form.is(':mage-form')).toBeTruthy();31 });32 it('check get handlers', function () {33 var form = $(elementId).form(),34 handlersData = form.form('option', 'handlersData'),35 handlers = [];36 $.each(handlersData, function (key) {37 handlers.push(key);38 });39 expect(handlers.join(' ')).toBe(form.data('form')._getHandlers().join(' '));40 });41 it('check store attribute', function () {42 var form = $(elementId).form(),43 initialFormAttrs = {44 action: form.attr('action'),45 target: form.attr('target'),46 method: form.attr('method')47 };48 form.data('form')._storeAttribute('action');49 form.data('form')._storeAttribute('target');50 form.data('form')._storeAttribute('method');51 expect(form.data('form').oldAttributes.action).toBe(initialFormAttrs.action);52 expect(form.data('form').oldAttributes.target).toBe(initialFormAttrs.target);53 expect(form.data('form').oldAttributes.method).toBe(initialFormAttrs.method);54 });55 it('check bind', function () {56 var form = $(elementId).form(),57 submitted = false,58 handlersData = form.form('option', 'handlersData');59 form.on('submit', function (e) {60 submitted = true;61 e.stopImmediatePropagation();62 e.preventDefault();63 });64 $.each(handlersData, function (key) {65 form.trigger(key);66 expect(submitted).toBeTruthy();67 submitted = false;68 });69 form.off('submit');70 });71 it('check get action URL', function () {72 var form = $(elementId).form(),73 action = form.attr('action'),74 testUrl = 'new/action/url',75 testArgs = {76 args: {77 arg: 'value'78 }79 };80 form.data('form')._storeAttribute('action');81 expect(form.data('form')._getActionUrl(testArgs)).toBe(action + '/arg/value/');82 expect(form.data('form')._getActionUrl(testUrl)).toBe(testUrl);83 expect(form.data('form')._getActionUrl()).toBe(action);84 });85 it('check process data', function () {86 var form = $(elementId).form(),87 initialFormAttrs = {88 action: form.attr('action'),89 target: form.attr('target'),90 method: form.attr('method')91 },92 testSimpleData = {93 action: 'new/action/url',94 target: '_blank',95 method: 'POST'96 },97 testActionArgsData = {98 action: {99 args: {100 arg: 'value'101 }102 }103 },104 processedData = form.data('form')._processData(testSimpleData);105 expect(form.data('form').oldAttributes.action).toBe(initialFormAttrs.action);106 expect(form.data('form').oldAttributes.target).toBe(initialFormAttrs.target);107 expect(form.data('form').oldAttributes.method).toBe(initialFormAttrs.method);108 expect(processedData.action).toBe(testSimpleData.action);109 expect(processedData.target).toBe(testSimpleData.target);110 expect(processedData.method).toBe(testSimpleData.method);111 form.data('form')._rollback();112 processedData = form.data('form')._processData(testActionArgsData);113 form.data('form')._storeAttribute('action');114 expect(processedData.action).toBe(form.data('form')._getActionUrl(testActionArgsData.action));115 });116 it('check before submit', function () {117 var testForm = $('<form id="test-form"></form>').appendTo('body'),118 testHandler = {119 action: {120 args: {121 arg1: 'value1'122 }123 }124 },125 form = $(elementId).form({126 handlersData: {127 testHandler: testHandler128 }129 }),130 beforeSubmitData = {131 action: {132 args: {133 arg2: 'value2'134 }135 },136 target: '_blank'137 },138 eventData = {139 method: 'POST'140 },141 resultData = $.extend(true, {}, testHandler, beforeSubmitData, eventData);142 form.data('form')._storeAttribute('action');143 resultData = form.data('form')._processData(resultData);144 testForm.prop(resultData);145 form.on('beforeSubmit', function (e, data) {146 $.extend(data, beforeSubmitData);147 });148 form.on('submit', function (e) {149 e.stopImmediatePropagation();150 e.preventDefault();151 });152 form.data('form')._beforeSubmit('testHandler', eventData);153 expect(testForm.prop('action')).toBe(form.prop('action'));154 expect(testForm.prop('target')).toBe(form.prop('target'));155 expect(testForm.prop('method')).toBe(form.prop('method'));156 });157 it('check submit', function () {158 var formSubmitted = false,159 form = $(elementId).form({160 handlersData: {161 save: {}162 }163 });164 form.data('form')._storeAttribute('action');165 form.data('form')._storeAttribute('target');166 form.data('form')._storeAttribute('method');167 form.on('submit', function (e) {168 e.preventDefault();169 e.stopImmediatePropagation();170 e.preventDefault();171 formSubmitted = true;172 }).prop({173 action: 'new/action/url',...
extended_login_form.py
Source:extended_login_form.py
...58 """59 if hasattr(self.alt_login_form, 'logout_url'):60 return self.alt_login_form.logout_url(next)61 return next62 def login_form(self):63 """64 Combine the auth() form with alt_login_form.65 If signals are set and a parameter in request matches any signals,66 it will return the call of alt_login_form.login_form instead.67 So alt_login_form can handle some particular situations, for example,68 multiple steps of OpenID login inside alt_login_form.login_form.69 Otherwise it will render the normal login form combined with70 alt_login_form.login_form.71 """72 request = current.request73 args = request.args74 if (self.signals and75 any([True for signal in self.signals if signal in request.vars])76 ):77 return self.alt_login_form.login_form()78 self.auth.settings.login_form = self.auth79 form = DIV(self.auth())80 self.auth.settings.login_form = self81 form.components.append(self.alt_login_form.login_form())...
index.js
Source:index.js
1export { default as BookingDatesForm } from './BookingDatesForm/BookingDatesForm';2export { default as ContactDetailsForm } from './ContactDetailsForm/ContactDetailsForm';3export { default as EditListingAvailabilityForm } from './EditListingAvailabilityForm/EditListingAvailabilityForm';4export { default as EditListingDescriptionForm } from './EditListingDescriptionForm/EditListingDescriptionForm';5export { default as EditListingFeaturesForm } from './EditListingFeaturesForm/EditListingFeaturesForm';6export { default as EditListingLocationForm } from './EditListingLocationForm/EditListingLocationForm';7export { default as EditListingPhotosForm } from './EditListingPhotosForm/EditListingPhotosForm';8export { default as EditListingPoliciesForm } from './EditListingPoliciesForm/EditListingPoliciesForm';9export { default as EditListingPricingForm } from './EditListingPricingForm/EditListingPricingForm';10export { default as EmailVerificationForm } from './EmailVerificationForm/EmailVerificationForm';11export { default as EnquiryForm } from './EnquiryForm/EnquiryForm';12export { default as FilterForm } from './FilterForm/FilterForm';13export { default as LocationSearchForm } from './LocationSearchForm/LocationSearchForm';14export { default as LoginForm } from './LoginForm/LoginForm';15export { default as PasswordChangeForm } from './PasswordChangeForm/PasswordChangeForm';16export { default as PasswordRecoveryForm } from './PasswordRecoveryForm/PasswordRecoveryForm';17export { default as PasswordResetForm } from './PasswordResetForm/PasswordResetForm';18export { default as PaymentMethodsForm } from './PaymentMethodsForm/PaymentMethodsForm';19export { default as PayoutDetailsForm } from './PayoutDetailsForm/PayoutDetailsForm';20export { default as PriceFilterForm } from './PriceFilterForm/PriceFilterForm';21export { default as ProfileSettingsForm } from './ProfileSettingsForm/ProfileSettingsForm';22export { default as ReviewForm } from './ReviewForm/ReviewForm';23export { default as SendMessageForm } from './SendMessageForm/SendMessageForm';24export { default as SignupForm } from './SignupForm/SignupForm';25export { default as StripePaymentForm } from './StripePaymentForm/StripePaymentForm';26export { default as TopbarSearchForm } from './TopbarSearchForm/TopbarSearchForm';27export { default as EditListingNumberOfPeopleForm} from "./EditListingNumberOfPeopleForm/EditListingNumberOfPeopleForm";28export { default as EditListingAnimalsForm} from "./EditListingAnimalsForm/EditListingAnimalsForm";...
test_forms.py
Source:test_forms.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3from django.test import TestCase4from lists.forms import (5 DUPLICATE_ITEM_ERROR, EMPTY_LIST_ERROR,6 ExistingListItemForm, ItemForm7)8from lists.models import Item, List9class ItemFormTest(TestCase):10 def test_form_renders_item_text_input(self):11 form = ItemForm()12 self.assertTrue(form.as_p())13 def test_form_item_input_has_placeholder_and_css_classes(self):14 form = ItemForm()15 self.assertIn('placeholder="Enter a to-do item"', form.as_p())16 self.assertIn('class="form-control input-lg"', form.as_p())17 def test_form_validation_for_blank_items(self):18 form = ItemForm(data={'text': ''})19 self.assertFalse(form.is_valid())20 self.assertEqual(form.errors['text'], [EMPTY_LIST_ERROR])21 def test_form_save_handles_saving_to_a_list(self):22 list_ = List.objects.create()23 form = ItemForm(data={'text': 'do me'})24 new_item = form.save(for_list=list_)25 self.assertEqual(new_item, Item.objects.first())26 self.assertEqual(new_item.text, 'do me')27 self.assertEqual(new_item.list, list_)28class ExistingListItemFormTest(TestCase):29 def test_form_renders_item_text_input(self):30 list_ = List.objects.create()31 form = ExistingListItemForm(for_list=list_)32 self.assertIn('placeholder="Enter a to-do item', form.as_p())33 def test_form_validation_for_blank_items(self):34 list_ = List.objects.create()35 form = ExistingListItemForm(for_list=list_, data={'text': ''})36 self.assertFalse(form.is_valid())37 self.assertEqual(form.errors['text'], [EMPTY_LIST_ERROR])38 def test_form_validation_for_duplicate_items(self):39 list_ = List.objects.create()40 Item.objects.create(list=list_, text='no twins!')41 form = ExistingListItemForm(for_list=list_, data={'text': 'no twins!'})42 self.assertFalse(form.is_valid())...
Using AI Code Generation
1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyForm = require('argosy-form')4var argosyService = argosy()5argosyService.pipe(argosyForm()).pipe(argosyService)6var pattern = argosyPattern({7 inputs: {8 },9 outputs: {10 }11})12argosyService.accept(pattern, function (args, callback) {13 callback(null, { name: args.name })14})15argosyService.request(pattern, { name: 'John' }, function (err, response) {16})17argosyService.request(pattern, { name: 'Jane' }, function (err, response) {18})
Using AI Code Generation
1var argosy = require('argosy')2var argosyService = require('argosy-service')3var argosyPattern = require('argosy-pattern')4var argosyForm = require('argosy-form')5var pattern = argosyPattern({6 request: {7 },8 response: {9 }10})11var formService = argosyForm({12 request: {13 },14 response: {15 }16})17var service = argosyService({18})19var argosyInstance = argosy()20argosyInstance.pipe(service).pipe(argosyInstance)21service.accept('test', function (request, callback) {22 console.log('request', request)23 callback(null, {24 headers: {},25 })26})27argosyInstance.accept({test: 'test'}, formService(function (request, callback) {28 console.log('request', request)29 callback(null, {30 headers: {},31 })32}))33var argosy = require('argosy')34var argosyService = require('argosy-service')35var argosyPattern = require('argosy-pattern')36var argosyForm = require('argosy-form')37var pattern = argosyPattern({38 request: {39 },40 response: {41 }42})43var formService = argosyForm({44 request: {45 },46 response: {
Using AI Code Generation
1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var service = argosy()4service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)5service.on('error', function (err) {6 console.error(err)7})8service.accept({ role: 'math', cmd: 'sum' }, function (msg, cb) {9 console.log(msg)10 cb(null, { answer: msg.left + msg.right })11})12service.accept({ role: 'math', cmd: 'product' }, function (msg, cb) {13 cb(null, { answer: msg.left * msg.right })14})15service.accept({ role: 'math', cmd: 'sum', integer: true }, function (msg, cb) {16 cb(null, Math.floor(msg.left) + Math.floor(msg.right))17})18service.accept({ role: 'math', cmd: 'product', integer: true }, function (msg, cb) {19 cb(null, Math.floor(msg.left) * Math.floor(msg.right))20})21var argosy = require('argosy')22var argosyPattern = require('argosy-pattern')23var service = argosy()24service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)25service.on('error', function (err) {26 console.error(err)27})28service.accept({ role: 'math', cmd: 'sum' }, function (msg, cb) {29 console.log(msg)30 cb(null, { answer: msg.left + msg.right })31})32service.accept({ role: 'math', cmd: 'product' }, function (msg, cb) {33 cb(null, { answer: msg.left * msg.right })34})35service.accept({ role: 'math', cmd: 'sum', integer: true }, function (msg, cb) {36 cb(null, Math.floor(msg.left) + Math.floor(msg.right))37})38service.accept({ role: 'math', cmd: 'product', integer: true }, function (msg, cb) {39 cb(null, Math.floor(msg.left) * Math.floor(msg.right))40})41var argosy = require('argosy')42var argosyPattern = require('
Using AI Code Generation
1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyService = require('argosy-service')4var argosyForm = require('argosy-form')5var argosyPipeline = require('argosy-pipeline')6var argosyHttp = require('argosy-http')7var argosyTransport = require('argosy-transport')8var argosyReceiver = require('argosy-receiver')9var argosySender = require('argosy-sender')10var pipeline = argosyPipeline()11var form = argosyForm()12var service = argosyService()13var transport = argosyTransport()14var receiver = argosyReceiver()15var sender = argosySender()16var http = argosyHttp()17pipeline.pipe(form).pipe(service).pipe(transport).pipe(receiver).pipe(sender).pipe(pipeline)18var argosy = argosy()19argosy.pipe(pipeline).pipe(argosy)20var formPattern = pattern({21 form: pattern.object({22 })23})24var formService = argosy.service(formPattern, function (msg, cb) {25 console.log('form submitted', msg.form)26 cb(null, {27 })28})29formService.pipe(argosy).pipe(formService)30var express = require('express')31var app = express()32app.use(express.static(__dirname + '/public'))33app.use('/argosy', http)34app.listen(3000, function () {35 console.log('listening on port 3000')36})37 .form-group {38 margin-bottom: 15px;39 }
Using AI Code Generation
1const argosy = require('argosy')2const pattern = require('argosy-pattern')3const request = require('request')4const form = require('argosy-form')5const service = argosy()6service.pipe(form()).pipe(argosy.acceptor({7})).pipe(service)8service.accept({9 test: pattern.match('hello')10}, (msg, cb) => {11 cb(null, 'world')12})13service.accept({14 test: pattern.match('test')15}, (msg, cb) => {16 cb(null, 'test')17})18service.accept({19 test: pattern.match('test2')20}, (msg, cb) => {21 cb(null, 'test2')22})23service.accept({24 test: pattern.match('test3')25}, (msg, cb) => {26 cb(null, 'test3')27})28service.accept({29 test: pattern.match('test4')30}, (msg, cb) => {31 cb(null, 'test4')32})33service.accept({34 test: pattern.match('test5')35}, (msg, cb) => {36 cb(null, 'test5')37})38service.accept({39 test: pattern.match('test6')40}, (msg, cb) => {41 cb(null, 'test6')42})43service.accept({44 test: pattern.match('test7')45}, (msg, cb) => {46 cb(null, 'test7')47})48service.accept({49 test: pattern.match('test8')50}, (msg, cb) => {51 cb(null, 'test8')52})53service.accept({54 test: pattern.match('test9')55}, (msg, cb) => {56 cb(null, 'test9')57})58service.accept({59 test: pattern.match('test10')60}, (msg, cb) => {61 cb(null, 'test10')62})63service.accept({64 test: pattern.match('test11')65}, (msg, cb) => {66 cb(null, 'test11')67})68service.accept({69 test: pattern.match('test12')70}, (msg, cb) => {71 cb(null, 'test12')72})
Using AI Code Generation
1var form = require('..').form2var argosy = require('argosy')3var transport = require('argosy-pattern/transport')4var pattern = require('argosy-pattern')5var through = require('through2')6var pump = require('pump')7var concat = require('concat-stream')8var test = require('tape')9test('form: basic test', function (t) {10 t.plan(2)11 var service = argosy()12 service.use('foo', function (msg, cb) {13 cb(null, {bar: 'baz'})14 })15 var client = argosy()16 client.pipe(form(service)).pipe(client)17 client.accept({foo: 'bar'}, function (err, res) {18 t.error(err)19 t.deepEqual(res, {bar: 'baz'})20 })21})22test('form: multiple messages', function (t) {23 t.plan(2)24 var service = argosy()25 service.use('foo', function (msg, cb) {26 cb(null, {bar: 'baz'})27 })28 var client = argosy()29 client.pipe(form(service)).pipe(client)30 client.accept({foo: 'bar'}, function (err, res) {31 t.error(err)32 t.deepEqual(res, {bar: 'baz'})33 })34 client.accept({foo: 'bar'}, function (err, res) {35 t.error(err)36 t.deepEqual(res, {bar: 'baz'})37 })38})39test('form: multiple messages with multiple services', function (t) {40 t.plan(4)41 var service = argosy()42 service.use('foo', function (msg, cb) {43 cb(null, {bar: 'baz'})44 })45 var service2 = argosy()46 service2.use('foo', function (msg, cb) {47 cb(null, {bar: 'baz'})48 })49 var client = argosy()50 client.pipe(form(service)).pipe(form(service2)).pipe(client)51 client.accept({foo: 'bar'}, function (err, res) {52 t.error(err)53 t.deepEqual(res, {bar: 'baz'})54 })55 client.accept({foo: 'bar'}, function (err, res) {56 t.error(err)57 t.deepEqual(res, {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!