Best Python code snippet using pandera_python
z3printer.py
Source:z3printer.py
...322 return '<line-break>'323 def space_upto_nl(self):324 return (0, True)325 def flat(self):326 return to_format(self.space)327class StringFormatObject(FormatObject):328 def __init__(self, string):329 assert isinstance(string, str)330 self.string = string331 def is_string(self):332 return True333 def as_tuple(self):334 return self.string335 def space_upto_nl(self):336 return (getattr(self, 'size', len(self.string)), False)337def fits(f, space_left):338 s, nl = f.space_upto_nl()339 return s <= space_left340def to_format(arg, size=None):341 if isinstance(arg, FormatObject):342 return arg343 else:344 r = StringFormatObject(str(arg))345 if size != None:346 r.size = size347 return r348def compose(*args):349 if len(args) == 1 and (isinstance(args[0], list) or isinstance(args[0], tuple)):350 args = args[0]351 return ComposeFormatObject(args)352def indent(i, arg):353 return IndentFormatObject(i, arg)354def group(arg):355 return ChoiceFormatObject([arg.flat(), arg])356def line_break():357 return LineBreakFormatObject()358def _len(a):359 if isinstance(a, StringFormatObject):360 return getattr(a, 'size', len(a.string))361 else:362 return len(a)363def seq(args, sep=',', space=True):364 nl = line_break()365 if not space:366 nl.space = ''367 r = []368 r.append(args[0])369 num = len(args)370 for i in range(num - 1):371 r.append(to_format(sep))372 r.append(nl)373 r.append(args[i+1])374 return compose(r)375def seq1(header, args, lp='(', rp=')'):376 return group(compose(to_format(header),377 to_format(lp),378 indent(len(lp) + _len(header),379 seq(args)),380 to_format(rp)))381def seq2(header, args, i=4, lp='(', rp=')'):382 if len(args) == 0:383 return compose(to_format(header), to_format(lp), to_format(rp))384 else:385 return group(compose(indent(len(lp), compose(to_format(lp), to_format(header))),386 indent(i, compose(seq(args), to_format(rp)))))387def seq3(args, lp='(', rp=')'):388 if len(args) == 0:389 return compose(to_format(lp), to_format(rp))390 else:391 return group(indent(len(lp), compose(to_format(lp), seq(args), to_format(rp))))392class StopPPException(Exception):393 def __str__(self):394 return 'pp-interrupted'395class PP:396 def __init__(self):397 self.max_lines = 200398 self.max_width = 60399 self.bounded = False400 self.max_indent = 40401 402 def pp_string(self, f, indent):403 if not self.bounded or self.pos <= self.max_width:404 sz = _len(f)405 if self.bounded and self.pos + sz > self.max_width:406 self.out.write(u(_ellipses))407 else:408 self.pos = self.pos + sz409 self.ribbon_pos = self.ribbon_pos + sz410 self.out.write(u(f.string))411 def pp_compose(self, f, indent):412 for c in f.children:413 self.pp(c, indent)414 def pp_choice(self, f, indent):415 space_left = self.max_width - self.pos416 if space_left > 0 and fits(f.children[0], space_left):417 self.pp(f.children[0], indent)418 else:419 self.pp(f.children[1], indent)420 421 def pp_line_break(self, f, indent):422 self.pos = indent423 self.ribbon_pos = 0424 self.line = self.line + 1425 if self.line < self.max_lines: 426 self.out.write(u('\n'))427 for i in range(indent):428 self.out.write(u(' '))429 else:430 self.out.write(u('\n...'))431 raise StopPPException()432 def pp(self, f, indent):433 if isinstance(f, str):434 self.pp_string(f, indent)435 elif f.is_string():436 self.pp_string(f, indent)437 elif f.is_indent():438 self.pp(f.child, min(indent + f.indent, self.max_indent))439 elif f.is_compose():440 self.pp_compose(f, indent)441 elif f.is_choice():442 self.pp_choice(f, indent)443 elif f.is_linebreak():444 self.pp_line_break(f, indent)445 else:446 return447 def __call__(self, out, f):448 try:449 self.pos = 0450 self.ribbon_pos = 0451 self.line = 0452 self.out = out453 self.pp(f, 0)454 except StopPPException:455 return456 457class Formatter:458 def __init__(self):459 global _ellipses460 self.max_depth = 20461 self.max_args = 128462 self.rational_to_decimal = False463 self.precision = 10464 self.ellipses = to_format(_ellipses)465 self.max_visited = 10000466 self.fpa_pretty = True467 468 def pp_ellipses(self):469 return self.ellipses470 def pp_arrow(self):471 return ' ->'472 def pp_unknown(self):473 return '<unknown>'474 475 def pp_name(self, a):476 return to_format(_op_name(a))477 def is_infix(self, a):478 return _is_infix(a)479 480 def is_unary(self, a):481 return _is_unary(a)482 def get_precedence(self, a):483 return _get_precedence(a)484 def is_infix_compact(self, a):485 return _is_infix_compact(a)486 def is_infix_unary(self, a):487 return self.is_infix(a) or self.is_unary(a) 488 def add_paren(self, a):489 return compose(to_format('('), indent(1, a), to_format(')'))490 491 def pp_sort(self, s):492 if isinstance(s, z3.ArraySortRef):493 return seq1('Array', (self.pp_sort(s.domain()), self.pp_sort(s.range())))494 elif isinstance(s, z3.BitVecSortRef):495 return seq1('BitVec', (to_format(s.size()), ))496 elif isinstance(s, z3.FPSortRef):497 return seq1('FPSort', (to_format(s.ebits()), to_format(s.sbits())))498 elif isinstance(s, z3.ReSortRef):499 return seq1('ReSort', (self.pp_sort(s.basis()), ))500 elif isinstance(s, z3.SeqSortRef):501 if s.is_string():502 return to_format("String")503 return seq1('Seq', (self.pp_sort(s.basis()), ))504 else:505 return to_format(s.name())506 def pp_const(self, a):507 k = a.decl().kind()508 if k == Z3_OP_RE_EMPTY_SET:509 return self.pp_set("Empty", a)510 elif k == Z3_OP_SEQ_EMPTY:511 return self.pp_set("Empty", a)512 elif k == Z3_OP_RE_FULL_SET:513 return self.pp_set("Full", a)514 return self.pp_name(a)515 def pp_int(self, a):516 return to_format(a.as_string())517 518 def pp_rational(self, a):519 if not self.rational_to_decimal:520 return to_format(a.as_string())521 else:522 return to_format(a.as_decimal(self.precision))523 def pp_algebraic(self, a):524 return to_format(a.as_decimal(self.precision))525 def pp_string(self, a):526 return to_format("\"" + a.as_string() + "\"")527 def pp_bv(self, a):528 return to_format(a.as_string())529 def pp_fd(self, a):530 return to_format(a.as_string())531 def pp_fprm_value(self, a):532 _z3_assert(z3.is_fprm_value(a), 'expected FPRMNumRef')533 if self.fpa_pretty and (a.decl().kind() in _z3_op_to_fpa_pretty_str):534 return to_format(_z3_op_to_fpa_pretty_str.get(a.decl().kind()))535 else:536 return to_format(_z3_op_to_fpa_normal_str.get(a.decl().kind()))537 def pp_fp_value(self, a):538 _z3_assert(isinstance(a, z3.FPNumRef), 'type mismatch')539 if not self.fpa_pretty:540 r = []541 if (a.isNaN()):542 r.append(to_format(_z3_op_to_fpa_normal_str[Z3_OP_FPA_NAN]))543 r.append(to_format('('))544 r.append(to_format(a.sort()))545 r.append(to_format(')'))546 return compose(r)547 elif (a.isInf()):548 if (a.isNegative()):549 r.append(to_format(_z3_op_to_fpa_normal_str[Z3_OP_FPA_MINUS_INF]))550 else:551 r.append(to_format(_z3_op_to_fpa_normal_str[Z3_OP_FPA_PLUS_INF])) 552 r.append(to_format('('))553 r.append(to_format(a.sort()))554 r.append(to_format(')'))555 return compose(r)556 elif (a.isZero()):557 if (a.isNegative()):558 return to_format('-zero')559 else:560 return to_format('+zero')561 else:562 _z3_assert(z3.is_fp_value(a), 'expecting FP num ast')563 r = []564 sgn = c_int(0)565 sgnb = Z3_fpa_get_numeral_sign(a.ctx_ref(), a.ast, byref(sgn))566 exp = Z3_fpa_get_numeral_exponent_string(a.ctx_ref(), a.ast, False)567 sig = Z3_fpa_get_numeral_significand_string(a.ctx_ref(), a.ast)568 r.append(to_format('FPVal('))569 if sgnb and sgn.value != 0:570 r.append(to_format('-'))571 r.append(to_format(sig))572 r.append(to_format('*(2**'))573 r.append(to_format(exp))574 r.append(to_format(', '))575 r.append(to_format(a.sort()))576 r.append(to_format('))'))577 return compose(r)578 else:579 if (a.isNaN()):580 return to_format(_z3_op_to_fpa_pretty_str[Z3_OP_FPA_NAN])581 elif (a.isInf()):582 if (a.isNegative()):583 return to_format(_z3_op_to_fpa_pretty_str[Z3_OP_FPA_MINUS_INF])584 else:585 return to_format(_z3_op_to_fpa_pretty_str[Z3_OP_FPA_PLUS_INF])586 elif (a.isZero()):587 if (a.isNegative()):588 return to_format(_z3_op_to_fpa_pretty_str[Z3_OP_FPA_MINUS_ZERO])589 else:590 return to_format(_z3_op_to_fpa_pretty_str[Z3_OP_FPA_PLUS_ZERO])591 else:592 _z3_assert(z3.is_fp_value(a), 'expecting FP num ast')593 r = []594 sgn = (ctypes.c_int)(0)595 sgnb = Z3_fpa_get_numeral_sign(a.ctx_ref(), a.ast, byref(sgn))596 exp = Z3_fpa_get_numeral_exponent_string(a.ctx_ref(), a.ast, False)597 sig = Z3_fpa_get_numeral_significand_string(a.ctx_ref(), a.ast)598 if sgnb and sgn.value != 0:599 r.append(to_format('-'))600 r.append(to_format(sig))601 if (exp != '0'):602 r.append(to_format('*(2**'))603 r.append(to_format(exp))604 r.append(to_format(')')) 605 return compose(r)606 def pp_fp(self, a, d, xs):607 _z3_assert(isinstance(a, z3.FPRef), "type mismatch")608 k = a.decl().kind()609 op = '?'610 if (self.fpa_pretty and k in _z3_op_to_fpa_pretty_str):611 op = _z3_op_to_fpa_pretty_str[k]612 elif k in _z3_op_to_fpa_normal_str:613 op = _z3_op_to_fpa_normal_str[k]614 elif k in _z3_op_to_str:615 op = _z3_op_to_str[k] 616 n = a.num_args()617 if self.fpa_pretty:618 if self.is_infix(k) and n >= 3: 619 rm = a.arg(0)620 if z3.is_fprm_value(rm) and z3.get_default_rounding_mode(a.ctx).eq(rm):621 arg1 = to_format(self.pp_expr(a.arg(1), d+1, xs))622 arg2 = to_format(self.pp_expr(a.arg(2), d+1, xs))623 r = []624 r.append(arg1)625 r.append(to_format(' '))626 r.append(to_format(op))627 r.append(to_format(' '))628 r.append(arg2)629 return compose(r)630 elif k == Z3_OP_FPA_NEG:631 return compose([to_format('-') , to_format(self.pp_expr(a.arg(0), d+1, xs))])632 if k in _z3_op_to_fpa_normal_str:633 op = _z3_op_to_fpa_normal_str[k]634 635 r = [] 636 r.append(to_format(op))637 if not z3.is_const(a):638 r.append(to_format('(')) 639 first = True640 for c in a.children(): 641 if first:642 first = False643 else:644 r.append(to_format(', '))645 r.append(self.pp_expr(c, d+1, xs))646 r.append(to_format(')'))647 return compose(r)648 else:649 return to_format(a.as_string())650 def pp_prefix(self, a, d, xs):651 r = []652 sz = 0653 for child in a.children(): 654 r.append(self.pp_expr(child, d+1, xs))655 sz = sz + 1656 if sz > self.max_args:657 r.append(self.pp_ellipses())658 break659 return seq1(self.pp_name(a), r)660 def is_assoc(self, k):661 return _is_assoc(k)662 def is_left_assoc(self, k):663 return _is_left_assoc(k)664 def infix_args_core(self, a, d, xs, r):665 sz = len(r)666 k = a.decl().kind()667 p = self.get_precedence(k)668 first = True669 for child in a.children():670 child_pp = self.pp_expr(child, d+1, xs)671 child_k = None672 if z3.is_app(child):673 child_k = child.decl().kind()674 if k == child_k and (self.is_assoc(k) or (first and self.is_left_assoc(k))):675 self.infix_args_core(child, d, xs, r)676 sz = len(r)677 if sz > self.max_args:678 return679 elif self.is_infix_unary(child_k):680 child_p = self.get_precedence(child_k)681 if p > child_p or (_is_add(k) and _is_sub(child_k)) or (_is_sub(k) and first and _is_add(child_k)):682 r.append(child_pp)683 else: 684 r.append(self.add_paren(child_pp))685 sz = sz + 1686 elif z3.is_quantifier(child):687 r.append(self.add_paren(child_pp))688 else:689 r.append(child_pp)690 sz = sz + 1691 if sz > self.max_args:692 r.append(self.pp_ellipses())693 return694 first = False695 def infix_args(self, a, d, xs):696 r = []697 self.infix_args_core(a, d, xs, r)698 return r699 def pp_infix(self, a, d, xs):700 k = a.decl().kind()701 if self.is_infix_compact(k):702 op = self.pp_name(a)703 return group(seq(self.infix_args(a, d, xs), op, False))704 else:705 op = self.pp_name(a)706 sz = _len(op)707 op.string = ' ' + op.string708 op.size = sz + 1709 return group(seq(self.infix_args(a, d, xs), op))710 def pp_unary(self, a, d, xs):711 k = a.decl().kind()712 p = self.get_precedence(k)713 child = a.children()[0]714 child_k = None715 if z3.is_app(child):716 child_k = child.decl().kind()717 child_pp = self.pp_expr(child, d+1, xs) 718 if k != child_k and self.is_infix_unary(child_k):719 child_p = self.get_precedence(child_k)720 if p <= child_p:721 child_pp = self.add_paren(child_pp)722 if z3.is_quantifier(child):723 child_pp = self.add_paren(child_pp)724 name = self.pp_name(a)725 return compose(to_format(name), indent(_len(name), child_pp))726 def pp_power_arg(self, arg, d, xs):727 r = self.pp_expr(arg, d+1, xs)728 k = None729 if z3.is_app(arg):730 k = arg.decl().kind()731 if self.is_infix_unary(k) or (z3.is_rational_value(arg) and arg.denominator_as_long() != 1):732 return self.add_paren(r)733 else:734 return r735 def pp_power(self, a, d, xs):736 arg1_pp = self.pp_power_arg(a.arg(0), d+1, xs)737 arg2_pp = self.pp_power_arg(a.arg(1), d+1, xs)738 return group(seq((arg1_pp, arg2_pp), '**', False))739 def pp_neq(self):740 return to_format("!=")741 def pp_distinct(self, a, d, xs):742 if a.num_args() == 2:743 op = self.pp_neq()744 sz = _len(op)745 op.string = ' ' + op.string746 op.size = sz + 1747 return group(seq(self.infix_args(a, d, xs), op))748 else:749 return self.pp_prefix(a, d, xs)750 def pp_select(self, a, d, xs):751 if a.num_args() != 2:752 return self.pp_prefix(a, d, xs)753 else:754 arg1_pp = self.pp_expr(a.arg(0), d+1, xs)755 arg2_pp = self.pp_expr(a.arg(1), d+1, xs)756 return compose(arg1_pp, indent(2, compose(to_format('['), arg2_pp, to_format(']'))))757 def pp_unary_param(self, a, d, xs):758 p = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 0)759 arg = self.pp_expr(a.arg(0), d+1, xs)760 return seq1(self.pp_name(a), [ to_format(p), arg ])761 def pp_extract(self, a, d, xs):762 h = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 0)763 l = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 1)764 arg = self.pp_expr(a.arg(0), d+1, xs)765 return seq1(self.pp_name(a), [ to_format(h), to_format(l), arg ])766 def pp_loop(self, a, d, xs):767 l = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 0)768 arg = self.pp_expr(a.arg(0), d+1, xs)769 if Z3_get_decl_num_parameters(a.ctx_ref(), a.decl().ast) > 1:770 h = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 1)771 return seq1("Loop", [ arg, to_format(l), to_format(h) ])772 return seq1("Loop", [ arg, to_format(l) ])773 def pp_set(self, id, a):774 return seq1(id, [self.pp_sort(a.sort())])775 def pp_pattern(self, a, d, xs):776 if a.num_args() == 1:777 return self.pp_expr(a.arg(0), d, xs)778 else:779 return seq1('MultiPattern', [ self.pp_expr(arg, d+1, xs) for arg in a.children() ])780 def pp_is(self, a, d, xs):781 f = a.params()[0]782 return self.pp_fdecl(f, a, d, xs)783 def pp_map(self, a, d, xs):784 f = z3.get_map_func(a)785 return self.pp_fdecl(f, a, d, xs)786 def pp_fdecl(self, f, a, d, xs):787 r = []788 sz = 0789 r.append(to_format(f.name()))790 for child in a.children(): 791 r.append(self.pp_expr(child, d+1, xs))792 sz = sz + 1793 if sz > self.max_args:794 r.append(self.pp_ellipses())795 break796 return seq1(self.pp_name(a), r)797 def pp_K(self, a, d, xs):798 return seq1(self.pp_name(a), [ self.pp_sort(a.domain()), self.pp_expr(a.arg(0), d+1, xs) ])799 def pp_atmost(self, a, d, f, xs):800 k = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 0)801 return seq1(self.pp_name(a), [seq3([ self.pp_expr(ch, d+1, xs) for ch in a.children()]), to_format(k)])802 def pp_pbcmp(self, a, d, f, xs):803 chs = a.children()804 rchs = range(len(chs))805 k = Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, 0)806 ks = [Z3_get_decl_int_parameter(a.ctx_ref(), a.decl().ast, i+1) for i in rchs]807 ls = [ seq3([self.pp_expr(chs[i], d+1,xs), to_format(ks[i])]) for i in rchs]808 return seq1(self.pp_name(a), [seq3(ls), to_format(k)])809 def pp_app(self, a, d, xs):810 if z3.is_int_value(a):811 return self.pp_int(a)812 elif z3.is_rational_value(a):813 return self.pp_rational(a)814 elif z3.is_algebraic_value(a):815 return self.pp_algebraic(a) 816 elif z3.is_bv_value(a):817 return self.pp_bv(a)818 elif z3.is_finite_domain_value(a):819 return self.pp_fd(a)820 elif z3.is_fprm_value(a):821 return self.pp_fprm_value(a)822 elif z3.is_fp_value(a):823 return self.pp_fp_value(a)824 elif z3.is_fp(a):825 return self.pp_fp(a, d, xs)826 elif z3.is_string_value(a):827 return self.pp_string(a)828 elif z3.is_const(a):829 return self.pp_const(a)830 else:831 f = a.decl()832 k = f.kind()833 if k == Z3_OP_POWER:834 return self.pp_power(a, d, xs)835 elif k == Z3_OP_DISTINCT:836 return self.pp_distinct(a, d, xs)837 elif k == Z3_OP_SELECT:838 return self.pp_select(a, d, xs)839 elif k == Z3_OP_SIGN_EXT or k == Z3_OP_ZERO_EXT or k == Z3_OP_REPEAT:840 return self.pp_unary_param(a, d, xs)841 elif k == Z3_OP_EXTRACT:842 return self.pp_extract(a, d, xs)843 elif k == Z3_OP_RE_LOOP:844 return self.pp_loop(a, d, xs)845 elif k == Z3_OP_DT_IS:846 return self.pp_is(a, d, xs)847 elif k == Z3_OP_ARRAY_MAP:848 return self.pp_map(a, d, xs)849 elif k == Z3_OP_CONST_ARRAY:850 return self.pp_K(a, d, xs)851 elif k == Z3_OP_PB_AT_MOST:852 return self.pp_atmost(a, d, f, xs)853 elif k == Z3_OP_PB_LE:854 return self.pp_pbcmp(a, d, f, xs)855 elif k == Z3_OP_PB_GE:856 return self.pp_pbcmp(a, d, f, xs)857 elif k == Z3_OP_PB_EQ:858 return self.pp_pbcmp(a, d, f, xs)859 elif z3.is_pattern(a):860 return self.pp_pattern(a, d, xs)861 elif self.is_infix(k):862 return self.pp_infix(a, d, xs)863 elif self.is_unary(k):864 return self.pp_unary(a, d, xs)865 else:866 return self.pp_prefix(a, d, xs)867 def pp_var(self, a, d, xs):868 idx = z3.get_var_index(a)869 sz = len(xs)870 if idx >= sz:871 return seq1('Var', (to_format(idx),))872 else:873 return to_format(xs[sz - idx - 1])874 875 def pp_quantifier(self, a, d, xs):876 ys = [ to_format(a.var_name(i)) for i in range(a.num_vars()) ]877 new_xs = xs + ys878 body_pp = self.pp_expr(a.body(), d+1, new_xs)879 if len(ys) == 1:880 ys_pp = ys[0]881 else:882 ys_pp = seq3(ys, '[', ']')883 if a.is_forall():884 header = 'ForAll'885 elif a.is_exists():886 header = 'Exists'887 else:888 header = 'Lambda'889 return seq1(header, (ys_pp, body_pp))890 def pp_expr(self, a, d, xs):891 self.visited = self.visited + 1892 if d > self.max_depth or self.visited > self.max_visited:893 return self.pp_ellipses()894 if z3.is_app(a):895 return self.pp_app(a, d, xs)896 elif z3.is_quantifier(a):897 return self.pp_quantifier(a, d, xs)898 elif z3.is_var(a):899 return self.pp_var(a, d, xs)900 else:901 return to_format(self.pp_unknown())902 def pp_decl(self, f):903 k = f.kind()904 if k == Z3_OP_DT_IS or k == Z3_OP_ARRAY_MAP:905 g = f.params()[0]906 r = [ to_format(g.name()) ]907 return seq1(self.pp_name(f), r)908 return self.pp_name(f) 909 def pp_seq_core(self, f, a, d, xs):910 self.visited = self.visited + 1911 if d > self.max_depth or self.visited > self.max_visited:912 return self.pp_ellipses()913 r = []914 sz = 0915 for elem in a:916 r.append(f(elem, d+1, xs))917 sz = sz + 1918 if sz > self.max_args:919 r.append(self.pp_ellipses())920 break921 return seq3(r, '[', ']')922 923 def pp_seq(self, a, d, xs):924 return self.pp_seq_core(self.pp_expr, a, d, xs)925 def pp_seq_seq(self, a, d, xs):926 return self.pp_seq_core(self.pp_seq, a, d, xs)927 def pp_model(self, m):928 r = []929 sz = 0930 for d in m:931 i = m[d]932 if isinstance(i, z3.FuncInterp):933 i_pp = self.pp_func_interp(i)934 else:935 i_pp = self.pp_expr(i, 0, [])936 name = self.pp_name(d)937 r.append(compose(name, to_format(' = '), indent(_len(name) + 3, i_pp)))938 sz = sz + 1939 if sz > self.max_args:940 r.append(self.pp_ellipses())941 break942 return seq3(r, '[', ']')943 def pp_func_entry(self, e):944 num = e.num_args()945 if num > 1:946 args = []947 for i in range(num):948 args.append(self.pp_expr(e.arg_value(i), 0, []))949 args_pp = group(seq3(args))950 else:951 args_pp = self.pp_expr(e.arg_value(0), 0, [])952 value_pp = self.pp_expr(e.value(), 0, []) 953 return group(seq((args_pp, value_pp), self.pp_arrow()))954 def pp_func_interp(self, f):955 r = []956 sz = 0957 num = f.num_entries()958 for i in range(num):959 r.append(self.pp_func_entry(f.entry(i)))960 sz = sz + 1961 if sz > self.max_args:962 r.append(self.pp_ellipses())963 break964 if sz <= self.max_args:965 else_val = f.else_value()966 if else_val == None:967 else_pp = to_format('#unspecified')968 else:969 else_pp = self.pp_expr(else_val, 0, [])970 r.append(group(seq((to_format('else'), else_pp), self.pp_arrow())))971 return seq3(r, '[', ']')972 def pp_list(self, a):973 r = []974 sz = 0975 for elem in a:976 if _support_pp(elem):977 r.append(self.main(elem))978 else:979 r.append(to_format(str(elem)))980 sz = sz + 1981 if sz > self.max_args:982 r.append(self.pp_ellipses())983 break984 if isinstance(a, tuple):985 return seq3(r)986 else:987 return seq3(r, '[', ']')988 def main(self, a):989 if z3.is_expr(a):990 return self.pp_expr(a, 0, [])991 elif z3.is_sort(a):992 return self.pp_sort(a)993 elif z3.is_func_decl(a):994 return self.pp_decl(a)995 elif isinstance(a, z3.Goal) or isinstance(a, z3.AstVector):996 return self.pp_seq(a, 0, [])997 elif isinstance(a, z3.Solver):998 return self.pp_seq(a.assertions(), 0, [])999 elif isinstance(a, z3.Fixedpoint):1000 return a.sexpr()1001 elif isinstance(a, z3.Optimize):1002 return a.sexpr()1003 elif isinstance(a, z3.ApplyResult):1004 return self.pp_seq_seq(a, 0, [])1005 elif isinstance(a, z3.ModelRef):1006 return self.pp_model(a)1007 elif isinstance(a, z3.FuncInterp):1008 return self.pp_func_interp(a)1009 elif isinstance(a, list) or isinstance(a, tuple):1010 return self.pp_list(a)1011 else:1012 return to_format(self.pp_unknown())1013 def __call__(self, a):1014 self.visited = 01015 return self.main(a)1016class HTMLFormatter(Formatter):1017 def __init__(self):1018 Formatter.__init__(self)1019 global _html_ellipses1020 self.ellipses = to_format(_html_ellipses)1021 def pp_arrow(self):1022 return to_format(' →', 1)1023 def pp_unknown(self):1024 return '<b>unknown</b>'1025 1026 def pp_name(self, a):1027 r = _html_op_name(a)1028 if r[0] == '&' or r[0] == '/' or r[0] == '%':1029 return to_format(r, 1)1030 else:1031 pos = r.find('__')1032 if pos == -1 or pos == 0:1033 return to_format(r)1034 else:1035 sz = len(r)1036 if pos + 2 == sz:1037 return to_format(r)1038 else:1039 return to_format('%s<sub>%s</sub>' % (r[0:pos], r[pos+2:sz]), sz - 2)1040 def is_assoc(self, k):1041 return _is_html_assoc(k)1042 def is_left_assoc(self, k):1043 return _is_html_left_assoc(k)1044 def is_infix(self, a):1045 return _is_html_infix(a)1046 1047 def is_unary(self, a):1048 return _is_html_unary(a)1049 def get_precedence(self, a):1050 return _get_html_precedence(a)1051 def pp_neq(self):1052 return to_format("≠")1053 def pp_power(self, a, d, xs):1054 arg1_pp = self.pp_power_arg(a.arg(0), d+1, xs)1055 arg2_pp = self.pp_expr(a.arg(1), d+1, xs)1056 return compose(arg1_pp, to_format('<sup>', 1), arg2_pp, to_format('</sup>', 1)) 1057 def pp_var(self, a, d, xs):1058 idx = z3.get_var_index(a)1059 sz = len(xs)1060 if idx >= sz:1061 # 957 is the greek letter nu1062 return to_format('ν<sub>%s</sub>' % idx, 1)1063 else:1064 return to_format(xs[sz - idx - 1])1065 def pp_quantifier(self, a, d, xs):1066 ys = [ to_format(a.var_name(i)) for i in range(a.num_vars()) ]1067 new_xs = xs + ys1068 body_pp = self.pp_expr(a.body(), d+1, new_xs)1069 ys_pp = group(seq(ys))1070 if a.is_forall():1071 header = '∀'1072 else:1073 header = '∃'1074 return group(compose(to_format(header, 1), 1075 indent(1, compose(ys_pp, to_format(' :'), line_break(), body_pp))))1076_PP = PP()1077_Formatter = Formatter()1078def set_pp_option(k, v):1079 if k == 'html_mode':1080 if v:1081 set_html_mode(True)1082 else:1083 set_html_mode(False)1084 return True1085 if k == 'fpa_pretty':1086 if v:1087 set_fpa_pretty(True)1088 else:1089 set_fpa_pretty(False)...
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!!