Mercurial > p > roundup > code
comparison roundup/cgi/TAL/TALInterpreter.py @ 5393:46b2fd6d342e
Python 3 preparation: avoid implicit tuple parameter unpacking.
Tool-assisted patch.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 23:02:44 +0000 |
| parents | d26921b851c3 |
| children | 2120f77554d5 |
comparison
equal
deleted
inserted
replaced
| 5392:a7bf8c4e502f | 5393:46b2fd6d342e |
|---|---|
| 263 | 263 |
| 264 def do_startEndTag(self, stuff): | 264 def do_startEndTag(self, stuff): |
| 265 self.do_startTag(stuff, self.endsep, self.endlen) | 265 self.do_startTag(stuff, self.endsep, self.endlen) |
| 266 bytecode_handlers["startEndTag"] = do_startEndTag | 266 bytecode_handlers["startEndTag"] = do_startEndTag |
| 267 | 267 |
| 268 def do_startTag(self, (name, attrList), | 268 def do_startTag(self, name_attrList, |
| 269 end=">", endlen=1, _len=len): | 269 end=">", endlen=1, _len=len): |
| 270 # The bytecode generator does not cause calls to this method | 270 # The bytecode generator does not cause calls to this method |
| 271 # for start tags with no attributes; those are optimized down | 271 # for start tags with no attributes; those are optimized down |
| 272 # to rawtext events. Hence, there is no special "fast path" | 272 # to rawtext events. Hence, there is no special "fast path" |
| 273 # for that case. | 273 # for that case. |
| 274 (name, attrList) = name_attrList | |
| 274 L = ["<", name] | 275 L = ["<", name] |
| 275 append = L.append | 276 append = L.append |
| 276 col = self.col + _len(name) + 1 | 277 col = self.col + _len(name) + 1 |
| 277 wrap = self.wrap | 278 wrap = self.wrap |
| 278 align = col + 1 | 279 align = col + 1 |
| 388 self._stream_write = stream.write | 389 self._stream_write = stream.write |
| 389 self.interpret(start) | 390 self.interpret(start) |
| 390 self.restoreOutputState(state) | 391 self.restoreOutputState(state) |
| 391 self.interpret(program) | 392 self.interpret(program) |
| 392 | 393 |
| 393 def do_optTag(self, (name, cexpr, tag_ns, isend, start, program), | 394 def do_optTag(self, args_tuple, |
| 394 omit=0): | 395 omit=0): |
| 396 (name, cexpr, tag_ns, isend, start, program) = args_tuple | |
| 395 if tag_ns and not self.showtal: | 397 if tag_ns and not self.showtal: |
| 396 return self.no_tag(start, program) | 398 return self.no_tag(start, program) |
| 397 | 399 |
| 398 self.interpret(start) | 400 self.interpret(start) |
| 399 if not isend: | 401 if not isend: |
| 409 self.no_tag(stuff[-2], stuff[-1]) | 411 self.no_tag(stuff[-2], stuff[-1]) |
| 410 else: | 412 else: |
| 411 self.do_optTag(stuff) | 413 self.do_optTag(stuff) |
| 412 bytecode_handlers["optTag"] = do_optTag | 414 bytecode_handlers["optTag"] = do_optTag |
| 413 | 415 |
| 414 def do_rawtextBeginScope(self, (s, col, position, closeprev, dict)): | 416 def do_rawtextBeginScope(self, args_tuple): |
| 417 (s, col, position, closeprev, dict) = args_tuple | |
| 415 self._stream_write(s) | 418 self._stream_write(s) |
| 416 self.col = col | 419 self.col = col |
| 417 self.position = position | 420 self.position = position |
| 418 self.engine.setPosition(position) | 421 self.engine.setPosition(position) |
| 419 if closeprev: | 422 if closeprev: |
| 422 engine.beginScope() | 425 engine.beginScope() |
| 423 else: | 426 else: |
| 424 self.engine.beginScope() | 427 self.engine.beginScope() |
| 425 self.scopeLevel = self.scopeLevel + 1 | 428 self.scopeLevel = self.scopeLevel + 1 |
| 426 | 429 |
| 427 def do_rawtextBeginScope_tal(self, (s, col, position, closeprev, dict)): | 430 def do_rawtextBeginScope_tal(self, args_tuple): |
| 431 (s, col, position, closeprev, dict) = args_tuple | |
| 428 self._stream_write(s) | 432 self._stream_write(s) |
| 429 self.col = col | 433 self.col = col |
| 430 engine = self.engine | 434 engine = self.engine |
| 431 self.position = position | 435 self.position = position |
| 432 engine.setPosition(position) | 436 engine.setPosition(position) |
| 456 bytecode_handlers["endScope"] = do_endScope | 460 bytecode_handlers["endScope"] = do_endScope |
| 457 | 461 |
| 458 def do_setLocal(self, notused): | 462 def do_setLocal(self, notused): |
| 459 pass | 463 pass |
| 460 | 464 |
| 461 def do_setLocal_tal(self, (name, expr)): | 465 def do_setLocal_tal(self, name_expr): |
| 466 (name, expr) = name_expr | |
| 462 self.engine.setLocal(name, self.engine.evaluateValue(expr)) | 467 self.engine.setLocal(name, self.engine.evaluateValue(expr)) |
| 463 bytecode_handlers["setLocal"] = do_setLocal | 468 bytecode_handlers["setLocal"] = do_setLocal |
| 464 | 469 |
| 465 def do_setGlobal_tal(self, (name, expr)): | 470 def do_setGlobal_tal(self, name_expr): |
| 471 (name, expr) = name_expr | |
| 466 self.engine.setGlobal(name, self.engine.evaluateValue(expr)) | 472 self.engine.setGlobal(name, self.engine.evaluateValue(expr)) |
| 467 bytecode_handlers["setGlobal"] = do_setLocal | 473 bytecode_handlers["setGlobal"] = do_setLocal |
| 468 | 474 |
| 469 def do_beginI18nContext(self, settings): | 475 def do_beginI18nContext(self, settings): |
| 470 get = settings.get | 476 get = settings.get |
| 558 bytecode_handlers['insertTranslation'] = do_insertTranslation | 564 bytecode_handlers['insertTranslation'] = do_insertTranslation |
| 559 | 565 |
| 560 def do_insertStructure(self, stuff): | 566 def do_insertStructure(self, stuff): |
| 561 self.interpret(stuff[2]) | 567 self.interpret(stuff[2]) |
| 562 | 568 |
| 563 def do_insertStructure_tal(self, (expr, repldict, block)): | 569 def do_insertStructure_tal(self, expr_repldict_block): |
| 570 (expr, repldict, block) = expr_repldict_block | |
| 564 structure = self.engine.evaluateStructure(expr) | 571 structure = self.engine.evaluateStructure(expr) |
| 565 if structure is None: | 572 if structure is None: |
| 566 return | 573 return |
| 567 if structure is self.Default: | 574 if structure is self.Default: |
| 568 self.interpret(block) | 575 self.interpret(block) |
| 597 gen.enable(0) | 604 gen.enable(0) |
| 598 p.parseFragment('</foo>', 1) | 605 p.parseFragment('</foo>', 1) |
| 599 program, macros = gen.getCode() | 606 program, macros = gen.getCode() |
| 600 self.interpret(program) | 607 self.interpret(program) |
| 601 | 608 |
| 602 def do_loop(self, (name, expr, block)): | 609 def do_loop(self, name_expr_block): |
| 610 (name, expr, block) = name_expr_block | |
| 603 self.interpret(block) | 611 self.interpret(block) |
| 604 | 612 |
| 605 def do_loop_tal(self, (name, expr, block)): | 613 def do_loop_tal(self, name_expr_block): |
| 614 (name, expr, block) = name_expr_block | |
| 606 iterator = self.engine.setRepeat(name, expr) | 615 iterator = self.engine.setRepeat(name, expr) |
| 607 while iterator.next(): | 616 while iterator.next(): |
| 608 self.interpret(block) | 617 self.interpret(block) |
| 609 bytecode_handlers["loop"] = do_loop | 618 bytecode_handlers["loop"] = do_loop |
| 610 | 619 |
| 615 return msgid | 624 return msgid |
| 616 # XXX We need to pass in one of context or target_language | 625 # XXX We need to pass in one of context or target_language |
| 617 return self.engine.translate(self.i18nContext.domain, | 626 return self.engine.translate(self.i18nContext.domain, |
| 618 msgid, i18ndict, default=default) | 627 msgid, i18ndict, default=default) |
| 619 | 628 |
| 620 def do_rawtextColumn(self, (s, col)): | 629 def do_rawtextColumn(self, s_col): |
| 630 (s, col) = s_col | |
| 621 self._stream_write(s) | 631 self._stream_write(s) |
| 622 self.col = col | 632 self.col = col |
| 623 bytecode_handlers["rawtextColumn"] = do_rawtextColumn | 633 bytecode_handlers["rawtextColumn"] = do_rawtextColumn |
| 624 | 634 |
| 625 def do_rawtextOffset(self, (s, offset)): | 635 def do_rawtextOffset(self, s_offset): |
| 636 (s, offset) = s_offset | |
| 626 self._stream_write(s) | 637 self._stream_write(s) |
| 627 self.col = self.col + offset | 638 self.col = self.col + offset |
| 628 bytecode_handlers["rawtextOffset"] = do_rawtextOffset | 639 bytecode_handlers["rawtextOffset"] = do_rawtextOffset |
| 629 | 640 |
| 630 def do_condition(self, (condition, block)): | 641 def do_condition(self, condition_block): |
| 642 (condition, block) = condition_block | |
| 631 if not self.tal or self.engine.evaluateBoolean(condition): | 643 if not self.tal or self.engine.evaluateBoolean(condition): |
| 632 self.interpret(block) | 644 self.interpret(block) |
| 633 bytecode_handlers["condition"] = do_condition | 645 bytecode_handlers["condition"] = do_condition |
| 634 | 646 |
| 635 def do_defineMacro(self, (macroName, macro)): | 647 def do_defineMacro(self, macroName_macro): |
| 648 (macroName, macro) = macroName_macro | |
| 636 macs = self.macroStack | 649 macs = self.macroStack |
| 637 if len(macs) == 1: | 650 if len(macs) == 1: |
| 638 entering = macs[-1][2] | 651 entering = macs[-1][2] |
| 639 if not entering: | 652 if not entering: |
| 640 macs.append(None) | 653 macs.append(None) |
| 643 macs.pop() | 656 macs.pop() |
| 644 return | 657 return |
| 645 self.interpret(macro) | 658 self.interpret(macro) |
| 646 bytecode_handlers["defineMacro"] = do_defineMacro | 659 bytecode_handlers["defineMacro"] = do_defineMacro |
| 647 | 660 |
| 648 def do_useMacro(self, (macroName, macroExpr, compiledSlots, block)): | 661 def do_useMacro(self, args_tuple): |
| 662 (macroName, macroExpr, compiledSlots, block) = args_tuple | |
| 649 if not self.metal: | 663 if not self.metal: |
| 650 self.interpret(block) | 664 self.interpret(block) |
| 651 return | 665 return |
| 652 macro = self.engine.evaluateMacro(macroExpr) | 666 macro = self.engine.evaluateMacro(macroExpr) |
| 653 if macro is self.Default: | 667 if macro is self.Default: |
| 668 self.engine.setSourceFile(prev_source) | 682 self.engine.setSourceFile(prev_source) |
| 669 self.sourceFile = prev_source | 683 self.sourceFile = prev_source |
| 670 self.popMacro() | 684 self.popMacro() |
| 671 bytecode_handlers["useMacro"] = do_useMacro | 685 bytecode_handlers["useMacro"] = do_useMacro |
| 672 | 686 |
| 673 def do_fillSlot(self, (slotName, block)): | 687 def do_fillSlot(self, slotName_block): |
| 674 # This is only executed if the enclosing 'use-macro' evaluates | 688 # This is only executed if the enclosing 'use-macro' evaluates |
| 675 # to 'default'. | 689 # to 'default'. |
| 690 (slotName, block) = slotName_block | |
| 676 self.interpret(block) | 691 self.interpret(block) |
| 677 bytecode_handlers["fillSlot"] = do_fillSlot | 692 bytecode_handlers["fillSlot"] = do_fillSlot |
| 678 | 693 |
| 679 def do_defineSlot(self, (slotName, block)): | 694 def do_defineSlot(self, slotName_block): |
| 695 (slotName, block) = slotName_block | |
| 680 if not self.metal: | 696 if not self.metal: |
| 681 self.interpret(block) | 697 self.interpret(block) |
| 682 return | 698 return |
| 683 macs = self.macroStack | 699 macs = self.macroStack |
| 684 if macs and macs[-1] is not None: | 700 if macs and macs[-1] is not None: |
| 695 self.pushMacro(macroName, slots) | 711 self.pushMacro(macroName, slots) |
| 696 # Falling out of the 'if' allows the macro to be interpreted. | 712 # Falling out of the 'if' allows the macro to be interpreted. |
| 697 self.interpret(block) | 713 self.interpret(block) |
| 698 bytecode_handlers["defineSlot"] = do_defineSlot | 714 bytecode_handlers["defineSlot"] = do_defineSlot |
| 699 | 715 |
| 700 def do_onError(self, (block, handler)): | 716 def do_onError(self, block_handler): |
| 717 (block, handler) = block_handler | |
| 701 self.interpret(block) | 718 self.interpret(block) |
| 702 | 719 |
| 703 def do_onError_tal(self, (block, handler)): | 720 def do_onError_tal(self, block_handler): |
| 721 (block, handler) = block_handler | |
| 704 state = self.saveState() | 722 state = self.saveState() |
| 705 self.stream = stream = self.StringIO() | 723 self.stream = stream = self.StringIO() |
| 706 self._stream_write = stream.write | 724 self._stream_write = stream.write |
| 707 try: | 725 try: |
| 708 self.interpret(block) | 726 self.interpret(block) |
