Best JavaScript code snippet using playwright-internal
1-LECC+MAINCODE(LECTURES).py
Source:1-LECC+MAINCODE(LECTURES).py
...230231 window.clear()232 window.bgpic('LEC C & C++ BCG.png')233 turtle.onscreenclick(btnclicksecondpage,1)234 turtle.listen()235236 if Button_x_c <= x <= Button_x_c + ButtonLength_c:237 if Button_y_c <= y <= Button_y_c + ButtonWidth_c:238239 window.clear()240 window.bgpic('LEC C & C++ BCG.png')241 turtle.onscreenclick(btnclicksecondpageC,1)242 turtle.listen()243244 if distance((Button_x_aboutus_circle,Button_y_aboutus_cirlce),(x,y)) <= Button_R_aboutus_circle**2:245246 window.clear()247 window.bgpic('ABOUT US.png')248 turtle.onscreenclick(btnclickaboutusreturn,1)249 turtle.listen()250251 if Button_x_what <= x <= Button_x_what + ButtonLength_what:252 if Button_y_what <= y <= Button_y_what + ButtonWidth_what:253254 window.clear()255 window.bgpic('WHAT IS PROGRAMMING.png')256 turtle.onscreenclick(btnclickwip,1)257 turtle.listen()258259 if distance((Button_x_what_circle,Button_y_what_cirlce),(x,y)) <= Button_R_what_circle**2:260261 window.clear()262 window.bgpic('WHAT IS PROGRAMMING.png')263 turtle.onscreenclick(btnclickwip,1)264 turtle.listen()265266 if Button_x_why <= x <= Button_x_why + ButtonLength_why:267 if Button_y_why <= y <= Button_y_why + ButtonWidth_why:268269 window.clear()270 window.bgpic('WHY SHOULD WE LEARN PROGRAMMING.png')271 turtle.onscreenclick(btnclickwswlp,1)272 turtle.listen()273274 if distance((Button_x_why_circle,Button_y_why_cirlce),(x,y)) <= Button_R_why_circle**2:275276 window.clear()277 window.bgpic('WHY SHOULD WE LEARN PROGRAMMING.png')278 turtle.onscreenclick(btnclickwswlp,1)279 turtle.listen()280281 if Button_x_play <= x <= Button_x_play + ButtonLength_play:282 if Button_y_play <= y <= Button_y_play + ButtonWidth_play:283284 window.clear()285 window.bgpic('GAME_FRONT_PAGE.png')286 turtle.onscreenclick(btnclickplay,1)287 turtle.listen()288289290291292293294295#Function that returns you back to homepage from button "play"296def btnclickplay(x,y):297 if distance((Button_x_play_return_circle,Button_y_play_return_circle),(x,y)) <= Button_R_play_return_circle**2:298299 window.clear()300 window.bgpic('FRONT.png')301 turtle.onscreenclick(btnclickfirstpage,1)302 turtle.listen()303304 if Button_x_how <= x <= Button_x_how + ButtonLength_how:305 if Button_y_how <= y <= Button_y_how + ButtonWidth_how:306307 window.clear()308 window.bgpic('HOW TO PLAY.png')309 turtle.onscreenclick(btnclickhowtoplayreturn,1)310 turtle.listen()311312 if Button_x_play2 <= x <= Button_x_play2 + ButtonLength_play2:313 if Button_y_play2 <= y <= Button_y_play2 + ButtonWidth_play2:314315 window.clear()316 window.bgpic('GAME!!!')317 turtle.onscreenclick(printcoordinates,1)318 turtle.listen()319320321322#Function that returns you back from how to play323def btnclickhowtoplayreturn(x,y):324 if distance((Button_x_how_return_circle,Button_y_how_return_circle),(x,y)) <= Button_R_how_return_circle**2:325326 window.clear()327 window.bgpic('GAME_FRONT_PAGE.png')328 turtle.onscreenclick(btnclickplay,1)329 turtle.listen()330331332#Function that returns you back from about us to home333def btnclickaboutusreturn(x,y):334 if distance((Button_x_aboutus_return_circle,Button_y_aboutus_return_circle),(x,y)) <= Button_R_aboutus_return_circle**2:335336 window.clear()337 window.bgpic('FRONT.png')338 turtle.onscreenclick(btnclickfirstpage,1)339 turtle.listen()340341#Return button function for WHAT IS PROGRAMMING page342def btnclickwip(x,y):343344 if distance((Button_x_returnwip,Button_y_returnwip),(x,y)) <= Button_R_returnwip**2:345346 window.clear()347 window.bgpic('FRONT.png')348 turtle.onscreenclick(btnclickfirstpage,1)349 turtle.listen()350351#Return button function for WHY SHOULD WE LEARN PROGRAMMING page352def btnclickwswlp(x,y):353354 if distance((Button_x_returnwswlp,Button_y_returnwswlp),(x,y)) <= Button_R_returnwswlp**2:355356 window.clear()357 window.bgpic('FRONT.png')358 turtle.onscreenclick(btnclickfirstpage,1)359 turtle.listen()360361#Function of the second page with buttons beginner and advanced C button362def btnclicksecondpageC(x,y):363364 if Button_x_begc <= x <= Button_x_begc + ButtonLength_begc:365 if Button_y_begc <= y <= Button_y_begc + ButtonWidth_begc:366367 window.clear()368 window.bgpic('LEC BCG.png')369 turtle.onscreenclick(btnclickthirdpagebegc,1)370 turtle.listen()371372 if Button_x_advc <= x <= Button_x_advc + ButtonLength_advc:373 if Button_y_advc <= y <= Button_y_advc + ButtonWidth_advc:374375 window.clear()376 window.bgpic('LEC BCG.png')377 turtle.onscreenclick(btnclickthirdpageadvC,1)378 turtle.listen()379380#Function of the second page with buttons beginner and advanced Cpp button381def btnclicksecondpage(x,y):382383384 if Button_x_begcpp <= x <= Button_x_begcpp + ButtonLength_begcpp:385 if Button_y_begcpp <= y <= Button_y_begcpp + ButtonWidth_begcpp:386387 window.clear()388 window.bgpic('LEC BCG.png')389 turtle.onscreenclick(btnclickthirdpagebegcpp,1)390 turtle.listen()391392 if Button_x_advcpp <= x <= Button_x_advcpp + ButtonLength_advcpp:393 if Button_y_advcpp <= y <= Button_y_advcpp + ButtonWidth_advcpp:394395 window.clear()396 window.bgpic('LEC BCG.png')397 turtle.onscreenclick(btnclickthirdpageadvCpp,1)398 turtle.listen()399400#Function of the third page beginner C - ENRIKETA's lectures401402def btnclickthirdpagebegc(x,y):403 if Button_x_lec1 <= x <= Button_x_lec1 + ButtonLength_lec1:404 if Button_y_lec1 <= y <= Button_y_lec1 + ButtonWidth_lec1:405406 window.clear()407 window.bgpic('LESSON 1 ENRIKETA-1.png')408 turtle.onscreenclick(btnclick_part1_tutorial1_begc,1)409 turtle.listen()410411 if Button_x_lec2 <= x <= Button_x_lec2 + ButtonLength_lec2:412 if Button_y_lec2 <= y <= Button_y_lec2 + ButtonWidth_lec2:413414 window.clear()415 window.bgpic('LESSON 2 ENRIKETA-1.png')416 turtle.onscreenclick(btnclick_part1_tutorial2_begc,1)417 turtle.listen()418419 if Button_x_lec3 <= x <= Button_x_lec3 + ButtonLength_lec3:420 if Button_y_lec3 <= y <= Button_y_lec3 + ButtonWidth_lec3:421422 window.clear()423 window.bgpic('LESSON 3 ENRIKETA-1.png')424 turtle.onscreenclick(btnclick_part1_tutorial3_begc,1)425 turtle.listen()426427 if Button_x_lec4 <= x <= Button_x_lec4 + ButtonLength_lec4:428 if Button_y_lec4 <= y <= Button_y_lec4 + ButtonWidth_lec4:429430 window.clear()431 window.bgpic('LESSON 4 ENRIKETA-1.png')432 turtle.onscreenclick(btnclick_part1_tutorial4_begc,1)433 turtle.listen()434435 if Button_x_lec5 <= x <= Button_x_lec5 + ButtonLength_lec5:436 if Button_y_lec5 <= y <= Button_y_lec5 + ButtonWidth_lec5:437438 window.clear()439 window.bgpic('LESSON 5 ENRIKETA-1.png')440 turtle.onscreenclick(btnclick_part1_tutorial5_begc,1)441 turtle.listen()442443 if Button_x_returnhm <= x <= Button_x_returnhm + ButtonLength_returnhm:444 if Button_y_returnhm <= y <= Button_y_returnhm + ButtonWidth_returnhm:445446 window.clear()447 window.bgpic('FRONT.png')448 turtle.onscreenclick(btnclickfirstpage,1)449 turtle.listen()450451 if distance((Button_x_returnhmcircle1,Button_y_returnhmcircle1),(x,y)) <= Button_R_returnhmcircle1**2:452453 window.clear()454 window.bgpic('FRONT.png')455 turtle.onscreenclick(btnclickfirstpage,1)456 turtle.listen()457458 if distance((Button_x_returnhmcircle2,Button_y_returnhmcircle2),(x,y)) <= Button_R_returnhmcircle2**2:459460 window.clear()461 window.bgpic('FRONT.png')462 turtle.onscreenclick(btnclickfirstpage,1)463 turtle.listen()464465#The following functions are Enriketa's lectures and the buttons for each page466#From lecture 1 till 5 (The last lecture)467#Inside the functions are included buttons: nextpage, previouspage, turntohomescreen, turntolectures, playagame(This one is located in the last lecture)468469def btnclick_part1_tutorial1_begc(x,y):470471 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:472 window.clear()473 window.bgpic('LESSON 1 ENRIKETA-2.png')474 turtle.onscreenclick(btnclick_part2_tutorial1_begc,1)475 turtle.listen()476477def btnclick_part2_tutorial1_begc(x,y):478479 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:480 window.clear()481 window.bgpic('LESSON 2 ENRIKETA-1.png')482 turtle.onscreenclick(btnclick_part1_tutorial2_begc,1)483 turtle.listen()484485 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:486 window.clear()487 window.bgpic('LESSON 1 ENRIKETA-1.png')488 turtle.onscreenclick(btnclick_part1_tutorial1_begc,1)489 turtle.listen()490491 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:492 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:493 window.clear()494 window.bgpic('LEC BCG.png')495 turtle.onscreenclick(btnclickthirdpagebegc,1)496 turtle.listen()497498 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:499 window.clear()500 window.bgpic('LEC BCG.png')501 turtle.onscreenclick(btnclickthirdpagebegc,1)502 turtle.listen()503504def btnclick_part1_tutorial2_begc(x,y):505506 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:507 window.clear()508 window.bgpic('LESSON 2 ENRIKETA-2.png')509 turtle.onscreenclick(btnclick_part2_tutorial2_begc,1)510 turtle.listen()511512def btnclick_part2_tutorial2_begc(x,y):513514 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:515 window.clear()516 window.bgpic('LESSON 3 ENRIKETA-1.png')517 turtle.onscreenclick(btnclick_part1_tutorial3_begc,1)518 turtle.listen()519520 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:521 window.clear()522 window.bgpic('LESSON 2 ENRIKETA-1.png')523 turtle.onscreenclick(btnclick_part1_tutorial2_begc,1)524 turtle.listen()525526 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:527 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:528 window.clear()529 window.bgpic('LEC BCG.png')530 turtle.onscreenclick(btnclickthirdpagebegc,1)531 turtle.listen()532533 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:534 window.clear()535 window.bgpic('LEC BCG.png')536 turtle.onscreenclick(btnclickthirdpagebegc,1)537 turtle.listen()538539def btnclick_part1_tutorial3_begc(x,y):540541 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:542 window.clear()543 window.bgpic('LESSON 4 ENRIKETA-1.png')544 turtle.onscreenclick(btnclick_part1_tutorial4_begc,1)545 turtle.listen()546547 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:548 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:549 window.clear()550 window.bgpic('LEC BCG.png')551 turtle.onscreenclick(btnclickthirdpagebegc,1)552 turtle.listen()553554 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:555 window.clear()556 window.bgpic('LEC BCG.png')557 turtle.onscreenclick(btnclickthirdpagebegc,1)558 turtle.listen()559560def btnclick_part1_tutorial4_begc(x,y):561562 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:563 window.clear()564 window.bgpic('LESSON 4 ENRIKETA-2.png')565 turtle.onscreenclick(btnclick_part2_tutorial4_begc,1)566 turtle.listen()567568def btnclick_part2_tutorial4_begc(x,y):569570 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:571 window.clear()572 window.bgpic('LESSON 4 ENRIKETA-3.png')573 turtle.onscreenclick(btnclick_part3_tutorial4_begc,1)574 turtle.listen()575576 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:577 window.clear()578 window.bgpic('LESSON 4 ENRIKETA-1.png')579 turtle.onscreenclick(btnclick_part1_tutorial3_begc,1)580 turtle.listen()581582def btnclick_part3_tutorial4_begc(x,y):583 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:584 window.clear()585 window.bgpic('LESSON 5 ENRIKETA-1.png')586 turtle.onscreenclick(btnclick_part1_tutorial5_begc,1)587 turtle.listen()588589 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:590 window.clear()591 window.bgpic('LESSON 4 ENRIKETA-3.png')592 turtle.onscreenclick(btnclick_part2_tutorial4_begc,1)593 turtle.listen()594595 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:596 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:597 window.clear()598 window.bgpic('LEC BCG.png')599 turtle.onscreenclick(btnclickthirdpagebegc,1)600 turtle.listen()601602 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:603 window.clear()604 window.bgpic('LEC BCG.png')605 turtle.onscreenclick(btnclickthirdpagebegc,1)606 turtle.listen()607608def btnclick_part1_tutorial5_begc(x,y):609 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:610 window.clear()611 window.bgpic('LESSON 5 ENRIKETA-2.png')612 turtle.onscreenclick(btnclick_part2_tutorial5_begc,1)613 turtle.listen()614615def btnclick_part2_tutorial5_begc(x,y):616 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:617 window.clear()618 window.bgpic('LESSON 5 ENRIKETA-3.png')619 turtle.onscreenclick(btnclick_part3_tutorial5_begc,1)620 turtle.listen()621622 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:623 window.clear()624 window.bgpic('LESSON 5 ENRIKETA-1.png')625 turtle.onscreenclick(btnclick_part1_tutorial5_begc,1)626 turtle.listen()627628def btnclick_part3_tutorial5_begc(x,y):629 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:630 window.clear()631 window.bgpic('LESSON 5 ENRIKETA-2.png')632 turtle.onscreenclick(btnclick_part1_tutorial5_begc,1)633 turtle.listen()634635 if Button_x_playfromlecture <= x <= Button_x_playfromlecture+ButtonLength_playfromlecture:636 if Button_y_playfromlecture <= y <= Button_y_playfromlecture+ButtonWidth_playfromlecture:637 window.clear()638 window.bgpic('GAME_FRONT_PAGE.png')639 turtle.onscreenclick(btnclickplay,1)640 turtle.listen()641642 if distance((Button_x_returnhm_lec_circle1_left,Button_y_returnhm_lec_circle1_left),(x,y)) <= Button_R_returnhm_lec_circle1_left**2:643 window.clear()644 window.bgpic('FRONT.png')645 turtle.onscreenclick(btnclickfirstpage,1)646 turtle.listen()647648 if distance((Button_x_returnhm_lec_circle1_right,Button_y_returnhm_lec_circle1_right),(x,y)) <= Button_R_returnhm_lec_circle1_right**2:649 window.clear()650 window.bgpic('FRONT.png')651 turtle.onscreenclick(btnclickfirstpage,1)652 turtle.listen()653654 if Button_x_returnhm_lec <= x <= Button_x_returnhm_lec+ButtonLength_returnhm_lec:655 if Button_y_returnhm_lec <= y <= Button_y_returnhm_lec+ButtonWidth_returnhm_lec:656 window.clear()657 window.bgpic('FRONT.png')658 turtle.onscreenclick(btnclickfirstpage,1)659 turtle.listen()660661#Function of the third page advanced C - EVA's lectures662663def btnclickthirdpageadvC(x,y):664 if Button_x_lec1 <= x <= Button_x_lec1 + ButtonLength_lec1:665 if Button_y_lec1 <= y <= Button_y_lec1 + ButtonWidth_lec1:666667 window.clear()668 window.bgpic('LESSON 1 EVA-1.png')669 turtle.onscreenclick(btnclick_part1_tutorial1_advc,1)670 turtle.listen()671672 if Button_x_lec2 <= x <= Button_x_lec2 + ButtonLength_lec2:673 if Button_y_lec2 <= y <= Button_y_lec2 + ButtonWidth_lec2:674675 window.clear()676 window.bgpic('LESSON 2 EVA-1.png')677 turtle.onscreenclick(btnclick_part1_tutorial2_advc,1)678 turtle.listen()679680 if Button_x_lec3 <= x <= Button_x_lec3 + ButtonLength_lec3:681 if Button_y_lec3 <= y <= Button_y_lec3 + ButtonWidth_lec3:682683 window.clear()684 window.bgpic('LESSON 3 EVA-1.png')685 turtle.onscreenclick(btnclick_part1_tutorial3_advc,1)686 turtle.listen()687688 if Button_x_lec4 <= x <= Button_x_lec4 + ButtonLength_lec4:689 if Button_y_lec4 <= y <= Button_y_lec4 + ButtonWidth_lec4:690691 window.clear()692 window.bgpic('LESSON 4 EVA-1.png')693 turtle.onscreenclick(btnclick_part1_tutorial4_advc,1)694 turtle.listen()695696 if Button_x_lec5 <= x <= Button_x_lec5 + ButtonLength_lec5:697 if Button_y_lec5 <= y <= Button_y_lec5 + ButtonWidth_lec5:698699 window.clear()700 window.bgpic('LESSON 5 EVA-1.png')701 turtle.onscreenclick(btnclick_part1_tutorial5_advc,1)702 turtle.listen()703704 if Button_x_returnhm <= x <= Button_x_returnhm + ButtonLength_returnhm:705 if Button_y_returnhm <= y <= Button_y_returnhm + ButtonWidth_returnhm:706707 window.clear()708 window.bgpic('FRONT.png')709 turtle.onscreenclick(btnclickfirstpage,1)710 turtle.listen()711712 if distance((Button_x_returnhmcircle1,Button_y_returnhmcircle1),(x,y)) <= Button_R_returnhmcircle1**2:713714 window.clear()715 window.bgpic('FRONT.png')716 turtle.onscreenclick(btnclickfirstpage,1)717 turtle.listen()718719 if distance((Button_x_returnhmcircle2,Button_y_returnhmcircle2),(x,y)) <= Button_R_returnhmcircle2**2:720721 window.clear()722 window.bgpic('FRONT.png')723 turtle.onscreenclick(btnclickfirstpage,1)724 turtle.listen()725726#The following functions are EVA's lectures and the buttons for each page727#From lecture 1 till 5 (The last lecture)728#Inside the functions are included buttons: nextpage, previouspage, turntohomescreen, turntolectures, playagame(This one is located in the last lecture)729730def btnclick_part1_tutorial1_advc(x,y):731732 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:733 window.clear()734 window.bgpic('LESSON 1 EVA-2.png')735 turtle.onscreenclick(btnclick_part2_tutorial1_advc,1)736 turtle.listen()737738def btnclick_part2_tutorial1_advc(x,y):739 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:740 window.clear()741 window.bgpic('LESSON 1 EVA-3.png')742 turtle.onscreenclick(btnclick_part3_tutorial1_advc,1)743 turtle.listen()744745 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:746 window.clear()747 window.bgpic('LESSON 1 EVA-1.png')748 turtle.onscreenclick(btnclick_part1_tutorial1_advc,1)749 turtle.listen()750751def btnclick_part3_tutorial1_advc(x,y):752 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:753 window.clear()754 window.bgpic('LESSON 2 EVA-1.png')755 turtle.onscreenclick(btnclick_part1_tutorial2_advc,1)756 turtle.listen()757758 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:759 window.clear()760 window.bgpic('LESSON 1 EVA-3.png')761 turtle.onscreenclick(btnclick_part2_tutorial1_advc,1)762 turtle.listen()763764 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:765 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:766 window.clear()767 window.bgpic('LEC BCG.png')768 turtle.onscreenclick(btnclickthirdpageadvC,1)769 turtle.listen()770771 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:772 window.clear()773 window.bgpic('LEC BCG.png')774 turtle.onscreenclick(btnclickthirdpageadvC,1)775 turtle.listen()776777def btnclick_part1_tutorial2_advc(x,y):778 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:779 window.clear()780 window.bgpic('LESSON 3 EVA-1.png')781 turtle.onscreenclick(btnclick_part1_tutorial3_advc,1)782 turtle.listen()783784 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:785 window.clear()786 window.bgpic('LESSON 2 EVA-1.png')787 turtle.onscreenclick(btnclick_part1_tutorial2_advc,1)788 turtle.listen()789790 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:791 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:792 window.clear()793 window.bgpic('LEC BCG.png')794 turtle.onscreenclick(btnclickthirdpageadvC,1)795 turtle.listen()796797 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:798 window.clear()799 window.bgpic('LEC BCG.png')800 turtle.onscreenclick(btnclickthirdpageadvC,1)801 turtle.listen()802803def btnclick_part1_tutorial3_advc(x,y):804 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:805 window.clear()806 window.bgpic('LESSON 3 EVA-2.png')807 turtle.onscreenclick(btnclick_part2_tutorial3_advc,1)808 turtle.listen()809810def btnclick_part2_tutorial3_advc(x,y):811 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:812 window.clear()813 window.bgpic('LESSON 4 EVA-1.png')814 turtle.onscreenclick(btnclick_part1_tutorial4_advc,1)815 turtle.listen()816817 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:818 window.clear()819 window.bgpic('LESSON 3 EVA-1.png')820 turtle.onscreenclick(btnclick_part1_tutorial3_advc,1)821 turtle.listen()822823 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:824 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:825 window.clear()826 window.bgpic('LEC BCG.png')827 turtle.onscreenclick(btnclickthirdpageadvC,1)828 turtle.listen()829830 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:831 window.clear()832 window.bgpic('LEC BCG.png')833 turtle.onscreenclick(btnclickthirdpageadvC,1)834 turtle.listen()835836def btnclick_part1_tutorial4_advc(x,y):837 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:838 window.clear()839 window.bgpic('LESSON 4 EVA-2.png')840 turtle.onscreenclick(btnclick_part2_tutorial4_advc,1)841 turtle.listen()842843def btnclick_part2_tutorial4_advc(x,y):844 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:845 window.clear()846 window.bgpic('LESSON 5 EVA-1.png')847 turtle.onscreenclick(btnclick_part1_tutorial5_advc,1)848 turtle.listen()849850 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:851 window.clear()852 window.bgpic('LESSON 4 EVA-1.png')853 turtle.onscreenclick(btnclick_part1_tutorial4_advc,1)854 turtle.listen()855856 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:857 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:858 window.clear()859 window.bgpic('LEC BCG.png')860 turtle.onscreenclick(btnclickthirdpageadvC,1)861 turtle.listen()862863 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:864 window.clear()865 window.bgpic('LEC BCG.png')866 turtle.onscreenclick(btnclickthirdpageadvC,1)867 turtle.listen()868869def btnclick_part1_tutorial5_advc(x,y):870 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:871 window.clear()872 window.bgpic('LESSON 5 EVA-2.png')873 turtle.onscreenclick(btnclick_part2_tutorial5_advc,1)874 turtle.listen()875876def btnclick_part2_tutorial5_advc(x,y):877878 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:879 window.clear()880 window.bgpic('LESSON 5 EVA-1.png')881 turtle.onscreenclick(btnclick_part1_tutorial5_advc,1)882 turtle.listen()883884 if Button_x_playfromlecture <= x <= Button_x_playfromlecture+ButtonLength_playfromlecture:885 if Button_y_playfromlecture <= y <= Button_y_playfromlecture+ButtonWidth_playfromlecture:886 window.clear()887 window.bgpic('GAME_FRONT_PAGE.png')888 turtle.onscreenclick(btnclickplay,1)889 turtle.listen()890891 if distance((Button_x_returnhm_lec_circle1_left,Button_y_returnhm_lec_circle1_left),(x,y)) <= Button_R_returnhm_lec_circle1_left**2:892 window.clear()893 window.bgpic('FRONT.png')894 turtle.onscreenclick(btnclickfirstpage,1)895 turtle.listen()896897 if distance((Button_x_returnhm_lec_circle1_right,Button_y_returnhm_lec_circle1_right),(x,y)) <= Button_R_returnhm_lec_circle1_right**2:898 window.clear()899 window.bgpic('FRONT.png')900 turtle.onscreenclick(btnclickfirstpage,1)901 turtle.listen()902903 if Button_x_returnhm_lec <= x <= Button_x_returnhm_lec+ButtonLength_returnhm_lec:904 if Button_y_returnhm_lec <= y <= Button_y_returnhm_lec+ButtonWidth_returnhm_lec:905 window.clear()906 window.bgpic('FRONT.png')907 turtle.onscreenclick(btnclickfirstpage,1)908 turtle.listen()909910#Function of the third page beginner CPP - KLAUDIA's lectures911912def btnclickthirdpagebegcpp(x,y):913 if Button_x_lec1 <= x <= Button_x_lec1 + ButtonLength_lec1:914 if Button_y_lec1 <= y <= Button_y_lec1 + ButtonWidth_lec1:915916 window.clear()917 window.bgpic('LESSON 1 KLAUDIA-1.png')918 turtle.onscreenclick(btnclick_part1_tutorial1_begcpp,1)919 turtle.listen()920921 if Button_x_lec2 <= x <= Button_x_lec2 + ButtonLength_lec2:922 if Button_y_lec2 <= y <= Button_y_lec2 + ButtonWidth_lec2:923924 window.clear()925 window.bgpic('LESSON 2 KLAUDIA-1.png')926 turtle.onscreenclick(btnclick_part1_tutorial2_begcpp,1)927 turtle.listen()928929 if Button_x_lec3 <= x <= Button_x_lec3 + ButtonLength_lec3:930 if Button_y_lec3 <= y <= Button_y_lec3 + ButtonWidth_lec3:931932 window.clear()933 window.bgpic('LESSON 3 KLAUDIA-1.png')934 turtle.onscreenclick(btnclick_part1_tutorial3_begcpp,1)935 turtle.listen()936937 if Button_x_lec4 <= x <= Button_x_lec4 + ButtonLength_lec4:938 if Button_y_lec4 <= y <= Button_y_lec4 + ButtonWidth_lec4:939940 window.clear()941 window.bgpic('LESSON 4 KLAUDIA-1.png')942 turtle.onscreenclick(btnclick_part1_tutorial4_begcpp,1)943 turtle.listen()944945 if Button_x_lec5 <= x <= Button_x_lec5 + ButtonLength_lec5:946 if Button_y_lec5 <= y <= Button_y_lec5 + ButtonWidth_lec5:947948 window.clear()949 window.bgpic('LESSON 5 KLAUDIA-1.png')950 turtle.onscreenclick(btnclick_part1_tutorial5_begcpp,1)951 turtle.listen()952953 if Button_x_returnhm <= x <= Button_x_returnhm + ButtonLength_returnhm:954 if Button_y_returnhm <= y <= Button_y_returnhm + ButtonWidth_returnhm:955956 window.clear()957 window.bgpic('FRONT.png')958 turtle.onscreenclick(btnclickfirstpage,1)959 turtle.listen()960961 if distance((Button_x_returnhmcircle1,Button_y_returnhmcircle1),(x,y)) <= Button_R_returnhmcircle1**2:962963 window.clear()964 window.bgpic('FRONT.png')965 turtle.onscreenclick(btnclickfirstpage,1)966 turtle.listen()967968 if distance((Button_x_returnhmcircle2,Button_y_returnhmcircle2),(x,y)) <= Button_R_returnhmcircle2**2:969970 window.clear()971 window.bgpic('FRONT.png')972 turtle.onscreenclick(btnclickfirstpage,1)973 turtle.listen()974975#The following functions are KLAUDIA's lectures and the buttons for each page976#From lecture 1 till 5 (The last lecture)977#Inside the functions are included buttons: nextpage, previouspage, turntohomescreen, turntolectures, playagame(This one is located in the last lecture)978979def btnclick_part1_tutorial1_begcpp(x,y):980981 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:982 window.clear()983 window.bgpic('LESSON 1 KLAUDIA-2.png')984 turtle.onscreenclick(btnclick_part2_tutorial1_begcpp,1)985 turtle.listen()986987988def btnclick_part2_tutorial1_begcpp(x,y):989 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:990 window.clear()991 window.bgpic('LESSON 2 KLAUDIA-1.png')992 turtle.onscreenclick(btnclick_part1_tutorial2_begcpp,1)993 turtle.listen()994995 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:996 window.clear()997 window.bgpic('LESSON 1 KLAUDIA-1.png')998 turtle.onscreenclick(btnclick_part1_tutorial1_begcpp,1)999 turtle.listen()10001001 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1002 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1003 window.clear()1004 window.bgpic('LEC BCG.png')1005 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1006 turtle.listen()10071008 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1009 window.clear()1010 window.bgpic('LEC BCG.png')1011 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1012 turtle.listen()10131014def btnclick_part1_tutorial2_begcpp(x,y):10151016 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1017 window.clear()1018 window.bgpic('LESSON 2 KLAUDIA-2.png')1019 turtle.onscreenclick(btnclick_part2_tutorial2_begcpp,1)1020 turtle.listen()10211022def btnclick_part2_tutorial2_begcpp(x,y):1023 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1024 window.clear()1025 window.bgpic('LESSON 3 KLAUDIA-1.png')1026 turtle.onscreenclick(btnclick_part1_tutorial3_begcpp,1)1027 turtle.listen()10281029 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1030 window.clear()1031 window.bgpic('LESSON 2 KLAUDIA-1.png')1032 turtle.onscreenclick(btnclick_part1_tutorial2_begcpp,1)1033 turtle.listen()10341035 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1036 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1037 window.clear()1038 window.bgpic('LEC BCG.png')1039 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1040 turtle.listen()10411042 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1043 window.clear()1044 window.bgpic('LEC BCG.png')1045 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1046 turtle.listen()10471048def btnclick_part1_tutorial3_begcpp(x,y):10491050 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1051 window.clear()1052 window.bgpic('LESSON 3 KLAUDIA-2.png')1053 turtle.onscreenclick(btnclick_part2_tutorial3_begcpp,1)1054 turtle.listen()10551056def btnclick_part2_tutorial3_begcpp(x,y):1057 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1058 window.clear()1059 window.bgpic('LESSON 3 KLAUDIA-3.png')1060 turtle.onscreenclick(btnclick_part3_tutorial3_begcpp,1)1061 turtle.listen()10621063 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1064 window.clear()1065 window.bgpic('LESSON 3 KLAUDIA-1.png')1066 turtle.onscreenclick(btnclick_part1_tutorial3_begcpp,1)1067 turtle.listen()10681069def btnclick_part3_tutorial3_begcpp(x,y):10701071 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1072 window.clear()1073 window.bgpic('LESSON 4 KLAUDIA-1.png')1074 turtle.onscreenclick(btnclick_part1_tutorial4_begcpp,1)1075 turtle.listen()10761077 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1078 window.clear()1079 window.bgpic('LESSON 3 KLAUDIA-2.png')1080 turtle.onscreenclick(btnclick_part2_tutorial3_begcpp,1)1081 turtle.listen()10821083 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1084 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1085 window.clear()1086 window.bgpic('LEC BCG.png')1087 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1088 turtle.listen()10891090 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1091 window.clear()1092 window.bgpic('LEC BCG.png')1093 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1094 turtle.listen()10951096def btnclick_part1_tutorial4_begcpp(x,y):10971098 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1099 window.clear()1100 window.bgpic('LESSON 4 KLAUDIA-2.png')1101 turtle.onscreenclick(btnclick_part2_tutorial4_begcpp,1)1102 turtle.listen()11031104def btnclick_part2_tutorial4_begcpp(x,y):1105 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1106 window.clear()1107 window.bgpic('LESSON 4 KLAUDIA-3.png')1108 turtle.onscreenclick(btnclick_part3_tutorial4_begcpp,1)1109 turtle.listen()11101111 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1112 window.clear()1113 window.bgpic('LESSON 4 KLAUDIA-1.png')1114 turtle.onscreenclick(btnclick_part1_tutorial4_begcpp,1)1115 turtle.listen()11161117def btnclick_part3_tutorial4_begcpp(x,y):11181119 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1120 window.clear()1121 window.bgpic('LESSON 4 KLAUDIA-4.png')1122 turtle.onscreenclick(btnclick_part4_tutorial4_begcpp,1)1123 turtle.listen()11241125def btnclick_part4_tutorial4_begcpp(x,y):11261127 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1128 window.clear()1129 window.bgpic('LESSON 5 KLAUDIA-1.png')1130 turtle.onscreenclick(btnclick_part1_tutorial5_begcpp,1)1131 turtle.listen()11321133 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1134 window.clear()1135 window.bgpic('LESSON 4 KLAUDIA-3.png')1136 turtle.onscreenclick(btnclick_part1_tutorial4_begcpp,1)1137 turtle.listen()11381139 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1140 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1141 window.clear()1142 window.bgpic('LEC BCG.png')1143 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1144 turtle.listen()11451146 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1147 window.clear()1148 window.bgpic('LEC BCG.png')1149 turtle.onscreenclick(btnclickthirdpagebegcpp,1)1150 turtle.listen()11511152def btnclick_part1_tutorial5_begcpp(x,y):1153 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1154 window.clear()1155 window.bgpic('LESSON 5 KLAUDIA-2.png')1156 turtle.onscreenclick(btnclick_part2_tutorial5_begcpp,1)1157 turtle.listen()11581159def btnclick_part2_tutorial5_begcpp(x,y):1160 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1161 window.clear()1162 window.bgpic('LESSON 5 KLAUDIA-3.png')1163 turtle.onscreenclick(btnclick_part3_tutorial5_begcpp,1)1164 turtle.listen()11651166 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1167 window.clear()1168 window.bgpic('LESSON 5 KLAUDIA-1.png')1169 turtle.onscreenclick(btnclick_part1_tutorial5_begcpp,1)1170 turtle.listen()11711172def btnclick_part3_tutorial5_begcpp(x,y):11731174 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1175 window.clear()1176 window.bgpic('LESSON 5 KLAUDIA-4.png')1177 turtle.onscreenclick(btnclick_part4_tutorial5_begcpp,1)1178 turtle.listen()11791180def btnclick_part4_tutorial5_begcpp(x,y):11811182 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1183 window.clear()1184 window.bgpic('LESSON 5 KLAUDIA-3.png')1185 turtle.onscreenclick(btnclick_part1_tutorial4_begcpp,1)1186 turtle.listen()11871188 if Button_x_playfromlecture <= x <= Button_x_playfromlecture+ButtonLength_playfromlecture:1189 if Button_y_playfromlecture <= y <= Button_y_playfromlecture+ButtonWidth_playfromlecture:1190 window.clear()1191 window.bgpic('GAME_FRONT_PAGE.png')1192 turtle.onscreenclick(btnclickplay,1)1193 turtle.listen()11941195 if distance((Button_x_returnhm_lec_circle1_left,Button_y_returnhm_lec_circle1_left),(x,y)) <= Button_R_returnhm_lec_circle1_left**2:1196 window.clear()1197 window.bgpic('FRONT.png')1198 turtle.onscreenclick(btnclickfirstpage,1)1199 turtle.listen()12001201 if distance((Button_x_returnhm_lec_circle1_right,Button_y_returnhm_lec_circle1_right),(x,y)) <= Button_R_returnhm_lec_circle1_right**2:1202 window.clear()1203 window.bgpic('FRONT.png')1204 turtle.onscreenclick(btnclickfirstpage,1)1205 turtle.listen()12061207 if Button_x_returnhm_lec <= x <= Button_x_returnhm_lec+ButtonLength_returnhm_lec:1208 if Button_y_returnhm_lec <= y <= Button_y_returnhm_lec+ButtonWidth_returnhm_lec:1209 window.clear()1210 window.bgpic('FRONT.png')1211 turtle.onscreenclick(btnclickfirstpage,1)1212 turtle.listen()12131214#Function of the third page advanced CPP - ENSILD's lectures1215def btnclickthirdpageadvCpp(x,y):1216 if Button_x_lec1 <= x <= Button_x_lec1 + ButtonLength_lec1:1217 if Button_y_lec1 <= y <= Button_y_lec1 + ButtonWidth_lec1:12181219 window.clear()1220 window.bgpic('LESSON 1 ENSILD-1.png')1221 turtle.onscreenclick(btnclick_part1_tutorial1_advcpp,1)1222 turtle.listen()12231224 if Button_x_lec2 <= x <= Button_x_lec2 + ButtonLength_lec2:1225 if Button_y_lec2 <= y <= Button_y_lec2 + ButtonWidth_lec2:12261227 window.clear()1228 window.bgpic('LESSON 2 ENSILD-1.png')1229 turtle.onscreenclick(btnclick_part1_tutorial2_advcpp,1)1230 turtle.listen()12311232 if Button_x_lec3 <= x <= Button_x_lec3 + ButtonLength_lec3:1233 if Button_y_lec3 <= y <= Button_y_lec3 + ButtonWidth_lec3:12341235 window.clear()1236 window.bgpic('LESSON 3 ENSILD-1.png')1237 turtle.onscreenclick(btnclick_part1_tutorial3_advcpp,1)1238 turtle.listen()12391240 if Button_x_lec4 <= x <= Button_x_lec4 + ButtonLength_lec4:1241 if Button_y_lec4 <= y <= Button_y_lec4 + ButtonWidth_lec4:12421243 window.clear()1244 window.bgpic('LESSON 4 ENSILD-1.png')1245 turtle.onscreenclick(btnclick_part1_tutorial4_advcpp,1)1246 turtle.listen()12471248 if Button_x_lec5 <= x <= Button_x_lec5 + ButtonLength_lec5:1249 if Button_y_lec5 <= y <= Button_y_lec5 + ButtonWidth_lec5:12501251 window.clear()1252 window.bgpic('LESSON 5 ENSILD-1.png')1253 turtle.onscreenclick(btnclick_part1_tutorial5_advcpp,1)1254 turtle.listen()12551256 if Button_x_returnhm <= x <= Button_x_returnhm + ButtonLength_returnhm:1257 if Button_y_returnhm <= y <= Button_y_returnhm + ButtonWidth_returnhm:12581259 window.clear()1260 window.bgpic('FRONT.png')1261 turtle.onscreenclick(btnclickfirstpage,1)1262 turtle.listen()12631264 if distance((Button_x_returnhmcircle1,Button_y_returnhmcircle1),(x,y)) <= Button_R_returnhmcircle1**2:12651266 window.clear()1267 window.bgpic('FRONT.png')1268 turtle.onscreenclick(btnclickfirstpage,1)1269 turtle.listen()12701271 if distance((Button_x_returnhmcircle2,Button_y_returnhmcircle2),(x,y)) <= Button_R_returnhmcircle2**2:12721273 window.clear()1274 window.bgpic('FRONT.png')1275 turtle.onscreenclick(btnclickfirstpage,1)1276 turtle.listen()12771278#The following functions are Ensildi's lectures and the buttons for each page1279#From lecture 1 till 5 (The last lecture)1280#Inside the functions are included buttons: nextpage, previouspage, turntohomescreen, turntolectures, playagame(This one is located in the last lecture)12811282def btnclick_part1_tutorial1_advcpp(x,y):12831284 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1285 window.clear()1286 window.bgpic('LESSON 1 ENSILD-2.png')1287 turtle.onscreenclick(btnclick_part2_tutorial1_advcpp,1)1288 turtle.listen()12891290def btnclick_part2_tutorial1_advcpp(x,y):12911292 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1293 window.clear()1294 window.bgpic('LESSON 2 ENSILD-1.png')1295 turtle.onscreenclick(btnclick_part1_tutorial2_advcpp,1)1296 turtle.listen()12971298 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1299 window.clear()1300 window.bgpic('LESSON 1 ENSILD-1.png')1301 turtle.onscreenclick(btnclick_part1_tutorial1_advcpp,1)1302 turtle.listen()13031304 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1305 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1306 window.clear()1307 window.bgpic('LEC BCG.png')1308 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1309 turtle.listen()13101311 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1312 window.clear()1313 window.bgpic('LEC BCG.png')1314 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1315 turtle.listen()13161317def btnclick_part1_tutorial2_advcpp(x,y):13181319 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1320 window.clear()1321 window.bgpic('LESSON 2 ENSILD-2.png')1322 turtle.onscreenclick(btnclick_part2_tutorial2_advcpp,1)1323 turtle.listen()13241325def btnclick_part2_tutorial2_advcpp(x,y):13261327 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1328 window.clear()1329 window.bgpic('LESSON 2 ENSILD-3.png')1330 turtle.onscreenclick(btnclick_part3_tutorial2_advcpp,1)1331 turtle.listen()13321333 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1334 window.clear()1335 window.bgpic('LESSON 2 ENSILD-1.png')1336 turtle.onscreenclick(btnclick_part1_tutorial2_advcpp,1)1337 turtle.listen()13381339def btnclick_part3_tutorial2_advcpp(x,y):13401341 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1342 window.clear()1343 window.bgpic('LESSON 2 ENSILD-4.png')1344 turtle.onscreenclick(btnclick_part4_tutorial2_advcpp,1)1345 turtle.listen()13461347 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1348 window.clear()1349 window.bgpic('LESSON 2 ENSILD-2.png')1350 turtle.onscreenclick(btnclick_part2_tutorial2_advcpp,1)1351 turtle.listen()13521353def btnclick_part4_tutorial2_advcpp(x,y):13541355 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1356 window.clear()1357 window.bgpic('LESSON 3 ENSILD-1.png')1358 turtle.onscreenclick(btnclick_part1_tutorial3_advcpp,1)1359 turtle.listen()13601361 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1362 window.clear()1363 window.bgpic('LESSON 2 ENSILD-3.png')1364 turtle.onscreenclick(btnclick_part3_tutorial2_advcpp,1)1365 turtle.listen()13661367 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1368 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1369 window.clear()1370 window.bgpic('LEC BCG.png')1371 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1372 turtle.listen()13731374 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1375 window.clear()1376 window.bgpic('LEC BCG.png')1377 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1378 turtle.listen()13791380def btnclick_part1_tutorial3_advcpp(x,y):13811382 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1383 window.clear()1384 window.bgpic('LESSON 3 ENSILD-2.png')1385 turtle.onscreenclick(btnclick_part2_tutorial3_advcpp,1)1386 turtle.listen()13871388def btnclick_part2_tutorial3_advcpp(x,y):13891390 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1391 window.clear()1392 window.bgpic('LESSON 3 ENSILD-3.png')1393 turtle.onscreenclick(btnclick_part3_tutorial3_advcpp,1)1394 turtle.listen()13951396 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1397 window.clear()1398 window.bgpic('LESSON 3 ENSILD-1.png')1399 turtle.onscreenclick(btnclick_part1_tutorial3_advcpp,1)1400 turtle.listen()14011402def btnclick_part3_tutorial3_advcpp(x,y):14031404 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1405 window.clear()1406 window.bgpic('LESSON 4 ENSILD-1.png')1407 turtle.onscreenclick(btnclick_part1_tutorial4_advcpp,1)1408 turtle.listen()14091410 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1411 window.clear()1412 window.bgpic('LESSON 3 ENSILD-2.png')1413 turtle.onscreenclick(btnclick_part2_tutorial3_advcpp,1)1414 turtle.listen()14151416 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1417 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1418 window.clear()1419 window.bgpic('LEC BCG.png')1420 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1421 turtle.listen()14221423 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1424 window.clear()1425 window.bgpic('LEC BCG.png')1426 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1427 turtle.listen()14281429def btnclick_part1_tutorial4_advcpp(x,y):14301431 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1432 window.clear()1433 window.bgpic('LESSON 4 ENSILD-2.png')1434 turtle.onscreenclick(btnclick_part2_tutorial4_advcpp,1)1435 turtle.listen()14361437def btnclick_part2_tutorial4_advcpp(x,y):14381439 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1440 window.clear()1441 window.bgpic('LESSON 5 ENSILD-1.png')1442 turtle.onscreenclick(btnclick_part1_tutorial5_advcpp,1)1443 turtle.listen()14441445 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1446 window.clear()1447 window.bgpic('LESSON 4 ENSILD-1.png')1448 turtle.onscreenclick(btnclick_part1_tutorial4_advcpp,1)1449 turtle.listen()14501451 if Button_x_returntolecture <= x <= Button_x_returntolecture+ButtonLength_returntolecture:1452 if Button_y_returntolecture <= y <= Button_y_returntolecture+ButtonWidth_returntolecture:1453 window.clear()1454 window.bgpic('LEC BCG.png')1455 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1456 turtle.listen()14571458 if distance((Button_x_lecture_circle3_center,Button_y_lecture_circle3_center),(x,y)) <= Button_R_lecture_circle3_center**2:1459 window.clear()1460 window.bgpic('LEC BCG.png')1461 turtle.onscreenclick(btnclickthirdpageadvCpp,1)1462 turtle.listen()14631464def btnclick_part1_tutorial5_advcpp(x,y):14651466 if distance((Button_x_lecture_circle1_next,Button_y_lecture_circle1_next),(x,y)) <= Button_R_lecture_circle1_next**2:1467 window.clear()1468 window.bgpic('LESSON 5 ENSILD-2.png')1469 turtle.onscreenclick(btnclick_part2_tutorial5_advcpp,1)1470 turtle.listen()14711472def btnclick_part2_tutorial5_advcpp(x,y):14731474 if distance((Button_x_lecture_circle2_prev,Button_y_lecture_circle2_prev),(x,y)) <= Button_R_lecture_circle2_prev**2:1475 window.clear()1476 window.bgpic('LESSON 5 ENSILD-1.png')1477 turtle.onscreenclick(btnclick_part1_tutorial5_advcpp,1)1478 turtle.listen()14791480 if Button_x_playfromlecture <= x <= Button_x_playfromlecture+ButtonLength_playfromlecture:1481 if Button_y_playfromlecture <= y <= Button_y_playfromlecture+ButtonWidth_playfromlecture:1482 window.clear()1483 window.bgpic('GAME_FRONT_PAGE.png')1484 turtle.onscreenclick(btnclickplay,1)1485 turtle.listen()14861487 if distance((Button_x_returnhm_lec_circle1_left,Button_y_returnhm_lec_circle1_left),(x,y)) <= Button_R_returnhm_lec_circle1_left**2:1488 window.clear()1489 window.bgpic('FRONT.png')1490 turtle.onscreenclick(btnclickfirstpage,1)1491 turtle.listen()14921493 if distance((Button_x_returnhm_lec_circle1_right,Button_y_returnhm_lec_circle1_right),(x,y)) <= Button_R_returnhm_lec_circle1_right**2:1494 window.clear()1495 window.bgpic('FRONT.png')1496 turtle.onscreenclick(btnclickfirstpage,1)1497 turtle.listen()14981499 if Button_x_returnhm_lec <= x <= Button_x_returnhm_lec+ButtonLength_returnhm_lec:1500 if Button_y_returnhm_lec <= y <= Button_y_returnhm_lec+ButtonWidth_returnhm_lec:1501 window.clear()1502 window.bgpic('FRONT.png')1503 turtle.onscreenclick(btnclickfirstpage,1)1504 turtle.listen()1505150615071508150915101511151215131514turtle.onscreenclick(btnclickfirstpage,1)1515turtle.listen()15161517
...
__init__.py
Source:__init__.py
1xiaozhan_reading_review = {2 '4-1': '/toefl/read/practicereview-52-13.html',3 '4-2': '/toefl/read/practicereview-53-13.html',4 '4-3': '/toefl/read/practicereview-54-13.html',5 '3-1': '/toefl/read/practicereview-35-13.html',6 '3-2': '/toefl/read/practicereview-36-13.html',7 '3-3': '/toefl/read/practicereview-37-13.html',8 '2-1': '/toefl/read/practicereview-18-13.html',9 '2-2': '/toefl/read/practicereview-19-13.html',10 '2-3': '/toefl/read/practicereview-20-13.html',11 '1-1': '/toefl/read/practicereview-1-13.html',12 '1-2': '/toefl/read/practicereview-2-13.html',13 '1-3': '/toefl/read/practicereview-3-13.html',14 '8-1': '/toefl/read/practicereview-120-13.html',15 '8-2': '/toefl/read/practicereview-121-13.html',16 '8-3': '/toefl/read/practicereview-122-13.html',17 '7-1': '/toefl/read/practicereview-103-13.html',18 '7-2': '/toefl/read/practicereview-104-13.html',19 '7-3': '/toefl/read/practicereview-105-13.html',20 '6-1': '/toefl/read/practicereview-86-13.html',21 '6-2': '/toefl/read/practicereview-87-13.html',22 '6-3': '/toefl/read/practicereview-88-13.html',23 '5-1': '/toefl/read/practicereview-69-13.html',24 '5-2': '/toefl/read/practicereview-70-13.html',25 '5-3': '/toefl/read/practicereview-71-13.html',26 '12-1': '/toefl/read/practicereview-188-13.html',27 '12-2': '/toefl/read/practicereview-189-13.html',28 '12-3': '/toefl/read/practicereview-190-13.html',29 '11-1': '/toefl/read/practicereview-171-13.html',30 '11-2': '/toefl/read/practicereview-172-13.html',31 '11-3': '/toefl/read/practicereview-173-13.html',32 '10-1': '/toefl/read/practicereview-154-13.html',33 '10-2': '/toefl/read/practicereview-155-13.html',34 '10-3': '/toefl/read/practicereview-156-13.html',35 '9-1': '/toefl/read/practicereview-137-13.html',36 '9-2': '/toefl/read/practicereview-138-13.html',37 '9-3': '/toefl/read/practicereview-139-13.html',38 '16-1': '/toefl/read/practicereview-256-13.html',39 '16-2': '/toefl/read/practicereview-257-13.html',40 '16-3': '/toefl/read/practicereview-258-13.html',41 '15-1': '/toefl/read/practicereview-239-13.html',42 '15-2': '/toefl/read/practicereview-240-13.html',43 '15-3': '/toefl/read/practicereview-241-13.html',44 '14-1': '/toefl/read/practicereview-222-13.html',45 '14-2': '/toefl/read/practicereview-223-13.html',46 '14-3': '/toefl/read/practicereview-224-13.html',47 '13-1': '/toefl/read/practicereview-205-13.html',48 '13-2': '/toefl/read/practicereview-206-13.html',49 '13-3': '/toefl/read/practicereview-207-13.html',50 '20-1': '/toefl/read/practicereview-324-13.html',51 '20-2': '/toefl/read/practicereview-325-13.html',52 '20-3': '/toefl/read/practicereview-326-13.html',53 '19-1': '/toefl/read/practicereview-307-13.html',54 '19-2': '/toefl/read/practicereview-308-13.html',55 '19-3': '/toefl/read/practicereview-309-13.html',56 '18-1': '/toefl/read/practicereview-290-13.html',57 '18-2': '/toefl/read/practicereview-291-13.html',58 '18-3': '/toefl/read/practicereview-292-13.html',59 '17-1': '/toefl/read/practicereview-273-13.html',60 '17-2': '/toefl/read/practicereview-274-13.html',61 '17-3': '/toefl/read/practicereview-275-13.html',62 '24-1': '/toefl/read/practicereview-392-13.html',63 '24-2': '/toefl/read/practicereview-393-13.html',64 '24-3': '/toefl/read/practicereview-394-13.html',65 '23-1': '/toefl/read/practicereview-375-13.html',66 '23-2': '/toefl/read/practicereview-376-13.html',67 '23-3': '/toefl/read/practicereview-377-13.html',68 '22-1': '/toefl/read/practicereview-358-13.html',69 '22-2': '/toefl/read/practicereview-359-13.html',70 '22-3': '/toefl/read/practicereview-360-13.html',71 '21-1': '/toefl/read/practicereview-341-13.html',72 '21-2': '/toefl/read/practicereview-342-13.html',73 '21-3': '/toefl/read/practicereview-343-13.html',74 '28-1': '/toefl/read/practicereview-460-13.html',75 '28-2': '/toefl/read/practicereview-461-13.html',76 '28-3': '/toefl/read/practicereview-462-13.html',77 '27-1': '/toefl/read/practicereview-443-13.html',78 '27-2': '/toefl/read/practicereview-444-13.html',79 '27-3': '/toefl/read/practicereview-445-13.html',80 '26-1': '/toefl/read/practicereview-426-13.html',81 '26-2': '/toefl/read/practicereview-427-13.html',82 '26-3': '/toefl/read/practicereview-428-13.html',83 '25-1': '/toefl/read/practicereview-409-13.html',84 '25-2': '/toefl/read/practicereview-410-13.html',85 '25-3': '/toefl/read/practicereview-411-13.html',86 '32-1': '/toefl/read/practicereview-528-13.html',87 '32-2': '/toefl/read/practicereview-529-13.html',88 '32-3': '/toefl/read/practicereview-530-13.html',89 '31-1': '/toefl/read/practicereview-511-13.html',90 '31-2': '/toefl/read/practicereview-512-13.html',91 '31-3': '/toefl/read/practicereview-513-13.html',92 '30-1': '/toefl/read/practicereview-494-13.html',93 '30-2': '/toefl/read/practicereview-495-13.html',94 '30-3': '/toefl/read/practicereview-496-13.html',95 '29-1': '/toefl/read/practicereview-477-13.html',96 '29-2': '/toefl/read/practicereview-478-13.html',97 '29-3': '/toefl/read/practicereview-479-13.html',98 '36-1': '/toefl/read/practicereview-951-13.html',99 '36-2': '/toefl/read/practicereview-952-13.html',100 '36-3': '/toefl/read/practicereview-953-13.html',101 '35-1': '/toefl/read/practicereview-917-13.html',102 '35-2': '/toefl/read/practicereview-918-13.html',103 '35-3': '/toefl/read/practicereview-919-13.html',104 '34-1': '/toefl/read/practicereview-562-13.html',105 '34-2': '/toefl/read/practicereview-563-13.html',106 '34-3': '/toefl/read/practicereview-564-13.html',107 '33-1': '/toefl/read/practicereview-545-13.html',108 '33-2': '/toefl/read/practicereview-546-13.html',109 '33-3': '/toefl/read/practicereview-547-13.html',110 '40-1': '/toefl/read/practicereview-611-13.html',111 '40-2': '/toefl/read/practicereview-612-13.html',112 '40-3': '/toefl/read/practicereview-613-13.html',113 '39-1': '/toefl/read/practicereview-934-13.html',114 '39-2': '/toefl/read/practicereview-935-13.html',115 '39-3': '/toefl/read/practicereview-936-13.html',116 '38-1': '/toefl/read/practicereview-968-13.html',117 '38-2': '/toefl/read/practicereview-969-13.html',118 '38-3': '/toefl/read/practicereview-970-13.html',119 '37-1': '/toefl/read/practicereview-985-13.html',120 '37-2': '/toefl/read/practicereview-986-13.html',121 '37-3': '/toefl/read/practicereview-987-13.html',122 '44-1': '/toefl/read/practicereview-679-13.html',123 '44-2': '/toefl/read/practicereview-680-13.html',124 '44-3': '/toefl/read/practicereview-681-13.html',125 '43-1': '/toefl/read/practicereview-662-13.html',126 '43-2': '/toefl/read/practicereview-663-13.html',127 '43-3': '/toefl/read/practicereview-664-13.html',128 '42-1': '/toefl/read/practicereview-645-13.html',129 '42-2': '/toefl/read/practicereview-646-13.html',130 '42-3': '/toefl/read/practicereview-647-13.html',131 '41-1': '/toefl/read/practicereview-628-13.html',132 '41-2': '/toefl/read/practicereview-629-13.html',133 '41-3': '/toefl/read/practicereview-630-13.html',134 '48-1': '/toefl/read/practicereview-747-13.html',135 '48-2': '/toefl/read/practicereview-748-13.html',136 '48-3': '/toefl/read/practicereview-749-13.html',137 '47-1': '/toefl/read/practicereview-730-13.html',138 '47-2': '/toefl/read/practicereview-731-13.html',139 '47-3': '/toefl/read/practicereview-732-13.html',140 '46-1': '/toefl/read/practicereview-713-13.html',141 '46-2': '/toefl/read/practicereview-714-13.html',142 '46-3': '/toefl/read/practicereview-715-13.html',143 '45-1': '/toefl/read/practicereview-696-13.html',144 '45-2': '/toefl/read/practicereview-697-13.html',145 '45-3': '/toefl/read/practicereview-698-13.html',146 '53-1': '/toefl/read/practicereview-1334-13.html',147 '53-2': '/toefl/read/practicereview-1335-13.html',148 '53-3': '/toefl/read/practicereview-1336-13.html',149 '52-1': '/toefl/read/practicereview-1312-13.html',150 '52-2': '/toefl/read/practicereview-1313-13.html',151 '52-3': '/toefl/read/practicereview-1314-13.html',152 '51-1': '/toefl/read/practicereview-1295-13.html',153 '51-2': '/toefl/read/practicereview-1296-13.html',154 '51-3': '/toefl/read/practicereview-1297-13.html',155 '50-1': '/toefl/read/practicereview-1278-13.html',156 '50-2': '/toefl/read/practicereview-1279-13.html',157 '50-3': '/toefl/read/practicereview-1280-13.html',158 '49-1': '/toefl/read/practicereview-900-13.html',159 '49-2': '/toefl/read/practicereview-901-13.html',160 '49-3': '/toefl/read/practicereview-902-13.html'161}162xiaozhan_reading_cihui = {163 # '4-1': '/cihui/toefl/reading-52.html',164 # '4-2': '/cihui/toefl/reading-53.html',165 # '4-3': '/cihui/toefl/reading-54.html',166 # '3-1': '/cihui/toefl/reading-35.html',167 # '3-2': '/cihui/toefl/reading-36.html',168 # '3-3': '/cihui/toefl/reading-37.html',169 # '2-1': '/cihui/toefl/reading-18.html',170 # '2-2': '/cihui/toefl/reading-19.html',171 # '2-3': '/cihui/toefl/reading-20.html',172 # '1-1': '/cihui/toefl/reading-1.html',173 # '1-2': '/cihui/toefl/reading-2.html',174 # '1-3': '/cihui/toefl/reading-3.html',175 # '8-1': '/cihui/toefl/reading-120.html',176 # '8-2': '/cihui/toefl/reading-121.html',177 # '8-3': '/cihui/toefl/reading-122.html',178 # '7-1': '/cihui/toefl/reading-103.html',179 # '7-2': '/cihui/toefl/reading-104.html',180 # '7-3': '/cihui/toefl/reading-105.html',181 # '6-1': '/cihui/toefl/reading-86.html',182 # '6-2': '/cihui/toefl/reading-87.html',183 # '6-3': '/cihui/toefl/reading-88.html',184 # '5-1': '/cihui/toefl/reading-69.html',185 # '5-2': '/cihui/toefl/reading-70.html',186 # '5-3': '/cihui/toefl/reading-71.html',187 # '12-1': '/cihui/toefl/reading-188.html',188 '12-2': '/cihui/toefl/reading-189.html',189 '12-3': '/cihui/toefl/reading-190.html',190 '11-1': '/cihui/toefl/reading-171.html',191 '11-2': '/cihui/toefl/reading-172.html',192 '11-3': '/cihui/toefl/reading-173.html',193 '10-1': '/cihui/toefl/reading-154.html',194 '10-2': '/cihui/toefl/reading-155.html',195 '10-3': '/cihui/toefl/reading-156.html',196 '9-1': '/cihui/toefl/reading-137.html',197 '9-2': '/cihui/toefl/reading-138.html',198 '9-3': '/cihui/toefl/reading-139.html',199 '16-1': '/cihui/toefl/reading-256.html',200 '16-2': '/cihui/toefl/reading-257.html',201 '16-3': '/cihui/toefl/reading-258.html',202 '15-1': '/cihui/toefl/reading-239.html',203 '15-2': '/cihui/toefl/reading-240.html',204 '15-3': '/cihui/toefl/reading-241.html',205 '14-1': '/cihui/toefl/reading-222.html',206 '14-2': '/cihui/toefl/reading-223.html',207 '14-3': '/cihui/toefl/reading-224.html',208 '13-1': '/cihui/toefl/reading-205.html',209 '13-2': '/cihui/toefl/reading-206.html',210 '13-3': '/cihui/toefl/reading-207.html',211 '20-1': '/cihui/toefl/reading-324.html',212 '20-2': '/cihui/toefl/reading-325.html',213 '20-3': '/cihui/toefl/reading-326.html',214 '19-1': '/cihui/toefl/reading-307.html',215 '19-2': '/cihui/toefl/reading-308.html',216 '19-3': '/cihui/toefl/reading-309.html',217 '18-1': '/cihui/toefl/reading-290.html',218 '18-2': '/cihui/toefl/reading-291.html',219 '18-3': '/cihui/toefl/reading-292.html',220 '17-1': '/cihui/toefl/reading-273.html',221 '17-2': '/cihui/toefl/reading-274.html',222 '17-3': '/cihui/toefl/reading-275.html',223 '24-1': '/cihui/toefl/reading-392.html',224 '24-2': '/cihui/toefl/reading-393.html',225 '24-3': '/cihui/toefl/reading-394.html',226 '23-1': '/cihui/toefl/reading-375.html',227 '23-2': '/cihui/toefl/reading-376.html',228 '23-3': '/cihui/toefl/reading-377.html',229 '22-1': '/cihui/toefl/reading-358.html',230 '22-2': '/cihui/toefl/reading-359.html',231 '22-3': '/cihui/toefl/reading-360.html',232 '21-1': '/cihui/toefl/reading-341.html',233 '21-2': '/cihui/toefl/reading-342.html',234 '21-3': '/cihui/toefl/reading-343.html',235 '28-1': '/cihui/toefl/reading-460.html',236 '28-2': '/cihui/toefl/reading-461.html',237 '28-3': '/cihui/toefl/reading-462.html',238 '27-1': '/cihui/toefl/reading-443.html',239 '27-2': '/cihui/toefl/reading-444.html',240 '27-3': '/cihui/toefl/reading-445.html',241 '26-1': '/cihui/toefl/reading-426.html',242 '26-2': '/cihui/toefl/reading-427.html',243 '26-3': '/cihui/toefl/reading-428.html',244 '25-1': '/cihui/toefl/reading-409.html',245 '25-2': '/cihui/toefl/reading-410.html',246 '25-3': '/cihui/toefl/reading-411.html',247 '32-1': '/cihui/toefl/reading-528.html',248 '32-2': '/cihui/toefl/reading-529.html',249 '32-3': '/cihui/toefl/reading-530.html',250 '31-1': '/cihui/toefl/reading-511.html',251 '31-2': '/cihui/toefl/reading-512.html',252 '31-3': '/cihui/toefl/reading-513.html',253 '30-1': '/cihui/toefl/reading-494.html',254 '30-2': '/cihui/toefl/reading-495.html',255 '30-3': '/cihui/toefl/reading-496.html',256 '29-1': '/cihui/toefl/reading-477.html',257 '29-2': '/cihui/toefl/reading-478.html',258 '29-3': '/cihui/toefl/reading-479.html',259 '36-1': '/cihui/toefl/reading-951.html',260 '36-2': '/cihui/toefl/reading-952.html',261 '36-3': '/cihui/toefl/reading-953.html',262 '35-1': '/cihui/toefl/reading-917.html',263 '35-2': '/cihui/toefl/reading-918.html',264 '35-3': '/cihui/toefl/reading-919.html',265 '34-1': '/cihui/toefl/reading-562.html',266 '34-2': '/cihui/toefl/reading-563.html',267 '34-3': '/cihui/toefl/reading-564.html',268 '33-1': '/cihui/toefl/reading-545.html',269 '33-2': '/cihui/toefl/reading-546.html',270 '33-3': '/cihui/toefl/reading-547.html',271 '40-1': '/cihui/toefl/reading-611.html',272 '40-2': '/cihui/toefl/reading-612.html',273 '40-3': '/cihui/toefl/reading-613.html',274 '39-1': '/cihui/toefl/reading-934.html',275 '39-2': '/cihui/toefl/reading-935.html',276 '39-3': '/cihui/toefl/reading-936.html',277 '38-1': '/cihui/toefl/reading-968.html',278 '38-2': '/cihui/toefl/reading-969.html',279 '38-3': '/cihui/toefl/reading-970.html',280 '37-1': '/cihui/toefl/reading-985.html',281 '37-2': '/cihui/toefl/reading-986.html',282 '37-3': '/cihui/toefl/reading-987.html',283 '44-1': '/cihui/toefl/reading-679.html',284 '44-2': '/cihui/toefl/reading-680.html',285 '44-3': '/cihui/toefl/reading-681.html',286 '43-1': '/cihui/toefl/reading-662.html',287 '43-2': '/cihui/toefl/reading-663.html',288 '43-3': '/cihui/toefl/reading-664.html',289 '42-1': '/cihui/toefl/reading-645.html',290 '42-2': '/cihui/toefl/reading-646.html',291 '42-3': '/cihui/toefl/reading-647.html',292 '41-1': '/cihui/toefl/reading-628.html',293 '41-2': '/cihui/toefl/reading-629.html',294 '41-3': '/cihui/toefl/reading-630.html',295 '48-1': '/cihui/toefl/reading-747.html',296 '48-2': '/cihui/toefl/reading-748.html',297 '48-3': '/cihui/toefl/reading-749.html',298 '47-1': '/cihui/toefl/reading-730.html',299 '47-2': '/cihui/toefl/reading-731.html',300 '47-3': '/cihui/toefl/reading-732.html',301 '46-1': '/cihui/toefl/reading-713.html',302 '46-2': '/cihui/toefl/reading-714.html',303 '46-3': '/cihui/toefl/reading-715.html',304 '45-1': '/cihui/toefl/reading-696.html',305 '45-2': '/cihui/toefl/reading-697.html',306 '45-3': '/cihui/toefl/reading-698.html',307 '53-1': '/cihui/toefl/reading-1334.html',308 '53-2': '/cihui/toefl/reading-1335.html',309 '53-3': '/cihui/toefl/reading-1336.html',310 '52-1': '/cihui/toefl/reading-1312.html',311 '52-2': '/cihui/toefl/reading-1313.html',312 '52-3': '/cihui/toefl/reading-1314.html',313 '51-1': '/cihui/toefl/reading-1295.html',314 '51-2': '/cihui/toefl/reading-1296.html',315 '51-3': '/cihui/toefl/reading-1297.html',316 '50-1': '/cihui/toefl/reading-1278.html',317 '50-2': '/cihui/toefl/reading-1279.html',318 '50-3': '/cihui/toefl/reading-1280.html',319 '49-1': '/cihui/toefl/reading-900.html',320 '49-2': '/cihui/toefl/reading-901.html',321 '49-3': '/cihui/toefl/reading-902.html'322}323xiaozhan_listen_review = {324 '4-1': '/toefl/listen/review-55-13.html',325 '4-2': '/toefl/listen/review-56-13.html',326 '4-3': '/toefl/listen/review-57-13.html',327 '4-4': '/toefl/listen/review-58-13.html',328 '4-5': '/toefl/listen/review-59-13.html',329 '4-6': '/toefl/listen/review-60-13.html',330 '3-1': '/toefl/listen/review-38-13.html',331 '3-2': '/toefl/listen/review-39-13.html',332 '3-3': '/toefl/listen/review-40-13.html',333 '3-4': '/toefl/listen/review-41-13.html',334 '3-5': '/toefl/listen/review-42-13.html',335 '3-6': '/toefl/listen/review-43-13.html',336 '2-1': '/toefl/listen/review-21-13.html',337 '2-2': '/toefl/listen/review-22-13.html',338 '2-3': '/toefl/listen/review-23-13.html',339 '2-4': '/toefl/listen/review-24-13.html',340 '2-5': '/toefl/listen/review-25-13.html',341 '2-6': '/toefl/listen/review-26-13.html',342 '1-1': '/toefl/listen/review-4-13.html',343 '1-2': '/toefl/listen/review-5-13.html',344 '1-3': '/toefl/listen/review-6-13.html',345 '1-4': '/toefl/listen/review-7-13.html',346 '1-5': '/toefl/listen/review-8-13.html',347 '1-6': '/toefl/listen/review-9-13.html',348 '8-1': '/toefl/listen/review-123-13.html',349 '8-2': '/toefl/listen/review-124-13.html',350 '8-3': '/toefl/listen/review-125-13.html',351 '8-4': '/toefl/listen/review-126-13.html',352 '8-5': '/toefl/listen/review-127-13.html',353 '8-6': '/toefl/listen/review-128-13.html',354 '7-1': '/toefl/listen/review-106-13.html',355 '7-2': '/toefl/listen/review-107-13.html',356 '7-3': '/toefl/listen/review-108-13.html',357 '7-4': '/toefl/listen/review-109-13.html',358 '7-5': '/toefl/listen/review-110-13.html',359 '7-6': '/toefl/listen/review-111-13.html',360 '6-1': '/toefl/listen/review-89-13.html',361 '6-2': '/toefl/listen/review-90-13.html',362 '6-3': '/toefl/listen/review-91-13.html',363 '6-4': '/toefl/listen/review-92-13.html',364 '6-5': '/toefl/listen/review-93-13.html',365 '6-6': '/toefl/listen/review-94-13.html',366 '5-1': '/toefl/listen/review-72-13.html',367 '5-2': '/toefl/listen/review-73-13.html',368 '5-3': '/toefl/listen/review-74-13.html',369 '5-4': '/toefl/listen/review-75-13.html',370 '5-5': '/toefl/listen/review-76-13.html',371 '5-6': '/toefl/listen/review-77-13.html',372 '12-1': '/toefl/listen/review-191-13.html',373 '12-2': '/toefl/listen/review-192-13.html',374 '12-3': '/toefl/listen/review-193-13.html',375 '12-4': '/toefl/listen/review-194-13.html',376 '12-5': '/toefl/listen/review-195-13.html',377 '12-6': '/toefl/listen/review-196-13.html',378 '11-1': '/toefl/listen/review-174-13.html',379 '11-2': '/toefl/listen/review-175-13.html',380 '11-3': '/toefl/listen/review-176-13.html',381 '11-4': '/toefl/listen/review-177-13.html',382 '11-5': '/toefl/listen/review-178-13.html',383 '11-6': '/toefl/listen/review-179-13.html',384 '10-1': '/toefl/listen/review-157-13.html',385 '10-2': '/toefl/listen/review-158-13.html',386 '10-3': '/toefl/listen/review-159-13.html',387 '10-4': '/toefl/listen/review-160-13.html',388 '10-5': '/toefl/listen/review-161-13.html',389 '10-6': '/toefl/listen/review-162-13.html',390 '9-1': '/toefl/listen/review-140-13.html',391 '9-2': '/toefl/listen/review-141-13.html',392 '9-3': '/toefl/listen/review-142-13.html',393 '9-4': '/toefl/listen/review-143-13.html',394 '9-5': '/toefl/listen/review-144-13.html',395 '9-6': '/toefl/listen/review-145-13.html',396 '16-1': '/toefl/listen/review-259-13.html',397 '16-2': '/toefl/listen/review-260-13.html',398 '16-3': '/toefl/listen/review-261-13.html',399 '16-4': '/toefl/listen/review-262-13.html',400 '16-5': '/toefl/listen/review-263-13.html',401 '16-6': '/toefl/listen/review-264-13.html',402 '15-1': '/toefl/listen/review-242-13.html',403 '15-2': '/toefl/listen/review-243-13.html',404 '15-3': '/toefl/listen/review-244-13.html',405 '15-4': '/toefl/listen/review-245-13.html',406 '15-5': '/toefl/listen/review-246-13.html',407 '15-6': '/toefl/listen/review-247-13.html',408 '14-1': '/toefl/listen/review-225-13.html',409 '14-2': '/toefl/listen/review-226-13.html',410 '14-3': '/toefl/listen/review-227-13.html',411 '14-4': '/toefl/listen/review-228-13.html',412 '14-5': '/toefl/listen/review-229-13.html',413 '14-6': '/toefl/listen/review-230-13.html',414 '13-1': '/toefl/listen/review-208-13.html',415 '13-2': '/toefl/listen/review-209-13.html',416 '13-3': '/toefl/listen/review-210-13.html',417 '13-4': '/toefl/listen/review-211-13.html',418 '13-5': '/toefl/listen/review-212-13.html',419 '13-6': '/toefl/listen/review-213-13.html',420 '20-1': '/toefl/listen/review-327-13.html',421 '20-2': '/toefl/listen/review-328-13.html',422 '20-3': '/toefl/listen/review-329-13.html',423 '20-4': '/toefl/listen/review-330-13.html',424 '20-5': '/toefl/listen/review-331-13.html',425 '20-6': '/toefl/listen/review-332-13.html',426 '19-1': '/toefl/listen/review-310-13.html',427 '19-2': '/toefl/listen/review-311-13.html',428 '19-3': '/toefl/listen/review-312-13.html',429 '19-4': '/toefl/listen/review-313-13.html',430 '19-5': '/toefl/listen/review-314-13.html',431 '19-6': '/toefl/listen/review-315-13.html',432 '18-1': '/toefl/listen/review-293-13.html',433 '18-2': '/toefl/listen/review-294-13.html',434 '18-3': '/toefl/listen/review-295-13.html',435 '18-4': '/toefl/listen/review-296-13.html',436 '18-5': '/toefl/listen/review-297-13.html',437 '18-6': '/toefl/listen/review-298-13.html',438 '17-1': '/toefl/listen/review-276-13.html',439 '17-2': '/toefl/listen/review-277-13.html',440 '17-3': '/toefl/listen/review-278-13.html',441 '17-4': '/toefl/listen/review-279-13.html',442 '17-5': '/toefl/listen/review-280-13.html',443 '17-6': '/toefl/listen/review-281-13.html',444 '24-1': '/toefl/listen/review-395-13.html',445 '24-2': '/toefl/listen/review-396-13.html',446 '24-3': '/toefl/listen/review-397-13.html',447 '24-4': '/toefl/listen/review-398-13.html',448 '24-5': '/toefl/listen/review-399-13.html',449 '24-6': '/toefl/listen/review-400-13.html',450 '23-1': '/toefl/listen/review-378-13.html',451 '23-2': '/toefl/listen/review-379-13.html',452 '23-3': '/toefl/listen/review-380-13.html',453 '23-4': '/toefl/listen/review-381-13.html',454 '23-5': '/toefl/listen/review-382-13.html',455 '23-6': '/toefl/listen/review-383-13.html',456 '22-1': '/toefl/listen/review-361-13.html',457 '22-2': '/toefl/listen/review-362-13.html',458 '22-3': '/toefl/listen/review-363-13.html',459 '22-4': '/toefl/listen/review-364-13.html',460 '22-5': '/toefl/listen/review-365-13.html',461 '22-6': '/toefl/listen/review-366-13.html',462 '21-1': '/toefl/listen/review-344-13.html',463 '21-2': '/toefl/listen/review-345-13.html',464 '21-3': '/toefl/listen/review-346-13.html',465 '21-4': '/toefl/listen/review-347-13.html',466 '21-5': '/toefl/listen/review-348-13.html',467 '21-6': '/toefl/listen/review-349-13.html',468 '28-1': '/toefl/listen/review-463-13.html',469 '28-2': '/toefl/listen/review-464-13.html',470 '28-3': '/toefl/listen/review-465-13.html',471 '28-4': '/toefl/listen/review-466-13.html',472 '28-5': '/toefl/listen/review-467-13.html',473 '28-6': '/toefl/listen/review-468-13.html',474 '27-1': '/toefl/listen/review-446-13.html',475 '27-2': '/toefl/listen/review-447-13.html',476 '27-3': '/toefl/listen/review-448-13.html',477 '27-4': '/toefl/listen/review-449-13.html',478 '27-5': '/toefl/listen/review-450-13.html',479 '27-6': '/toefl/listen/review-451-13.html',480 '26-1': '/toefl/listen/review-429-13.html',481 '26-2': '/toefl/listen/review-430-13.html',482 '26-3': '/toefl/listen/review-431-13.html',483 '26-4': '/toefl/listen/review-432-13.html',484 '26-5': '/toefl/listen/review-433-13.html',485 '26-6': '/toefl/listen/review-434-13.html',486 '25-1': '/toefl/listen/review-412-13.html',487 '25-2': '/toefl/listen/review-413-13.html',488 '25-3': '/toefl/listen/review-414-13.html',489 '25-4': '/toefl/listen/review-415-13.html',490 '25-5': '/toefl/listen/review-416-13.html',491 '25-6': '/toefl/listen/review-417-13.html',492 '32-1': '/toefl/listen/review-531-13.html',493 '32-2': '/toefl/listen/review-532-13.html',494 '32-3': '/toefl/listen/review-533-13.html',495 '32-4': '/toefl/listen/review-534-13.html',496 '32-5': '/toefl/listen/review-535-13.html',497 '32-6': '/toefl/listen/review-536-13.html',498 '31-1': '/toefl/listen/review-514-13.html',499 '31-2': '/toefl/listen/review-515-13.html',500 '31-3': '/toefl/listen/review-516-13.html',501 '31-4': '/toefl/listen/review-517-13.html',502 '31-5': '/toefl/listen/review-518-13.html',503 '31-6': '/toefl/listen/review-519-13.html',504 '30-1': '/toefl/listen/review-497-13.html',505 '30-2': '/toefl/listen/review-498-13.html',506 '30-3': '/toefl/listen/review-499-13.html',507 '30-4': '/toefl/listen/review-500-13.html',508 '30-5': '/toefl/listen/review-501-13.html',509 '30-6': '/toefl/listen/review-502-13.html',510 '29-1': '/toefl/listen/review-480-13.html',511 '29-2': '/toefl/listen/review-481-13.html',512 '29-3': '/toefl/listen/review-482-13.html',513 '29-4': '/toefl/listen/review-483-13.html',514 '29-5': '/toefl/listen/review-484-13.html',515 '29-6': '/toefl/listen/review-485-13.html',516 '36-1': '/toefl/listen/review-954-13.html',517 '36-2': '/toefl/listen/review-955-13.html',518 '36-3': '/toefl/listen/review-956-13.html',519 '36-4': '/toefl/listen/review-957-13.html',520 '36-5': '/toefl/listen/review-958-13.html',521 '36-6': '/toefl/listen/review-959-13.html',522 '35-1': '/toefl/listen/review-920-13.html',523 '35-2': '/toefl/listen/review-921-13.html',524 '35-3': '/toefl/listen/review-922-13.html',525 '35-4': '/toefl/listen/review-923-13.html',526 '35-5': '/toefl/listen/review-924-13.html',527 '35-6': '/toefl/listen/review-925-13.html',528 '34-1': '/toefl/listen/review-565-13.html',529 '34-2': '/toefl/listen/review-566-13.html',530 '34-3': '/toefl/listen/review-567-13.html',531 '34-4': '/toefl/listen/review-568-13.html',532 '34-5': '/toefl/listen/review-569-13.html',533 '34-6': '/toefl/listen/review-570-13.html',534 '33-1': '/toefl/listen/review-548-13.html',535 '33-2': '/toefl/listen/review-549-13.html',536 '33-3': '/toefl/listen/review-550-13.html',537 '33-4': '/toefl/listen/review-551-13.html',538 '33-5': '/toefl/listen/review-552-13.html',539 '33-6': '/toefl/listen/review-553-13.html',540 '40-1': '/toefl/listen/review-614-13.html',541 '40-2': '/toefl/listen/review-615-13.html',542 '40-3': '/toefl/listen/review-616-13.html',543 '40-4': '/toefl/listen/review-617-13.html',544 '40-5': '/toefl/listen/review-618-13.html',545 '40-6': '/toefl/listen/review-619-13.html',546 '39-1': '/toefl/listen/review-937-13.html',547 '39-2': '/toefl/listen/review-938-13.html',548 '39-3': '/toefl/listen/review-939-13.html',549 '39-4': '/toefl/listen/review-940-13.html',550 '39-5': '/toefl/listen/review-941-13.html',551 '39-6': '/toefl/listen/review-942-13.html',552 '38-1': '/toefl/listen/review-971-13.html',553 '38-2': '/toefl/listen/review-972-13.html',554 '38-3': '/toefl/listen/review-973-13.html',555 '38-4': '/toefl/listen/review-974-13.html',556 '38-5': '/toefl/listen/review-975-13.html',557 '38-6': '/toefl/listen/review-976-13.html',558 '37-1': '/toefl/listen/review-988-13.html',559 '37-2': '/toefl/listen/review-989-13.html',560 '37-3': '/toefl/listen/review-990-13.html',561 '37-4': '/toefl/listen/review-991-13.html',562 '37-5': '/toefl/listen/review-992-13.html',563 '37-6': '/toefl/listen/review-993-13.html',564 '44-1': '/toefl/listen/review-682-13.html',565 '44-2': '/toefl/listen/review-683-13.html',566 '44-3': '/toefl/listen/review-684-13.html',567 '44-4': '/toefl/listen/review-685-13.html',568 '44-5': '/toefl/listen/review-686-13.html',569 '44-6': '/toefl/listen/review-687-13.html',570 '43-1': '/toefl/listen/review-665-13.html',571 '43-2': '/toefl/listen/review-666-13.html',572 '43-3': '/toefl/listen/review-667-13.html',573 '43-4': '/toefl/listen/review-668-13.html',574 '43-5': '/toefl/listen/review-669-13.html',575 '43-6': '/toefl/listen/review-670-13.html',576 '42-1': '/toefl/listen/review-648-13.html',577 '42-2': '/toefl/listen/review-649-13.html',578 '42-3': '/toefl/listen/review-650-13.html',579 '42-4': '/toefl/listen/review-651-13.html',580 '42-5': '/toefl/listen/review-652-13.html',581 '42-6': '/toefl/listen/review-653-13.html',582 '41-1': '/toefl/listen/review-631-13.html',583 '41-2': '/toefl/listen/review-632-13.html',584 '41-3': '/toefl/listen/review-633-13.html',585 '41-4': '/toefl/listen/review-634-13.html',586 '41-5': '/toefl/listen/review-635-13.html',587 '41-6': '/toefl/listen/review-636-13.html',588 '48-1': '/toefl/listen/review-750-13.html',589 '48-2': '/toefl/listen/review-751-13.html',590 '48-3': '/toefl/listen/review-752-13.html',591 '48-4': '/toefl/listen/review-753-13.html',592 '48-5': '/toefl/listen/review-754-13.html',593 '48-6': '/toefl/listen/review-755-13.html',594 '47-1': '/toefl/listen/review-733-13.html',595 '47-2': '/toefl/listen/review-734-13.html',596 '47-3': '/toefl/listen/review-735-13.html',597 '47-4': '/toefl/listen/review-736-13.html',598 '47-5': '/toefl/listen/review-737-13.html',599 '47-6': '/toefl/listen/review-738-13.html',600 '46-1': '/toefl/listen/review-716-13.html',601 '46-2': '/toefl/listen/review-717-13.html',602 '46-3': '/toefl/listen/review-718-13.html',603 '46-4': '/toefl/listen/review-719-13.html',604 '46-5': '/toefl/listen/review-720-13.html',605 '46-6': '/toefl/listen/review-721-13.html',606 '45-1': '/toefl/listen/review-699-13.html',607 '45-2': '/toefl/listen/review-700-13.html',608 '45-3': '/toefl/listen/review-701-13.html',609 '45-4': '/toefl/listen/review-702-13.html',610 '45-5': '/toefl/listen/review-703-13.html',611 '45-6': '/toefl/listen/review-704-13.html',612 '53-1': '/toefl/listen/review-1347-13.html',613 '53-2': '/toefl/listen/review-1348-13.html',614 '53-3': '/toefl/listen/review-1350-13.html',615 '53-4': '/toefl/listen/review-1351-13.html',616 '53-5': '/toefl/listen/review-1352-13.html',617 '53-6': '/toefl/listen/review-1353-13.html',618 '52-1': '/toefl/listen/review-1315-13.html',619 '52-2': '/toefl/listen/review-1316-13.html',620 '52-3': '/toefl/listen/review-1317-13.html',621 '52-4': '/toefl/listen/review-1318-13.html',622 '52-5': '/toefl/listen/review-1319-13.html',623 '52-6': '/toefl/listen/review-1320-13.html',624 '51-1': '/toefl/listen/review-1298-13.html',625 '51-2': '/toefl/listen/review-1299-13.html',626 '51-3': '/toefl/listen/review-1300-13.html',627 '51-4': '/toefl/listen/review-1301-13.html',628 '51-5': '/toefl/listen/review-1302-13.html',629 '51-6': '/toefl/listen/review-1303-13.html',630 '50-1': '/toefl/listen/review-1281-13.html',631 '50-2': '/toefl/listen/review-1282-13.html',632 '50-3': '/toefl/listen/review-1283-13.html',633 '50-4': '/toefl/listen/review-1284-13.html',634 '50-5': '/toefl/listen/review-1285-13.html',635 '50-6': '/toefl/listen/review-1286-13.html',636 '49-1': '/toefl/listen/review-903-13.html',637 '49-2': '/toefl/listen/review-904-13.html',638 '49-3': '/toefl/listen/review-905-13.html',639 '49-4': '/toefl/listen/review-906-13.html',640 '49-5': '/toefl/listen/review-907-13.html',641 '49-6': '/toefl/listen/review-908-13.html'642}643if __name__ == '__main__':...
test_init.py
Source:test_init.py
1"""Test qwikswitch sensors."""2import asyncio3from unittest.mock import Mock4from aiohttp.client_exceptions import ClientError5import pytest6from yarl import URL7from homeassistant.components.qwikswitch import DOMAIN as QWIKSWITCH8from homeassistant.setup import async_setup_component9from tests.test_util.aiohttp import AiohttpClientMockResponse, MockLongPollSideEffect10@pytest.fixture11def qs_devices():12 """Return a set of devices as a response."""13 return [14 {15 "id": "@a00001",16 "name": "Switch 1",17 "type": "rel",18 "val": "OFF",19 "time": "1522777506",20 "rssi": "51%",21 },22 {23 "id": "@a00002",24 "name": "Light 2",25 "type": "rel",26 "val": "ON",27 "time": "1522777507",28 "rssi": "45%",29 },30 {31 "id": "@a00003",32 "name": "Dim 3",33 "type": "dim",34 "val": "280c00",35 "time": "1522777544",36 "rssi": "62%",37 },38 ]39EMPTY_PACKET = {"cmd": ""}40async def test_binary_sensor_device(hass, aioclient_mock, qs_devices):41 """Test a binary sensor device."""42 config = {43 "qwikswitch": {44 "sensors": {"name": "s1", "id": "@a00001", "channel": 1, "type": "imod"}45 }46 }47 aioclient_mock.get("http://127.0.0.1:2020/&device", json=qs_devices)48 listen_mock = MockLongPollSideEffect()49 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)50 assert await async_setup_component(hass, QWIKSWITCH, config)51 await hass.async_start()52 await hass.async_block_till_done()53 # verify initial state is off per the 'val' in qs_devices54 state_obj = hass.states.get("binary_sensor.s1")55 assert state_obj.state == "off"56 # receive turn on command from network57 listen_mock.queue_response(58 json={"id": "@a00001", "cmd": "STATUS.ACK", "data": "4e0e1601", "rssi": "61%"}59 )60 await asyncio.sleep(0.01)61 await hass.async_block_till_done()62 state_obj = hass.states.get("binary_sensor.s1")63 assert state_obj.state == "on"64 # receive turn off command from network65 listen_mock.queue_response(66 json={"id": "@a00001", "cmd": "STATUS.ACK", "data": "4e0e1701", "rssi": "61%"},67 )68 await asyncio.sleep(0.01)69 await hass.async_block_till_done()70 state_obj = hass.states.get("binary_sensor.s1")71 assert state_obj.state == "off"72 listen_mock.stop()73async def test_sensor_device(hass, aioclient_mock, qs_devices):74 """Test a sensor device."""75 config = {76 "qwikswitch": {77 "sensors": {78 "name": "ss1",79 "id": "@a00001",80 "channel": 1,81 "type": "qwikcord",82 }83 }84 }85 aioclient_mock.get("http://127.0.0.1:2020/&device", json=qs_devices)86 listen_mock = MockLongPollSideEffect()87 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)88 assert await async_setup_component(hass, QWIKSWITCH, config)89 await hass.async_start()90 await hass.async_block_till_done()91 state_obj = hass.states.get("sensor.ss1")92 assert state_obj.state == "None"93 # receive command that sets the sensor value94 listen_mock.queue_response(95 json={"id": "@a00001", "name": "ss1", "type": "rel", "val": "4733800001a00000"},96 )97 await asyncio.sleep(0.01)98 await hass.async_block_till_done()99 state_obj = hass.states.get("sensor.ss1")100 assert state_obj.state == "416"101 listen_mock.stop()102async def test_switch_device(hass, aioclient_mock, qs_devices):103 """Test a switch device."""104 async def get_devices_json(method, url, data):105 return AiohttpClientMockResponse(method=method, url=url, json=qs_devices)106 config = {"qwikswitch": {"switches": ["@a00001"]}}107 aioclient_mock.get("http://127.0.0.1:2020/&device", side_effect=get_devices_json)108 listen_mock = MockLongPollSideEffect()109 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)110 assert await async_setup_component(hass, QWIKSWITCH, config)111 await hass.async_start()112 await hass.async_block_till_done()113 # verify initial state is off per the 'val' in qs_devices114 state_obj = hass.states.get("switch.switch_1")115 assert state_obj.state == "off"116 # ask hass to turn on and verify command is sent to device117 aioclient_mock.mock_calls.clear()118 aioclient_mock.get("http://127.0.0.1:2020/@a00001=100", json={"data": "OK"})119 await hass.services.async_call(120 "switch", "turn_on", {"entity_id": "switch.switch_1"}, blocking=True121 )122 await asyncio.sleep(0.01)123 assert (124 "GET",125 URL("http://127.0.0.1:2020/@a00001=100"),126 None,127 None,128 ) in aioclient_mock.mock_calls129 # verify state is on130 state_obj = hass.states.get("switch.switch_1")131 assert state_obj.state == "on"132 # ask hass to turn off and verify command is sent to device133 aioclient_mock.mock_calls.clear()134 aioclient_mock.get("http://127.0.0.1:2020/@a00001=0", json={"data": "OK"})135 await hass.services.async_call(136 "switch", "turn_off", {"entity_id": "switch.switch_1"}, blocking=True137 )138 assert (139 "GET",140 URL("http://127.0.0.1:2020/@a00001=0"),141 None,142 None,143 ) in aioclient_mock.mock_calls144 # verify state is off145 state_obj = hass.states.get("switch.switch_1")146 assert state_obj.state == "off"147 # check if setting the value in the network show in hass148 qs_devices[0]["val"] = "ON"149 listen_mock.queue_response(json=EMPTY_PACKET)150 await hass.async_block_till_done()151 state_obj = hass.states.get("switch.switch_1")152 assert state_obj.state == "on"153 listen_mock.stop()154async def test_light_device(hass, aioclient_mock, qs_devices):155 """Test a light device."""156 async def get_devices_json(method, url, data):157 return AiohttpClientMockResponse(method=method, url=url, json=qs_devices)158 config = {"qwikswitch": {}}159 aioclient_mock.get("http://127.0.0.1:2020/&device", side_effect=get_devices_json)160 listen_mock = MockLongPollSideEffect()161 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)162 assert await async_setup_component(hass, QWIKSWITCH, config)163 await hass.async_start()164 await hass.async_block_till_done()165 # verify initial state is on per the 'val' in qs_devices166 state_obj = hass.states.get("light.dim_3")167 assert state_obj.state == "on"168 assert state_obj.attributes["brightness"] == 255169 # ask hass to turn off and verify command is sent to device170 aioclient_mock.mock_calls.clear()171 aioclient_mock.get("http://127.0.0.1:2020/@a00003=0", json={"data": "OK"})172 await hass.services.async_call(173 "light", "turn_off", {"entity_id": "light.dim_3"}, blocking=True174 )175 await asyncio.sleep(0.01)176 assert (177 "GET",178 URL("http://127.0.0.1:2020/@a00003=0"),179 None,180 None,181 ) in aioclient_mock.mock_calls182 state_obj = hass.states.get("light.dim_3")183 assert state_obj.state == "off"184 # change brightness in network and check that hass updates185 qs_devices[2]["val"] = "280c55" # half dimmed186 listen_mock.queue_response(json=EMPTY_PACKET)187 await asyncio.sleep(0.01)188 await hass.async_block_till_done()189 state_obj = hass.states.get("light.dim_3")190 assert state_obj.state == "on"191 assert 16 < state_obj.attributes["brightness"] < 240192 # turn off in the network and see that it is off in hass as well193 qs_devices[2]["val"] = "280c78" # off194 listen_mock.queue_response(json=EMPTY_PACKET)195 await asyncio.sleep(0.01)196 await hass.async_block_till_done()197 state_obj = hass.states.get("light.dim_3")198 assert state_obj.state == "off"199 # ask hass to turn on and verify command is sent to device200 aioclient_mock.mock_calls.clear()201 aioclient_mock.get("http://127.0.0.1:2020/@a00003=100", json={"data": "OK"})202 await hass.services.async_call(203 "light", "turn_on", {"entity_id": "light.dim_3"}, blocking=True204 )205 assert (206 "GET",207 URL("http://127.0.0.1:2020/@a00003=100"),208 None,209 None,210 ) in aioclient_mock.mock_calls211 await hass.async_block_till_done()212 state_obj = hass.states.get("light.dim_3")213 assert state_obj.state == "on"214 listen_mock.stop()215async def test_button(hass, aioclient_mock, qs_devices):216 """Test that buttons fire an event."""217 async def get_devices_json(method, url, data):218 return AiohttpClientMockResponse(method=method, url=url, json=qs_devices)219 config = {"qwikswitch": {"button_events": "TOGGLE"}}220 aioclient_mock.get("http://127.0.0.1:2020/&device", side_effect=get_devices_json)221 listen_mock = MockLongPollSideEffect()222 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)223 assert await async_setup_component(hass, QWIKSWITCH, config)224 await hass.async_start()225 await hass.async_block_till_done()226 button_pressed = Mock()227 hass.bus.async_listen_once("qwikswitch.button.@a00002", button_pressed)228 listen_mock.queue_response(229 json={"id": "@a00002", "cmd": "TOGGLE"},230 )231 await asyncio.sleep(0.01)232 await hass.async_block_till_done()233 button_pressed.assert_called_once()234 listen_mock.stop()235async def test_failed_update_devices(hass, aioclient_mock):236 """Test that code behaves correctly when unable to get the devices."""237 config = {"qwikswitch": {}}238 aioclient_mock.get("http://127.0.0.1:2020/&device", exc=ClientError())239 listen_mock = MockLongPollSideEffect()240 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)241 assert not await async_setup_component(hass, QWIKSWITCH, config)242 await hass.async_start()243 await hass.async_block_till_done()244 listen_mock.stop()245async def test_single_invalid_sensor(hass, aioclient_mock, qs_devices):246 """Test that a single misconfigured sensor doesn't block the others."""247 config = {248 "qwikswitch": {249 "sensors": [250 {"name": "ss1", "id": "@a00001", "channel": 1, "type": "qwikcord"},251 {"name": "ss2", "id": "@a00002", "channel": 1, "type": "ERROR_TYPE"},252 {"name": "ss3", "id": "@a00003", "channel": 1, "type": "qwikcord"},253 ]254 }255 }256 aioclient_mock.get("http://127.0.0.1:2020/&device", json=qs_devices)257 listen_mock = MockLongPollSideEffect()258 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)259 assert await async_setup_component(hass, QWIKSWITCH, config)260 await hass.async_start()261 await hass.async_block_till_done()262 await asyncio.sleep(0.01)263 assert hass.states.get("sensor.ss1")264 assert not hass.states.get("sensor.ss2")265 assert hass.states.get("sensor.ss3")266 listen_mock.stop()267async def test_non_binary_sensor_with_binary_args(268 hass, aioclient_mock, qs_devices, caplog269):270 """Test that the system logs a warning when a non-binary device has binary specific args."""271 config = {272 "qwikswitch": {273 "sensors": [274 {275 "name": "ss1",276 "id": "@a00001",277 "channel": 1,278 "type": "qwikcord",279 "invert": True,280 },281 ]282 }283 }284 aioclient_mock.get("http://127.0.0.1:2020/&device", json=qs_devices)285 listen_mock = MockLongPollSideEffect()286 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)287 assert await async_setup_component(hass, QWIKSWITCH, config)288 await hass.async_start()289 await hass.async_block_till_done()290 await asyncio.sleep(0.01)291 await hass.async_block_till_done()292 assert hass.states.get("sensor.ss1")293 assert "invert should only be used for binary_sensors" in caplog.text294 listen_mock.stop()295async def test_non_relay_switch(hass, aioclient_mock, qs_devices, caplog):296 """Test that the system logs a warning when a switch is configured for a device that is not a relay."""297 config = {"qwikswitch": {"switches": ["@a00003"]}}298 aioclient_mock.get("http://127.0.0.1:2020/&device", json=qs_devices)299 listen_mock = MockLongPollSideEffect()300 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)301 assert await async_setup_component(hass, QWIKSWITCH, config)302 await hass.async_start()303 await hass.async_block_till_done()304 await asyncio.sleep(0.01)305 await hass.async_block_till_done()306 assert not hass.states.get("switch.dim_3")307 assert "You specified a switch that is not a relay @a00003" in caplog.text308 listen_mock.stop()309async def test_unknown_device(hass, aioclient_mock, qs_devices, caplog):310 """Test that the system logs a warning when a network device has unknown type."""311 config = {"qwikswitch": {}}312 qs_devices[1]["type"] = "ERROR_TYPE"313 aioclient_mock.get("http://127.0.0.1:2020/&device", json=qs_devices)314 listen_mock = MockLongPollSideEffect()315 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)316 assert await async_setup_component(hass, QWIKSWITCH, config)317 await hass.async_start()318 await hass.async_block_till_done()319 await asyncio.sleep(0.01)320 await hass.async_block_till_done()321 assert hass.states.get("light.switch_1")322 assert not hass.states.get("light.light_2")323 assert hass.states.get("light.dim_3")324 assert "Ignored unknown QSUSB device" in caplog.text325 listen_mock.stop()326async def test_no_discover_info(hass, hass_storage, aioclient_mock, caplog):327 """Test that discovery with no discovery_info does not result in errors."""328 config = {329 "qwikswitch": {},330 "light": {"platform": "qwikswitch"},331 "switch": {"platform": "qwikswitch"},332 "sensor": {"platform": "qwikswitch"},333 "binary_sensor": {"platform": "qwikswitch"},334 }335 aioclient_mock.get(336 "http://127.0.0.1:2020/&device",337 json=[338 {339 "id": "@a00001",340 "name": "Switch 1",341 "type": "ERROR_TYPE",342 "val": "OFF",343 "time": "1522777506",344 "rssi": "51%",345 },346 ],347 )348 listen_mock = MockLongPollSideEffect()349 aioclient_mock.get("http://127.0.0.1:2020/&listen", side_effect=listen_mock)350 assert await async_setup_component(hass, "light", config)351 assert await async_setup_component(hass, "switch", config)352 assert await async_setup_component(hass, "sensor", config)353 assert await async_setup_component(hass, "binary_sensor", config)354 await hass.async_start()355 await hass.async_block_till_done()356 assert "Error while setting up qwikswitch platform" not in caplog.text...
snat_dynamic_info.py
Source:snat_dynamic_info.py
1import sys2import pdb3import os4from debug.common import init_neutron_client5from debug.common import discovery6PORT_ID_PREFEX = 107class SNATInfo:8 """9 Uses OpenStack SDK to retrieve all relevant information about a VM and the network it is on, for the SNAT Checker10 """11 def __init__(self, vm_name, neutron):12 self.neutron = neutron13 self.vm_name = discovery.vmname_parse(vm_name)14 self.source_port_dict = discovery.get_port_dict(self.vm_name, self.neutron)15 self.source_host_id = self.source_port_dict['binding:host_id']16 self.fixed_ip_address = self.source_port_dict['fixed_ips'][0]['ip_address']17 self.tenant_network_id = self.source_port_dict['network_id']18 self.sg_port = discovery.get_sg_port(self.tenant_network_id, self.neutron)19 self.router_id = self.sg_port['device_id']20 self.qr_port_id, self.dest_mac_address = discovery.get_qr_port(self.router_id, self.neutron)21 self.qg_port = discovery.get_qg_port(self.router_id, self.neutron)22 self.external_network_id = self.qg_port['network_id']23 self.snat_external_ip = self.qg_port['fixed_ips'][0]['ip_address']24 self.dest_ip_address = "8.8.8.8"25 self.vif_names = self.get_vif_list()26 self.ns_vif_names = self.get_ns_vif_list()27 self.snat_host_id = self.sg_port['binding:host_id']28 snat_host = self.determine_snat_host()29 if snat_host == "local snat":30 self.local_listen_dict = self.init_local_snat_process()31 self.remote_listen_dict = {}32 else:33 self.local_listen_dict, self.remote_listen_dict = self.init_remote_snat_process()34 self.inject_icmp_dict = self.format_inject_dict()35 def init_local_snat_process(self):36 local_listen_dict = dict()37 local_listen_dict['checker_type'] = "SNAT"38 local_listen_dict['packet_type'] = "ICMP"39 local_listen_dict['vm_name'] = self.vm_name40 local_listen_dict['src_ip_address'] = self.fixed_ip_address41 local_listen_dict['src_mac_address'] = self.source_port_dict['mac_address']42 local_listen_dict['dest_ip_address'] = self.dest_ip_address43 local_listen_dict['dest_mac_address'] = self.dest_mac_address44 local_listen_dict['host_id'] = self.source_host_id45 local_listen_dict['port_id'] = self.source_port_dict['id']46 local_listen_dict['network_label'] = discovery.get_network_label(self.external_network_id, self.neutron)47 local_listen_dict['network_type'] = discovery.get_network_type(self.external_network_id, self.neutron)48 local_listen_dict['nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % (self.snat_external_ip, self.dest_ip_address, self.dest_ip_address, self.snat_external_ip)49 local_listen_dict['bridge_name'] = discovery.get_bridge_name(local_listen_dict['network_label'], self.source_host_id, self.neutron)50 local_listen_dict['tag'] = "VM SOURCE"51 local_listen_dict['vif_names'] = self.vif_names52 local_listen_dict['ns_vif_names'] = self.ns_vif_names53 local_listen_dict['snat_host'] = "local"54 return local_listen_dict55 def init_remote_snat_process(self):56 local_listen_dict = dict()57 local_listen_dict['checker_type'] = "SNAT"58 local_listen_dict['packet_type'] = "ICMP"59 local_listen_dict['vm_name'] = self.vm_name60 local_listen_dict['src_ip_address'] = self.fixed_ip_address61 local_listen_dict['src_mac_address'] = self.source_port_dict['mac_address']62 local_listen_dict['dest_ip_address'] = self.dest_ip_address63 local_listen_dict['dest_mac_address'] = self.dest_mac_address64 local_listen_dict['host_id'] = self.source_host_id65 local_listen_dict['port_id'] = self.source_port_dict['id']66 local_listen_dict['network_label'] = discovery.get_network_label(self.tenant_network_id, self.neutron)67 local_listen_dict['network_type'] = discovery.get_network_type(self.tenant_network_id, self.neutron)68 local_listen_dict['nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % (self.fixed_ip_address, self.dest_ip_address, self.dest_ip_address, self.fixed_ip_address)69 local_listen_dict['snat_host'] = "remote"70 tunnel_ip = discovery.get_tunnel_ip(self.source_host_id, self.neutron)71 local_listen_dict['tunnel_ip'] = tunnel_ip72 local_listen_dict['vxlan_filter'] = "(src %s or dst %s) and udp port (4789)" % (local_listen_dict['tunnel_ip'], local_listen_dict['tunnel_ip'])73 if local_listen_dict['network_type'] == "vxlan":74 local_listen_dict['tunnel_port'] = discovery.get_tunnel_port(self.source_host_id, local_listen_dict['tunnel_ip'], self.neutron)75 else:76 local_listen_dict['tunnel_port'] = "None"77 local_listen_dict['bridge_name'] = discovery.get_bridge_name(local_listen_dict['network_label'], self.source_host_id, self.neutron)78 local_listen_dict['tag'] = "VM SOURCE"79 local_listen_dict['vif_names'] = self.vif_names80 local_listen_dict['ns_vif_names'] = []81 vif_buffer = self.ns_vif_names82 for vif in vif_buffer:83 for vif_name in list(vif.keys()):84 if "qr" in vif_name:85 local_listen_dict['ns_vif_names'].append(vif)86 break87 remote_listen_dict = dict()88 remote_listen_dict['checker_type'] = "SNAT"89 remote_listen_dict['packet_type'] = "ICMP"90 remote_listen_dict['vm_name'] = self.vm_name91 remote_listen_dict['src_ip_address'] = self.fixed_ip_address92 remote_listen_dict['src_mac_address'] = self.source_port_dict['mac_address']93 remote_listen_dict['dest_ip_address'] = self.dest_ip_address94 remote_listen_dict['dest_mac_address'] = self.dest_mac_address95 remote_listen_dict['host_id'] = self.snat_host_id96 remote_listen_dict['port_id'] = self.source_port_dict['id']97 remote_listen_dict['network_label_remote_ext'] = discovery.get_network_label(self.external_network_id, self.neutron)98 remote_listen_dict['network_type_remote_ext'] = discovery.get_network_type(self.external_network_id, self.neutron)99 remote_listen_dict['network_label'] = discovery.get_network_label(self.tenant_network_id, self.neutron)100 remote_listen_dict['network_type'] = discovery.get_network_type(self.tenant_network_id, self.neutron)101 remote_listen_dict['nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % (self.fixed_ip_address, self.dest_ip_address, self.dest_ip_address, self.fixed_ip_address)102 remote_listen_dict['ext_nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % (self.snat_external_ip, self.dest_ip_address, self.dest_ip_address, self.snat_external_ip)103 tunnel_ip = discovery.get_tunnel_ip(self.snat_host_id, self.neutron)104 remote_listen_dict['tunnel_ip'] = tunnel_ip105 remote_listen_dict['vxlan_filter'] = "(src %s or dst %s) and udp port (4789)" % (remote_listen_dict['tunnel_ip'], remote_listen_dict['tunnel_ip'])106 if remote_listen_dict['network_type'] == "vxlan":107 remote_listen_dict['tunnel_port'] = discovery.get_tunnel_port(self.snat_host_id, remote_listen_dict['tunnel_ip'], self.neutron)108 else:109 remote_listen_dict['tunnel_port'] = "None"110 remote_listen_dict['bridge_name'] = discovery.get_bridge_name(remote_listen_dict['network_label'], self.snat_host_id, self.neutron)111 remote_listen_dict['bridge_name_remote_ext'] = discovery.get_bridge_name(remote_listen_dict['network_label_remote_ext'], self.snat_host_id, self.neutron)112 remote_listen_dict['tag'] = "SNAT NS"113 remote_listen_dict['vif_names'] = []114 remote_listen_dict['ns_vif_names'] = []115 for vif in vif_buffer:116 for vif_name in list(vif.keys()):117 if "qg" in vif_name or "sg" in vif_name:118 remote_listen_dict['ns_vif_names'].append(vif)119 break120 return local_listen_dict, remote_listen_dict121 def format_inject_dict(self):122 inject_icmp_dict = dict()123 inject_icmp_dict.update(self.local_listen_dict)124 inject_icmp_dict['payload'] = "abcd" * 3125 for vif in inject_icmp_dict['vif_names']:126 if "qbr" in list(vif.keys())[0]:127 inject_port = list(vif.keys())[0]128 break129 inject_icmp_dict['inject_port'] = inject_port130 return inject_icmp_dict131 def get_vif_list(self):132 vif_list = []133 vif_names = discovery.get_vif_names(self.source_port_dict['id'])134 for port_type, vif_name in vif_names.items():135 vif = dict()136 vif[vif_name] = dict()137 vif[vif_name]['filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % (self.fixed_ip_address, self.dest_ip_address, self.dest_ip_address, self.fixed_ip_address)138 vif[vif_name]['is_ns'] = "None"139 vif[vif_name]['port_type'] = port_type140 vif_list.append(vif)141 return vif_list142 def get_ns_vif_list(self):143 ns_vif_list = []144 ns_vif_names = discovery.get_snat_interfaces(self.router_id, self.qr_port_id, self.sg_port['id'], self.qg_port['id'])145 for vif_name, netns in ns_vif_names.items():146 vif = dict()147 vif[vif_name] = dict()148 if "qg" in vif_name:149 vif[vif_name]['filter'] = "icmp and host %s and host %s " % (self.snat_external_ip, self.dest_ip_address)150 else:151 vif[vif_name]['filter'] = "icmp and host %s and host %s " % (self.fixed_ip_address, self.dest_ip_address)152 vif[vif_name]['is_ns'] = netns153 vif[vif_name]['port_type'] = vif_name154 ns_vif_list.append(vif)155 return ns_vif_list156 def determine_snat_host(self):157 if self.snat_host_id == self.source_host_id:158 self.flag = "local"159 return "local snat"160 else:161 self.flag = "remote"162 return "remote snat"163 def get_local_dict(self):164 return self.local_listen_dict165 def get_remote_dict(self):166 return self.remote_listen_dict167 def get_inject_dict(self):168 return self.inject_icmp_dict169 def get_flag(self):...
server_socket_multiplexer.py
Source:server_socket_multiplexer.py
...19#20# i. Wait for controller to create a mock listen socket and call bind() on21# the mock listen socket.22# ii. Store the address/port from bind() in the mock listen socket.23# iii. Wait for controller to call listen() on the mock listen socket.24# iv. Create a true listen socket that waits on address/port for the client25# SocketDemuliplexer to connect. Store this true listen socket in26# ServerMultiplexedSelect.27# v. Once the client connects to the true listen socket, invoke its accept()28# to create a final true socket.29# vi. Wrap the final true socket in an io_worker managed by ServerMultiplexedSelect,30# and close() the true listen socket.31# vii. Wrap the io_worker in a ServerSocketDemultiplexer.32# viii. Whenever the ClientSocketDemultiplexer negotiates a new connection,33# create a new mock socket and hand it to the mock listen socket created34# in step i.35class ServerSocketDemultiplexer(SocketDemultiplexer):36 # ServerSocketDemultiplexer should be a singleton37 instance = None38 def __init__(self, true_io_worker, mock_listen_sock):39 super(ServerSocketDemultiplexer, self).__init__(true_io_worker)40 # Whenever we see a handshake from the client, hand new MockSockets to41 # mock_listen_sock so that they can be accept()'ed42 self.mock_listen_sock = mock_listen_sock43 if ServerSocketDemultiplexer.instance is not None:44 raise RuntimeError("There's already a ServerSocketDemultiplexer instance")45 ServerSocketDemultiplexer.instance = self46 def _on_receive(self, worker, json_hash):47 super(ServerSocketDemultiplexer, self)._on_receive(worker, json_hash)48 sock_id = json_hash['id']49 msg_type = json_hash['type']50 if msg_type == "SYN":51 # we just saw an unknown channel.52 print("Incoming MockSocket connection %s" %53 json_hash['address'])54 new_sock = self.new_socket(sock_id=sock_id,55 peer_address=json_hash['address'])56 self.mock_listen_sock.append_new_mock_socket(new_sock)57 elif msg_type == "data":58 raw_data = base64.b64decode(json_hash['data'])59 sock_id = json_hash['id']60 if sock_id not in self.id2socket:61 raise ValueError("Unknown socket id %d" % sock_id)62 sock = self.id2socket[sock_id]63 sock.append_read(raw_data)64 else:65 raise ValueError("Unknown msg_type %s" % msg_type)66 def new_socket(self, sock_id=-1, peer_address=None):67 sock = ServerMockSocket(None, None, sock_id=sock_id,68 json_worker=self.json_worker,69 peer_address=peer_address)70 MultiplexedSelect.fileno2ready_to_read[sock_id] = sock.ready_to_read71 self.id2socket[sock_id] = sock72 return sock73def create_true_listen_socket(server_info, protocol, sock_type, blocking=0):74 ''' Return a socket bound to server_info and set to listen '''75 if hasattr(socket, "_old_socket"):76 true_socket = socket._old_socket(protocol, sock_type)77 else:78 true_socket = socket.socket(protocol, sock_type)79 true_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)80 true_socket.bind(server_info)81 true_socket.setblocking(blocking)82 true_socket.listen(1)83 return true_socket84class ServerMockSocket(MockSocket):85 def __init__(self, protocol, sock_type, sock_id=-1, json_worker=None,86 set_true_listen_socket=lambda: None, peer_address=None):87 super(ServerMockSocket, self).__init__(protocol, sock_type,88 sock_id=sock_id,89 json_worker=json_worker)90 self.log = logging.getLogger("mock_sock")91 self.set_true_listen_socket = set_true_listen_socket92 self.peer_address = peer_address93 self.listener = False94 # N.B. only used by mock listen sockets95 self.new_sockets = []96 self.server_info = None97 def ready_to_read(self):98 return self.pending_reads != [] or self.new_sockets != []99 def bind(self, server_info):100 # Before bind() is called, we don't know the101 # address of the true connection.102 self.server_info = server_info103 def listen(self, _):104 self.listener = True105 # Here, we create a *real* socket.106 # bind it to server_info, and wait for the client SocketDemultiplexer to107 # connect. After this is done, we can instantiate our own108 # SocketDemultiplexer. Assumes that all invocations of bind() are intended109 # for connection to STS.110 # TODO(cs): STS should tell pox_monkeypatcher exactly what ports it111 # intends to connect to. If bind() is called for some other port, delegate to112 # a real socket.113 true_socket = create_true_listen_socket(self.server_info, self.protocol,114 self.sock_type, blocking=0)115 # We give this true socket to select.select and116 # wait for the client SocketDemultiplexer connection117 self.set_true_listen_socket(true_socket, self,...
registry.py
Source:registry.py
...18from .. import exc19from .. import util20_key_to_collection = collections.defaultdict(dict)21"""22Given an original listen() argument, can locate all23listener collections and the listener fn contained24(target, identifier, fn) -> {25 ref(listenercollection) -> ref(listener_fn)26 ref(listenercollection) -> ref(listener_fn)27 ref(listenercollection) -> ref(listener_fn)28 }29"""30_collection_to_key = collections.defaultdict(dict)31"""32Given a _ListenerCollection or _ClsLevelListener, can locate33all the original listen() arguments and the listener fn contained34ref(listenercollection) -> {35 ref(listener_fn) -> (target, identifier, fn),36 ref(listener_fn) -> (target, identifier, fn),37 ref(listener_fn) -> (target, identifier, fn),38 }39"""40def _collection_gced(ref):41 # defaultdict, so can't get a KeyError42 if not _collection_to_key or ref not in _collection_to_key:43 return44 listener_to_key = _collection_to_key.pop(ref)45 for key in listener_to_key.values():46 if key in _key_to_collection:47 # defaultdict, so can't get a KeyError48 dispatch_reg = _key_to_collection[key]49 dispatch_reg.pop(ref)50 if not dispatch_reg:51 _key_to_collection.pop(key)52def _stored_in_collection(event_key, owner):53 key = event_key._key54 dispatch_reg = _key_to_collection[key]55 owner_ref = owner.ref56 listen_ref = weakref.ref(event_key._listen_fn)57 if owner_ref in dispatch_reg:58 return False59 dispatch_reg[owner_ref] = listen_ref60 listener_to_key = _collection_to_key[owner_ref]61 listener_to_key[listen_ref] = key62 return True63def _removed_from_collection(event_key, owner):64 key = event_key._key65 dispatch_reg = _key_to_collection[key]66 listen_ref = weakref.ref(event_key._listen_fn)67 owner_ref = owner.ref68 dispatch_reg.pop(owner_ref, None)69 if not dispatch_reg:70 del _key_to_collection[key]71 if owner_ref in _collection_to_key:72 listener_to_key = _collection_to_key[owner_ref]73 listener_to_key.pop(listen_ref)74def _stored_in_collection_multi(newowner, oldowner, elements):75 if not elements:76 return77 oldowner = oldowner.ref78 newowner = newowner.ref79 old_listener_to_key = _collection_to_key[oldowner]80 new_listener_to_key = _collection_to_key[newowner]81 for listen_fn in elements:82 listen_ref = weakref.ref(listen_fn)83 key = old_listener_to_key[listen_ref]84 dispatch_reg = _key_to_collection[key]85 if newowner in dispatch_reg:86 assert dispatch_reg[newowner] == listen_ref87 else:88 dispatch_reg[newowner] = listen_ref89 new_listener_to_key[listen_ref] = key90def _clear(owner, elements):91 if not elements:92 return93 owner = owner.ref94 listener_to_key = _collection_to_key[owner]95 for listen_fn in elements:96 listen_ref = weakref.ref(listen_fn)97 key = listener_to_key[listen_ref]98 dispatch_reg = _key_to_collection[key]99 dispatch_reg.pop(owner, None)100 if not dispatch_reg:101 del _key_to_collection[key]102class _EventKey(object):103 """Represent :func:`.listen` arguments.104 """105 __slots__ = (106 "target",107 "identifier",108 "fn",109 "fn_key",110 "fn_wrap",111 "dispatch_target",112 )113 def __init__(self, target, identifier, fn, dispatch_target, _fn_wrap=None):114 self.target = target115 self.identifier = identifier116 self.fn = fn117 if isinstance(fn, types.MethodType):118 self.fn_key = id(fn.__func__), id(fn.__self__)119 else:120 self.fn_key = id(fn)121 self.fn_wrap = _fn_wrap122 self.dispatch_target = dispatch_target123 @property124 def _key(self):125 return (id(self.target), self.identifier, self.fn_key)126 def with_wrapper(self, fn_wrap):127 if fn_wrap is self._listen_fn:128 return self129 else:130 return _EventKey(131 self.target,132 self.identifier,133 self.fn,134 self.dispatch_target,135 _fn_wrap=fn_wrap,136 )137 def with_dispatch_target(self, dispatch_target):138 if dispatch_target is self.dispatch_target:139 return self140 else:141 return _EventKey(142 self.target,143 self.identifier,144 self.fn,145 dispatch_target,146 _fn_wrap=self.fn_wrap,147 )148 def listen(self, *args, **kw):149 once = kw.pop("once", False)150 named = kw.pop("named", False)151 target, identifier, fn = (152 self.dispatch_target,153 self.identifier,154 self._listen_fn,155 )156 dispatch_collection = getattr(target.dispatch, identifier)157 adjusted_fn = dispatch_collection._adjust_fn_spec(fn, named)158 self = self.with_wrapper(adjusted_fn)159 if once:160 self.with_wrapper(util.only_once(self._listen_fn)).listen(161 *args, **kw162 )163 else:164 self.dispatch_target.dispatch._listen(self, *args, **kw)165 def remove(self):166 key = self._key167 if key not in _key_to_collection:168 raise exc.InvalidRequestError(169 "No listeners found for event %s / %r / %s "170 % (self.target, self.identifier, self.fn)171 )172 dispatch_reg = _key_to_collection.pop(key)173 for collection_ref, listener_ref in dispatch_reg.items():174 collection = collection_ref()175 listener_fn = listener_ref()176 if collection is not None and listener_fn is not None:177 collection.remove(self.with_wrapper(listener_fn))178 def contains(self):179 """Return True if this event key is registered to listen.180 """181 return self._key in _key_to_collection182 def base_listen(183 self, propagate=False, insert=False, named=False, retval=None184 ):185 target, identifier = self.dispatch_target, self.identifier186 dispatch_collection = getattr(target.dispatch, identifier)187 if insert:188 dispatch_collection.for_modify(target.dispatch).insert(189 self, propagate190 )191 else:192 dispatch_collection.for_modify(target.dispatch).append(193 self, propagate194 )195 @property196 def _listen_fn(self):...
data.py
Source:data.py
1"""Data used by this integration."""2from __future__ import annotations3import asyncio4from collections import defaultdict5from typing import NamedTuple, cast6from async_upnp_client import UpnpEventHandler, UpnpFactory, UpnpRequester7from async_upnp_client.aiohttp import AiohttpNotifyServer, AiohttpSessionRequester8from homeassistant.const import EVENT_HOMEASSISTANT_STOP9from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant10from homeassistant.helpers import aiohttp_client11from .const import DOMAIN, LOGGER12class EventListenAddr(NamedTuple):13 """Unique identifier for an event listener."""14 host: str | None # Specific local IP(v6) address for listening on15 port: int # Listening port, 0 means use an ephemeral port16 callback_url: str | None17class DlnaDmrData:18 """Storage class for domain global data."""19 lock: asyncio.Lock20 requester: UpnpRequester21 upnp_factory: UpnpFactory22 event_notifiers: dict[EventListenAddr, AiohttpNotifyServer]23 event_notifier_refs: defaultdict[EventListenAddr, int]24 stop_listener_remove: CALLBACK_TYPE | None = None25 def __init__(self, hass: HomeAssistant) -> None:26 """Initialize global data."""27 self.lock = asyncio.Lock()28 session = aiohttp_client.async_get_clientsession(hass, verify_ssl=False)29 self.requester = AiohttpSessionRequester(session, with_sleep=True)30 self.upnp_factory = UpnpFactory(self.requester, non_strict=True)31 self.event_notifiers = {}32 self.event_notifier_refs = defaultdict(int)33 async def async_cleanup_event_notifiers(self, event: Event) -> None:34 """Clean up resources when Home Assistant is stopped."""35 LOGGER.debug("Cleaning resources in DlnaDmrData")36 async with self.lock:37 tasks = (38 server.async_stop_server() for server in self.event_notifiers.values()39 )40 asyncio.gather(*tasks)41 self.event_notifiers = {}42 self.event_notifier_refs = defaultdict(int)43 async def async_get_event_notifier(44 self, listen_addr: EventListenAddr, hass: HomeAssistant45 ) -> UpnpEventHandler:46 """Return existing event notifier for the listen_addr, or create one.47 Only one event notify server is kept for each listen_addr. Must call48 async_release_event_notifier when done to cleanup resources.49 """50 LOGGER.debug("Getting event handler for %s", listen_addr)51 async with self.lock:52 # Stop all servers when HA shuts down, to release resources on devices53 if not self.stop_listener_remove:54 self.stop_listener_remove = hass.bus.async_listen_once(55 EVENT_HOMEASSISTANT_STOP, self.async_cleanup_event_notifiers56 )57 # Always increment the reference counter, for existing or new event handlers58 self.event_notifier_refs[listen_addr] += 159 # Return an existing event handler if we can60 if listen_addr in self.event_notifiers:61 return self.event_notifiers[listen_addr].event_handler62 # Start event handler63 source = (listen_addr.host or "0.0.0.0", listen_addr.port)64 server = AiohttpNotifyServer(65 requester=self.requester,66 source=source,67 callback_url=listen_addr.callback_url,68 loop=hass.loop,69 )70 await server.async_start_server()71 LOGGER.debug("Started event handler at %s", server.callback_url)72 self.event_notifiers[listen_addr] = server73 return server.event_handler74 async def async_release_event_notifier(self, listen_addr: EventListenAddr) -> None:75 """Indicate that the event notifier for listen_addr is not used anymore.76 This is called once by each caller of async_get_event_notifier, and will77 stop the listening server when all users are done.78 """79 async with self.lock:80 assert self.event_notifier_refs[listen_addr] > 081 self.event_notifier_refs[listen_addr] -= 182 # Shutdown the server when it has no more users83 if self.event_notifier_refs[listen_addr] == 0:84 server = self.event_notifiers.pop(listen_addr)85 await server.async_stop_server()86 # Remove the cleanup listener when there's nothing left to cleanup87 if not self.event_notifiers:88 assert self.stop_listener_remove is not None89 self.stop_listener_remove()90 self.stop_listener_remove = None91def get_domain_data(hass: HomeAssistant) -> DlnaDmrData:92 """Obtain this integration's domain data, creating it if needed."""93 if DOMAIN in hass.data:94 return cast(DlnaDmrData, hass.data[DOMAIN])95 data = DlnaDmrData(hass)96 hass.data[DOMAIN] = data...
test_data.py
Source:test_data.py
1"""Tests for the DLNA DMR data module."""2from __future__ import annotations3from collections.abc import Iterable4from unittest.mock import ANY, Mock, patch5from async_upnp_client import UpnpEventHandler6from async_upnp_client.aiohttp import AiohttpNotifyServer7import pytest8from homeassistant.components.dlna_dmr.const import DOMAIN9from homeassistant.components.dlna_dmr.data import EventListenAddr, get_domain_data10from homeassistant.const import EVENT_HOMEASSISTANT_STOP11from homeassistant.core import Event, HomeAssistant12@pytest.fixture13def aiohttp_notify_servers_mock() -> Iterable[Mock]:14 """Construct mock AiohttpNotifyServer on demand, eliminating network use.15 This fixture provides a list of the constructed servers.16 """17 with patch(18 "homeassistant.components.dlna_dmr.data.AiohttpNotifyServer"19 ) as mock_constructor:20 servers = []21 def make_server(*_args, **_kwargs):22 server = Mock(spec=AiohttpNotifyServer)23 servers.append(server)24 server.event_handler = Mock(spec=UpnpEventHandler)25 return server26 mock_constructor.side_effect = make_server27 yield mock_constructor28 # Every server must be stopped if it was started29 for server in servers:30 assert (31 server.async_start_server.call_count32 == server.async_stop_server.call_count33 )34async def test_get_domain_data(hass: HomeAssistant) -> None:35 """Test the get_domain_data function returns the same data every time."""36 assert DOMAIN not in hass.data37 domain_data = get_domain_data(hass)38 assert domain_data is not None39 assert get_domain_data(hass) is domain_data40async def test_event_notifier(41 hass: HomeAssistant, aiohttp_notify_servers_mock: Mock42) -> None:43 """Test getting and releasing event notifiers."""44 domain_data = get_domain_data(hass)45 listen_addr = EventListenAddr(None, 0, None)46 event_notifier = await domain_data.async_get_event_notifier(listen_addr, hass)47 assert event_notifier is not None48 # Check that the parameters were passed through to the AiohttpNotifyServer49 aiohttp_notify_servers_mock.assert_called_with(50 requester=ANY, source=("0.0.0.0", 0), callback_url=None, loop=ANY51 )52 # Same address should give same notifier53 listen_addr_2 = EventListenAddr(None, 0, None)54 event_notifier_2 = await domain_data.async_get_event_notifier(listen_addr_2, hass)55 assert event_notifier_2 is event_notifier56 # Different address should give different notifier57 listen_addr_3 = EventListenAddr(58 "192.88.99.4", 9999, "http://192.88.99.4:9999/notify"59 )60 event_notifier_3 = await domain_data.async_get_event_notifier(listen_addr_3, hass)61 assert event_notifier_3 is not None62 assert event_notifier_3 is not event_notifier63 # Check that the parameters were passed through to the AiohttpNotifyServer64 aiohttp_notify_servers_mock.assert_called_with(65 requester=ANY,66 source=("192.88.99.4", 9999),67 callback_url="http://192.88.99.4:9999/notify",68 loop=ANY,69 )70 # There should be 2 notifiers total, one with 2 references, and a stop callback71 assert set(domain_data.event_notifiers.keys()) == {listen_addr, listen_addr_3}72 assert domain_data.event_notifier_refs == {listen_addr: 2, listen_addr_3: 1}73 assert domain_data.stop_listener_remove is not None74 # Releasing notifiers should delete them when they have not more references75 await domain_data.async_release_event_notifier(listen_addr)76 assert set(domain_data.event_notifiers.keys()) == {listen_addr, listen_addr_3}77 assert domain_data.event_notifier_refs == {listen_addr: 1, listen_addr_3: 1}78 assert domain_data.stop_listener_remove is not None79 await domain_data.async_release_event_notifier(listen_addr)80 assert set(domain_data.event_notifiers.keys()) == {listen_addr_3}81 assert domain_data.event_notifier_refs == {listen_addr: 0, listen_addr_3: 1}82 assert domain_data.stop_listener_remove is not None83 await domain_data.async_release_event_notifier(listen_addr_3)84 assert set(domain_data.event_notifiers.keys()) == set()85 assert domain_data.event_notifier_refs == {listen_addr: 0, listen_addr_3: 0}86 assert domain_data.stop_listener_remove is None87async def test_cleanup_event_notifiers(88 hass: HomeAssistant, aiohttp_notify_servers_mock: Mock89) -> None:90 """Test cleanup function clears all event notifiers."""91 domain_data = get_domain_data(hass)92 await domain_data.async_get_event_notifier(EventListenAddr(None, 0, None), hass)93 await domain_data.async_get_event_notifier(94 EventListenAddr(None, 0, "different"), hass95 )96 await domain_data.async_cleanup_event_notifiers(Event(EVENT_HOMEASSISTANT_STOP))97 assert not domain_data.event_notifiers...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('text=Hello world!');7 await browser.close();8})();9- [Playwright code examples](
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.route('**/*', route => {7 if (route.request().url().endsWith('.png'))8 route.fulfill({path: './assets/cat.png'});9 route.continue();10 });11 await page.screenshot({path: 'google.png'});12 await browser.close();13})();14const {chromium} = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const context = await browser.newContext();18 const page = await context.newPage();19 await page.route('**/*', route => {20 if (route.request().url().endsWith('.png'))21 route.fulfill({path: './assets/cat.png'});22 route.continue();23 });24 await page.screenshot({path: 'google.png'});25 await browser.close();26})();27const {chromium} = require('playwright');28(async () => {29 const browser = await chromium.launch();30 const context = await browser.newContext();31 const page = await context.newPage();32 await page.route('**/*', route => {33 if (route.request().url().endsWith('.png'))34 route.fulfill({path: './assets/cat.png'});35 route.continue();36 });37 await page.screenshot({path: 'google.png'});38 await browser.close();39})();40const {chromium} = require('playwright');41(async () => {42 const browser = await chromium.launch();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Hello, world!');7 await context.close();8 await browser.close();9})();10#### playwrightServer.listen(options)11#### playwrightServer.close()12#### playwrightServer.url()
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.route('**/*', route => route.fulfill({7 headers: {8 'content-type': 'text/html; charset=utf-8',9 },10 }));11 await page.screenshot({ path: 'example.png' });12 await browser.close();13})();14[MIT License](LICENSE)
Using AI Code Generation
1const {chromium} = require('playwright-chromium');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.route("**/test.js", route => route.fulfill({7 }));8 await page.click('#text');9 await page.screenshot({path: 'example.png'});10 await browser.close();11})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const [request] = await Promise.all([7 page.waitForEvent('request'),8 ]);9 console.log(request.url());10 await browser.close();11})();12### **waitForEvent**(_eventType_, _options_)13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const request = await page.waitForEvent('request');19 console.log(request.url());20 await browser.close();21})();22### **waitForRequest**(_urlOrPredicate_, _options_)23 - `timeout` <[number]> Maximum time in milliseconds to wait, defaults to `30000` (30 seconds). Pass `0` to disable the timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](./class-page#pageset
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const server = await playwright._impl._server.create();4 await server.listen(8080);5})();6#### `PlaywrightServer.listen(port)`7#### `PlaywrightServer.close()`8#### `PlaywrightServer.on(event, handler)`9#### `PlaywrightServer.off(event, handler)`10#### `PlaywrightServer.emit(event, ...args)`11#### `PlaywrightServer.on('request', handler)`12#### `PlaywrightServer.on('response', handler)`13#### `PlaywrightServer.on('close', handler)`14#### `PlaywrightRequest.url()`15#### `PlaywrightRequest.method()`16#### `PlaywrightRequest.postData()`17#### `PlaywrightRequest.headers()`18#### `PlaywrightRequest.route(handler)`19#### `PlaywrightResponse.statusCode()`
Using AI Code Generation
1const { listen } = require('@playwright/test');2const app = require('./app');3const server = listen(app);4module.exports = server;5const { test } = require('@playwright/test');6const server = require('./server');7test('should open login page', async ({ page }) => {8 await page.goto(server.PREFIX);9 await page.screenshot({ path: `screenshots/login.png` });10});11const { test } = require('@playwright/test');12const server = require('./server');13test('should open login page', async ({ page }) => {14 await page.goto(server.PREFIX);15 await page.screenshot({ path: `screenshots/login.png` });16});17const { test } = require('@playwright/test');18const server = require('./server');19test('should open login page', async ({ page }) => {20 await page.goto(server.PREFIX);21 await page.screenshot({ path: `screenshots/login.png` });22});23const { test } = require('@playwright/test');24const server = require('./server');25test('should open login page', async ({ page }) => {26 await page.goto(server.PREFIX);27 await page.screenshot({ path: `screenshots/login.png` });28});
Using AI Code Generation
1const { webServer } = require('@playwright/test');2(async () => {3 const server = await webServer.listen();4 const { port } = server;5 console.log(port);6 await server.stop();7})();8### `webServer.listen(options)`
Using AI Code Generation
1const { chromium } = require('playwright');2const { test, expect } = require('@playwright/test');3const { createServer } = require('http');4const { createReadStream } = require('fs');5const { join } = require('path');6test.describe('Playwright Internal Server', () => {7 test('should listen to the request and response', async ({ page }) => {8 const server = createServer((req, res) => {9 res.writeHead(200, {10 });11 createReadStream(join(__dirname, 'index.html')).pipe(res);12 });13 server.listen(3000);14 await expect(page.title()).resolves.toMatch('Playwright');15 server.close();16 });17});18const { chromium } = require('playwright');19const { test, expect } = require('@playwright/test');20test.describe('Devtools option', () => {21 test('should open the browser in the devtools mode', async ({ page }) => {22 const browser = await chromium.launch({23 });24 const page = await browser.newPage();25 await expect(page.title()).resolves.toMatch('Playwright');26 await browser.close();27 });28});
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!