Best Python code snippet using slash
alert.js
Source:alert.js  
1  var alert;2  document.writeln("<style type=\"text\/css\">");3  document.writeln("");4  document.writeln(".window {");5  document.writeln("	width:290px;");6  document.writeln("	position:absolute;");7  document.writeln("	display:none;");8  document.writeln("	bottom:30px;");9  document.writeln("	left:50%;");10  document.writeln("	 z-index:9999;");11  document.writeln("	margin:-50px auto 0 -145px;");12  document.writeln("	padding:2px;");13  document.writeln("	border-radius:0.6em;");14  document.writeln("	-webkit-border-radius:0.6em;");15  document.writeln("	-moz-border-radius:0.6em;");16  document.writeln("	background-color: #ffffff;");17  document.writeln("	-webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);");18  document.writeln("	-moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);");19  document.writeln("	-o-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);");20  document.writeln("	box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);");21  document.writeln("	font:14px\/1.5 Microsoft YaHei,Helvitica,Verdana,Arial,san-serif;");22  document.writeln("}");23  document.writeln(".window .title {");24  document.writeln("	");25  document.writeln("	background-color: #A3A2A1;");26  document.writeln("	line-height: 26px;");27  document.writeln("    padding: 5px 5px 5px 10px;");28  document.writeln("	color:#ffffff;");29  document.writeln("	font-size:16px;");30  document.writeln("	border-radius:0.5em 0.5em 0 0;");31  document.writeln("	-webkit-border-radius:0.5em 0.5em 0 0;");32  document.writeln("	-moz-border-radius:0.5em 0.5em 0 0;");33  document.writeln("	background-image: -webkit-gradient(linear, left top, left bottom, from( #585858 ), to( #565656 )); \/* Saf4+, Chrome *\/");34  document.writeln("	background-image: -webkit-linear-gradient(#585858, #565656); \/* Chrome 10+, Saf5.1+ *\/");35  document.writeln("	background-image:    -moz-linear-gradient(#585858, #565656); \/* FF3.6 *\/");36  document.writeln("	background-image:     -ms-linear-gradient(#585858, #565656); \/* IE10 *\/");37  document.writeln("	background-image:      -o-linear-gradient(#585858, #565656); \/* Opera 11.10+ *\/");38  document.writeln("	background-image:         linear-gradient(#585858, #565656);");39  document.writeln("	");40  document.writeln("}");41  document.writeln(".window .content {");42  document.writeln("	\/*min-height:100px;*\/");43  document.writeln("	overflow:auto;");44  document.writeln("	padding:10px;");45  document.writeln("	background: linear-gradient(#FBFBFB, #EEEEEE) repeat scroll 0 0 #FFF9DF;");46  document.writeln("    color: #222222;");47  document.writeln("    text-shadow: 0 1px 0 #FFFFFF;");48  document.writeln("	border-radius: 0 0 0.6em 0.6em;");49  document.writeln("	-webkit-border-radius: 0 0 0.6em 0.6em;");50  document.writeln("	-moz-border-radius: 0 0 0.6em 0.6em;");51  document.writeln("}");52  document.writeln(".window #txt {");53  document.writeln("	min-height:30px;font-size:16px; line-height:22px;");54  document.writeln("}");55  document.writeln(".window .txtbtn {");56  document.writeln("	");57  document.writeln("	background: #f1f1f1;");58  document.writeln("	background-image: -webkit-gradient(linear, left top, left bottom, from( #DCDCDC ), to( #f1f1f1 )); \/* Saf4+, Chrome *\/");59  document.writeln("	background-image: -webkit-linear-gradient( #ffffff , #DCDCDC ); \/* Chrome 10+, Saf5.1+ *\/");60  document.writeln("	background-image:    -moz-linear-gradient( #ffffff , #DCDCDC ); \/* FF3.6 *\/");61  document.writeln("	background-image:     -ms-linear-gradient( #ffffff , #DCDCDC ); \/* IE10 *\/");62  document.writeln("	background-image:      -o-linear-gradient( #ffffff , #DCDCDC ); \/* Opera 11.10+ *\/");63  document.writeln("	background-image:         linear-gradient( #ffffff , #DCDCDC );");64  document.writeln("	border: 1px solid #CCCCCC;");65  document.writeln("	border-bottom: 1px solid #B4B4B4;");66  document.writeln("	color: #555555;");67  document.writeln("	font-weight: bold;");68  document.writeln("	text-shadow: 0 1px 0 #FFFFFF;");69  document.writeln("	border-radius: 0.6em 0.6em 0.6em 0.6em;");70  document.writeln("	display: block;");71  document.writeln("	width: 100%;");72  document.writeln("	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);");73  document.writeln("	text-overflow: ellipsis;");74  document.writeln("	white-space: nowrap;");75  document.writeln("	cursor: pointer;");76  document.writeln("	text-align: windowcenter;");77  document.writeln("	font-weight: bold;");78  document.writeln("	font-size: 18px;");79  document.writeln("	padding:6px;");80  document.writeln("	margin:10px 0 0 0;");81  document.writeln("}");82  document.writeln(".window .txtbtn:visited {");83  document.writeln("	background-image: -webkit-gradient(linear, left top, left bottom, from( #ffffff ), to( #cccccc )); \/* Saf4+, Chrome *\/");84  document.writeln("	background-image: -webkit-linear-gradient( #ffffff , #cccccc ); \/* Chrome 10+, Saf5.1+ *\/");85  document.writeln("	background-image:    -moz-linear-gradient( #ffffff , #cccccc ); \/* FF3.6 *\/");86  document.writeln("	background-image:     -ms-linear-gradient( #ffffff , #cccccc ); \/* IE10 *\/");87  document.writeln("	background-image:      -o-linear-gradient( #ffffff , #cccccc ); \/* Opera 11.10+ *\/");88  document.writeln("	background-image:         linear-gradient( #ffffff , #cccccc );");89  document.writeln("}");90  document.writeln(".window .txtbtn:hover {");91  document.writeln("	background-image: -webkit-gradient(linear, left top, left bottom, from( #ffffff ), to( #cccccc )); \/* Saf4+, Chrome *\/");92  document.writeln("	background-image: -webkit-linear-gradient( #ffffff , #cccccc ); \/* Chrome 10+, Saf5.1+ *\/");93  document.writeln("	background-image:    -moz-linear-gradient( #ffffff , #cccccc ); \/* FF3.6 *\/");94  document.writeln("	background-image:     -ms-linear-gradient( #ffffff , #cccccc ); \/* IE10 *\/");95  document.writeln("	background-image:      -o-linear-gradient( #ffffff , #cccccc ); \/* Opera 11.10+ *\/");96  document.writeln("	background-image:         linear-gradient( #ffffff , #cccccc );");97  document.writeln("}");98  document.writeln(".window .txtbtn:active {");99  document.writeln("	background-image: -webkit-gradient(linear, left top, left bottom, from( #cccccc ), to( #ffffff )); \/* Saf4+, Chrome *\/");100  document.writeln("	background-image: -webkit-linear-gradient( #cccccc , #ffffff ); \/* Chrome 10+, Saf5.1+ *\/");101  document.writeln("	background-image:    -moz-linear-gradient( #cccccc , #ffffff ); \/* FF3.6 *\/");102  document.writeln("	background-image:     -ms-linear-gradient( #cccccc , #ffffff ); \/* IE10 *\/");103  document.writeln("	background-image:      -o-linear-gradient( #cccccc , #ffffff ); \/* Opera 11.10+ *\/");104  document.writeln("	background-image:         linear-gradient( #cccccc , #ffffff );");105  document.writeln("	border: 1px solid #C9C9C9;");106  document.writeln("	border-top: 1px solid #B4B4B4;");107  document.writeln("	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3) inset;");108  document.writeln("}");109  document.writeln("");110  document.writeln(".window .title .close {");111  document.writeln("	float:right;");112  document.writeln("	background-image: url(\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACTSURBVEhL7dNtCoAgDAZgb60nsGN1tPLVCVNHmg76kQ8E1mwv+GG27cestQ4PvTZ69SFocBGpWa8+zHt\/Up+IN+MhgLlUmnIE1CpBQB2COZibfpnXhHFaIZkYph0SOeeK\/QJ8o7KOek84fkCWSBtfL+Ny2MPpCkPFMH6PWEhWhKncIyEk69VfiUuVhqJefds+YcwNbEwxGqGIFWYAAAAASUVORK5CYII=\");");113  document.writeln("	width:26px;");114  document.writeln("	height:26px;");115  document.writeln("	display:block;	");116  document.writeln("}");117  document.writeln("<\/style>");118  document.writeln("<div class=\"window\" id=\"windowcenter\">");119  document.writeln("	<div id=\"title\" class=\"title\">消息提醒<span class=\"close\" id=\"alertclose\"><\/span><\/div>");120  document.writeln("	<div class=\"content\">");121  document.writeln("	 <div id=\"txt\"><\/div>");122  document.writeln("	   <input type=\"hidden\"  ID=\"url\" />");123  document.writeln("	 <input type=\"button\" value=\"确定\" id=\"windowclosebutton\" name=\"确定\" class=\"txtbtn\">	");124  document.writeln("	<\/div>");125  document.writeln("<\/div>");126  $(function () {127      $("#windowclosebutton").click(function () {128          if ($("#url").val()== "")129              $("#windowcenter").slideUp(500);130          else131              location.href = $("#url").val();132      });133      $("#alertclose").click(function () {134          $("#windowcenter").slideUp(500);135      });136  });137  alert = function (title) {138      $("#windowcenter").slideToggle("slow");139      $("#txt").html(title);...root_right01.js
Source:root_right01.js  
1document.writeln("<table width=96%  border=0 cellspacing=0 cellpadding=0>");2document.writeln("<tr>");		  3document.writeln("<td colspan=2>");4document.writeln("<table width=100%  border=0 cellspacing=0 cellpadding=0>");5document.writeln("<tr>");6document.writeln("<td width=25 align=center><img src=../hudonghd/images/dot_01.gif width=20 height=21 border=0></td>");  7document.writeln("<td class=f14>ç¸å
³ç½å大å
¨</td>"); 8document.writeln("</tr>"); 9document.writeln("<tr>");10document.writeln("<td height=3 colspan=2 bgcolor=#4BCB66></td>");11document.writeln("</tr>");12document.writeln("</table></td>");13document.writeln("</tr>");14document.writeln("<tr>"); 15document.writeln("<td width=300 align=center bgcolor=#F7FDF6><table width=150  border=0 align=center cellpadding=1 cellspacing=0>");16document.writeln("<tr>");17document.writeln("<td width=7% ><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");18document.writeln("<td width=93% class=f9><a href=01tupian.htm class=mm>å¾çç½å大å
¨</a></td>");                         19document.writeln("</tr>");20document.writeln("<tr>"); 21document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 22document.writeln("</tr>");23document.writeln("<tr>");24document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");25document.writeln("<td class=f9><a href=03luntan.htm class=mm>论åç½å大å
¨</a></td>");26document.writeln("</tr>");27document.writeln("<tr>"); 28document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 29document.writeln("</tr>");30document.writeln("<tr>");31document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");32document.writeln("<td class=f9><a href=06xiaoshuo.htm class=mm>å°è¯´ç½å大å
¨</a></td>");33document.writeln("</tr>");34document.writeln("<tr>"); 35document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 36document.writeln("</tr>");37document.writeln("<tr>");38document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");39document.writeln("<td class=f9><a href=07mingxing.htm class=mm>ææç½å大å
¨</a></td>");40document.writeln("</tr>");41document.writeln("<tr>"); 42document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 43document.writeln("</tr>");44document.writeln("<tr>");45document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");46document.writeln("<td class=f9><a href=04ertong.htm class=mm>å¿ç«¥ç½å大å
¨</a></td>");47document.writeln("</tr>");48document.writeln("<tr>"); 49document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 50document.writeln("</tr>");51document.writeln("<tr>");52document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");53document.writeln("<td class=f9><a href=08wap.htm class=mm>WAPç½å大å
¨</a></td>");54document.writeln("</tr>");55document.writeln("<tr>"); 56document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 57document.writeln("</tr>");58document.writeln("<tr>");59document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");60document.writeln("<td class=f9><a href=09guowu.htm class=mm>è´ç©ç½å大å
¨</a></td>");61document.writeln("</tr>");62document.writeln("<tr>"); 63document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 64document.writeln("</tr>");65document.writeln("<tr>");66document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");67document.writeln("<td class=f9><a href=11kejian.htm class=mm>课件ç½å大å
¨</a></td>");68document.writeln("</tr>");69document.writeln("<tr>"); 70document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 71document.writeln("</tr>");72document.writeln("<tr>");73document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");74document.writeln("<td class=f9><a href=12english.htm class=mm>è±è¯ç½å大å
¨</a></td>");75document.writeln("</tr>");76document.writeln("<tr>"); 77document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 78document.writeln("</tr>");79document.writeln("<tr>");80document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");81document.writeln("<td class=f9><a href=13shipin.htm class=mm>è§é¢ç½å大å
¨</a></td>");82document.writeln("</tr>");83document.writeln("<tr>"); 84document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 85document.writeln("</tr>");86document.writeln("<tr>");87document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");88document.writeln("<td class=f9><a href=16dongman.htm class=mm>卿¼«ç½å大å
¨</a></td>");89document.writeln("</tr>");90document.writeln("<tr>"); 91document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 92document.writeln("</tr>");93document.writeln("<tr>");94document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");95document.writeln("<td class=f9><a href=15mradio.htm class=mm>é³ä¹çµå°ç½å大å
¨</a></td>");96document.writeln("</tr>");97document.writeln("<tr>"); 98document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 99document.writeln("</tr>");100document.writeln("<tr>");101document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");102document.writeln("<td class=f9><a href=17hanguo.htm class=mm>é©å½ç½å大å
¨</a></td>");103document.writeln("</tr>");104document.writeln("<tr>"); 105document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 106document.writeln("</tr>");107document.writeln("<tr>");108document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");109document.writeln("<td class=f9><a href=19netradio.htm class=mm>ç½ç»çµå°ç½å大å
¨</a></td>");110document.writeln("</tr>");111document.writeln("<tr>"); 112document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 113document.writeln("</tr>");114document.writeln("<tr>");115document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");116document.writeln("<td class=f9><a href=05redian.htm class=mm>çç¹æç´¢å表</a></td>");117document.writeln("</tr>");118document.writeln("<tr>"); 119document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 120document.writeln("</tr>");121document.writeln("<tr>");122document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");123document.writeln("<td class=f9><a href=02tieba.htm class=mm>ç¾åº¦çé¨è´´å§å表</a></td>");124document.writeln("</tr>");125document.writeln("<tr>"); 126document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 127document.writeln("</tr>");128document.writeln("<tr>");129document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");130document.writeln("<td class=f9><a href=18shipinjc.htm class=mm>è§é¢æç¨å¤§å
¨</a></td>");131document.writeln("</tr>");132document.writeln("<tr>"); 133document.writeln("<td height=1 colspan=2 background=../hudonghd/images/dot_05.gif></td>"); 134document.writeln("</tr>");135document.writeln("<tr>");136document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");137document.writeln("<td class=f9><a href=23citiao.htm class=mm>ç¾ç§ç²¾å½©è¯æ¡å¤§å
¨</a></td>");138document.writeln("</tr>");139document.writeln("<tr>");140document.writeln("<td><img src=../hudonghd/images/dot_02.gif width=8 height=20></td>");141document.writeln("<td class=f9><a href=../caipu.htm class=mm>家常è大å
¨</a></td>");142document.writeln("</tr>");143document.writeln("</table></td>");...codeWriter.py
Source:codeWriter.py  
...20        return self.asm21    def set_file_name(self, filename):22        self.current_file = filename23    def write_init(self):24        self.writeln('// Bootstrap code')25        self.writeln('@256')26        self.writeln('D=A')27        self.writeln('@SP')28        self.writeln('M=D')29        self.write_call('Sys.init', 0)30    def write(self, command: Command):31        cmd_type = command.get_command_type()32        cmd = command.get_command()33        arg1 = command.get_arg1()34        arg2 = command.get_arg2()35        self.writeln('// {} {} {}'.format(cmd, arg1, arg2))36        if cmd_type == 'C_ARITHMETIC':37            self.write_arithmetic(cmd)38        elif cmd_type in ['C_PUSH', 'C_POP']:39            self.write_push_pop(cmd, arg1, arg2)40        elif cmd_type == 'C_LABEL':41            self.write_label(arg1)42        elif cmd_type == 'C_GOTO':43            self.write_goto(arg1)44        elif cmd_type == 'C_IF':45            self.write_if(arg1)46        elif cmd_type == 'C_FUNCTION':47            self.write_function(arg1, arg2)48        elif cmd_type == 'C_CALL':49            self.write_call(arg1, arg2)50        elif cmd_type == 'C_RETURN':51            self.write_return()52        else:53            raise Exception("Unknown command type {}".format(cmd))54    def write_label(self, label: str):55        self.writeln('({}${})'.format(self.current_file, label))56    def write_goto(self, label: str):57        self.writeln('@{}${}'.format(self.current_file, label))58        self.writeln('0;JMP')59    def write_if(self, label: str):60        self.stack_to_d()61        self.writeln('@{}${}'.format(self.current_file, label))62        self.writeln('D;JNE')63    def write_function(self, name: str, num_vars: int):64        self.writeln('({})'.format(name))65        for _ in range(int(num_vars)):66            self.writeln('D=0')67            self.d_to_stack()68    def write_call(self, f_name: str, num_args: int):69        ret_addr = f_name + 'RET' + str(self.call_count)70        self.call_count += 171        # push retAddr72        self.writeln('@' + ret_addr)73        self.writeln('D=A')74        self.d_to_stack()75        # push 'LCL', 'ARG', 'THIS', 'THAT'76        for segment in ['LCL', 'ARG', 'THIS', 'THAT']:77            self.writeln('@' + segment)78            self.writeln('D=M')79            self.d_to_stack()80        # Reposition ARG = SP - 5 -nArgs81        self.writeln('@SP')82        self.writeln('D=M')83        self.writeln('@' + str(int(num_args) + 5))84        self.writeln('D=D-A')85        self.writeln('@ARG')86        self.writeln('M=D')87        # Reposition LCL = SP88        self.writeln('@SP')89        self.writeln('D=M')90        self.writeln('@LCL')91        self.writeln('M=D')92        # goto function name93        self.writeln('@' + f_name)94        self.writeln('0;JMP')95        # retAddr96        self.writeln('({})'.format(ret_addr))97    def write_return(self):98        end_frame = 'R13'99        ret_addr = 'R14'100        # endFrame = LCL101        self.writeln('@LCL')102        self.writeln('D=M')103        self.writeln('@' + end_frame)104        self.writeln('M=D')105        # retAddr = endFrame - 5106        self.writeln('@' + end_frame)107        self.writeln('D=M')108        self.writeln('@5')109        self.writeln('D=D-A')110        self.writeln('A=D')111        self.writeln('D=M')112        self.writeln('@' + ret_addr)113        self.writeln('M=D')114        # *ARG = pop()115        self.stack_to_d()116        self.writeln('@ARG')117        self.writeln('A=M')118        self.writeln('M=D')119        # SP = ARG + 1120        self.writeln('@ARG')121        self.writeln('D=M')122        self.writeln('@SP')123        self.writeln('M=D+1')124        # THAT, THIS, ARG, LCL = endFrame -1, -2, -3, -4125        i = 1126        for segment in ['THAT', 'THIS', 'ARG', 'LCL']:127            self.writeln('@' + end_frame)128            self.writeln('D=M')129            self.writeln('@' + str(i))130            self.writeln('D=D-A')131            self.writeln('A=D')132            self.writeln('D=M')133            self.writeln('@' + segment)134            self.writeln('M=D')135            i += 1136        # goto retAddr137        self.writeln('@' + ret_addr)138        self.writeln('A=M')139        self.writeln('0;JMP')140    def write_arithmetic(self, command: str):141        if command not in ['neg', 'not']:  # no need to pop from stack for unary ops142            self.stack_to_d()143        self.decrement_sp()144        self.writeln('@SP')145        self.writeln('A=M')146        if command == 'add':147            self.writeln('M=M+D')148        elif command == 'sub':149            self.writeln('M=M-D')150        elif command == 'and':151            self.writeln('M=M&D')152        elif command == 'or':153            self.writeln('M=M|D')154        elif command == 'neg':155            self.writeln('M=-M')156        elif command == 'not':157            self.writeln('M=!M')158        elif command in ['eq', 'gt', 'lt']:159            self.writeln('D=M-D')160            self.writeln('@COND{}'.format(self.cond_count))161            if command == 'eq':162                self.writeln('D;JEQ')  # M = D163            if command == 'gt':164                self.writeln('D;JGT')  # M > D165            if command == 'lt':166                self.writeln('D;JLT')  # M < D167            self.writeln('@SP')168            self.writeln('A=M')169            self.writeln('M=0')  # false170            self.writeln('@ENDCOND{}'.format(self.cond_count))171            self.writeln('0;JMP')172            self.writeln('(COND{})'.format(self.cond_count))173            self.writeln('@SP')174            self.writeln('A=M')175            self.writeln('M=-1')  # true176            self.writeln('(ENDCOND{})'.format(self.cond_count))177            self.cond_count += 1178        else:179            raise Exception('Unconown command {}'.format(command))180        self.increment_sp()181    def write_push_pop(self, command: str, segment: str, index: int):182        self.write_address(segment, index)183        if command == 'push':184            if segment == 'constant':185                self.writeln('D=A')186            else:187                self.writeln('D=M')188            self.d_to_stack()189        elif command == 'pop':190            self.writeln('D=A')191            self.writeln('@R13')192            self.writeln('M=D')193            self.stack_to_d()194            self.writeln('@R13')195            self.writeln('A=M')196            self.writeln('M=D')197        else:198            raise Exception('Unknown command')199    def write_address(self, segment, index):200        if segment == 'constant':201            self.writeln('@' + str(index))202        elif segment == 'static':203            self.writeln('@' + self.current_file + '.' + str(index))204        elif segment in ['local', 'argument', 'this', 'that']:205            self.writeln('@' + CodeWriter.ADDRESSES[segment])206            self.writeln('D=M')207            self.writeln('@' + str(index))208            self.writeln('A=D+A')209        elif segment in ['pointer', 'temp']:210            self.writeln('@R' + str(CodeWriter.ADDRESSES[segment] + int(index)))211        else:212            raise Exception('Wrong address')213    def writeln(self, cmd):214        self.asm.append(cmd)215    def d_to_stack(self):216        self.writeln('@SP')217        self.writeln('A=M')218        self.writeln('M=D')219        self.writeln('@SP')220        self.writeln('M=M+1')221    def stack_to_d(self):222        self.writeln('@SP')223        self.writeln('M=M-1')224        self.writeln('A=M')225        self.writeln('D=M')226    def decrement_sp(self):227        self.writeln('@SP')228        self.writeln('M=M-1')229    def increment_sp(self):230        self.writeln('@SP')...generate-pyr-policy-template.py
Source:generate-pyr-policy-template.py  
...17'''18import os19import sys20# TODO: use single list of defaults, and generate dynamically21def writeln(f, to_write):22    f.write(to_write+'\n')23# adapted from: github.com/kantai/passe-framework-prototype/blob/master/django/analysis/persisted.py24def create_apparmor_prof(prof_path, app):25    z = open(prof_path, 'w')26    writeln(z, app+" {")27    writeln(z, "# these need to be included by default")28    writeln(z, "/etc/ld.so.cache r,")29    writeln(z, "/lib/x86_64-linux-gnu/libc-2.23.so rm,")30    writeln(z, "/lib/x86_64-linux-gnu/libpyronia.so rm,")31    writeln(z, "/lib/x86_64-linux-gnu/libsmv.so rm,")32    writeln(z, "/lib/x86_64-linux-gnu/libpthread-2.23.so rm,")33    writeln(z, "/lib/x86_64-linux-gnu/libnl-genl-3.so.200.22.0 rm,")34    writeln(z, "/lib/x86_64-linux-gnu/libnl-3.so.200.22.0 rm,")35    writeln(z, "/lib/x86_64-linux-gnu/libm-2.23.so rm,")36    writeln(z, "/lib/x86_64-linux-gnu/libgcc_s.so.1 rm,")37    writeln(z, "/proc/*/net/psched r,")38    writeln(z, "/dev/pts/* r,")39    writeln(z, prof_path+"-lib.prof r,")40    writeln(z, "")41    writeln(z, "# TODO: replace these with YOUR resource access rules")42    writeln(z, "<file1> <perms>,")43    writeln(z, "<file2> <perms>,")44    writeln(z, "network inet,")45    writeln(z, "}")46    z.close()47def create_lib_prof(prof_path):48    z = open(prof_path, 'w')49    writeln(z, "d /etc/ld.so.cache,")50    writeln(z, "d /lib/x86_64-linux-gnu/libc-2.23.so,")51    writeln(z, "d /lib/x86_64-linux-gnu/libpyronia.so,")52    writeln(z, "d /lib/x86_64-linux-gnu/libsmv.so,")53    writeln(z, "d /lib/x86_64-linux-gnu/libpthread-2.23.so,")54    writeln(z, "d /lib/x86_64-linux-gnu/libnl-genl-3.so.200.22.0,")55    writeln(z, "d /lib/x86_64-linux-gnu/libnl-3.so.200.22.0,")56    writeln(z, "d /lib/x86_64-linux-gnu/libm-2.23.so,")57    writeln(z, "d /lib/x86_64-linux-gnu/libgcc_s.so.1,")58    writeln(z, "d /proc/*/net/psched,")59    writeln(z, "d /dev/pts/*,")60    writeln(z, "")61    writeln(z, "<lib1> <file1>,")62    writeln(z, "<lib2> <file1>,")63    writeln(z, "<lib2> <file2,")64    writeln(z, "<lib1> network <IP address>,")65    writeln(z, "<lib3> network <IP address>,")66    z.close()67if __name__ == '__main__':68    # expect the absolute path to the application to be confined,69    # and the destination for the generated profile templates.70    if len(sys.argv) != 3:71        print('Usage: python generate-pyr-policy-template.py <abs app path> <dir>')72        sys.exit(0)73    # parse the command-line args74    app_path = os.path.normpath(sys.argv[1])75    prof_dest_dir = os.path.normpath(sys.argv[2])76    # generate the app-wide profile name77    # names requires the absolute path of the application to be "."-separated78    app_prof_file = ".".join(app_path.lstrip(os.path.sep).split(os.path.sep))79    create_apparmor_prof(prof_dest_dir+"/"+app_prof_file, app_path)...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!!
