2022-01-03 14:02:41 +00:00
// Do not edit this file; automatically generated.
2021-08-28 14:28:26 +00:00
/* eslint-disable */
; ( function ( root , factory ) {
if ( typeof define === 'function' && define . amd ) { // AMD
2022-01-03 14:02:41 +00:00
define ( [ "./blockly_compressed.js" ] , factory ) ;
2021-08-28 14:28:26 +00:00
} else if ( typeof exports === 'object' ) { // Node.js
2022-01-03 14:02:41 +00:00
module . exports = factory ( require ( "./blockly_compressed.js" ) ) ;
2021-08-28 14:28:26 +00:00
} else { // Browser
2022-06-07 11:14:29 +00:00
var factoryExports = factory ( root . Blockly ) ;
root . Blockly . Python = factoryExports ;
2021-08-28 14:28:26 +00:00
}
2022-06-07 11:14:29 +00:00
} ( this , function ( _ _parent _ _ ) {
var $ = _ _parent _ _ . _ _namespace _ _ ;
2022-01-03 14:02:41 +00:00
var module$contents$Blockly$Python _Python = new $ . module$exports$Blockly$Generator . Generator ( "Python" ) ; module$contents$Blockly$Python _Python . addReservedWords ( "False,None,True,and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,nonlocal,not,or,pass,print,raise,return,try,while,with,yield,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,ArithmeticError,AssertionError,AttributeError,BaseException,BlockingIOError,BrokenPipeError,BufferError,BytesWarning,ChildProcessError,ConnectionAbortedError,ConnectionError,ConnectionRefusedError,ConnectionResetError,DeprecationWarning,EOFError,Ellipsis,EnvironmentError,Exception,FileExistsError,FileNotFoundError,FloatingPointError,FutureWarning,GeneratorExit,IOError,ImportError,ImportWarning,IndentationError,IndexError,InterruptedError,IsADirectoryError,KeyError,KeyboardInterrupt,LookupError,MemoryError,ModuleNotFoundError,NameError,NotADirectoryError,NotImplemented,NotImplementedError,OSError,OverflowError,PendingDeprecationWarning,PermissionError,ProcessLookupError,RecursionError,ReferenceError,ResourceWarning,RuntimeError,RuntimeWarning,StandardError,StopAsyncIteration,StopIteration,SyntaxError,SyntaxWarning,SystemError,SystemExit,TabError,TimeoutError,TypeError,UnboundLocalError,UnicodeDecodeError,UnicodeEncodeError,UnicodeError,UnicodeTranslateError,UnicodeWarning,UserWarning,ValueError,Warning,ZeroDivisionError,_,__build_class__,__debug__,__doc__,__import__,__loader__,__name__,__package__,__spec__,abs,all,any,apply,ascii,basestring,bin,bool,buffer,bytearray,bytes,callable,chr,classmethod,cmp,coerce,compile,complex,copyright,credits,delattr,dict,dir,divmod,enumerate,eval,exec,execfile,exit,file,filter,float,format,frozenset,getattr,globals,hasattr,hash,help,hex,id,input,int,intern,isinstance,issubclass,iter,len,license,list,locals,long,map,max,memoryview,min,next,object,oct,open,ord,pow,print,property,quit,range,raw_input,reduce,reload,repr,reversed,round,set,setattr,slice,sorted,staticmethod,str,sum,super,tuple,type,unichr,unicode,vars,xrange,zip" ) ;
module$contents$Blockly$Python _Python . ORDER _ATOMIC = 0 ; module$contents$Blockly$Python _Python . ORDER _COLLECTION = 1 ; module$contents$Blockly$Python _Python . ORDER _STRING _CONVERSION = 1 ; module$contents$Blockly$Python _Python . ORDER _MEMBER = 2.1 ; module$contents$Blockly$Python _Python . ORDER _FUNCTION _CALL = 2.2 ; module$contents$Blockly$Python _Python . ORDER _EXPONENTIATION = 3 ; module$contents$Blockly$Python _Python . ORDER _UNARY _SIGN = 4 ; module$contents$Blockly$Python _Python . ORDER _BITWISE _NOT = 4 ;
module$contents$Blockly$Python _Python . ORDER _MULTIPLICATIVE = 5 ; module$contents$Blockly$Python _Python . ORDER _ADDITIVE = 6 ; module$contents$Blockly$Python _Python . ORDER _BITWISE _SHIFT = 7 ; module$contents$Blockly$Python _Python . ORDER _BITWISE _AND = 8 ; module$contents$Blockly$Python _Python . ORDER _BITWISE _XOR = 9 ; module$contents$Blockly$Python _Python . ORDER _BITWISE _OR = 10 ; module$contents$Blockly$Python _Python . ORDER _RELATIONAL = 11 ; module$contents$Blockly$Python _Python . ORDER _LOGICAL _NOT = 12 ;
module$contents$Blockly$Python _Python . ORDER _LOGICAL _AND = 13 ; module$contents$Blockly$Python _Python . ORDER _LOGICAL _OR = 14 ; module$contents$Blockly$Python _Python . ORDER _CONDITIONAL = 15 ; module$contents$Blockly$Python _Python . ORDER _LAMBDA = 16 ; module$contents$Blockly$Python _Python . ORDER _NONE = 99 ;
module$contents$Blockly$Python _Python . ORDER _OVERRIDES = [ [ module$contents$Blockly$Python _Python . ORDER _FUNCTION _CALL , module$contents$Blockly$Python _Python . ORDER _MEMBER ] , [ module$contents$Blockly$Python _Python . ORDER _FUNCTION _CALL , module$contents$Blockly$Python _Python . ORDER _FUNCTION _CALL ] , [ module$contents$Blockly$Python _Python . ORDER _MEMBER , module$contents$Blockly$Python _Python . ORDER _MEMBER ] , [ module$contents$Blockly$Python _Python . ORDER _MEMBER , module$contents$Blockly$Python _Python . ORDER _FUNCTION _CALL ] , [ module$contents$Blockly$Python _Python . ORDER _LOGICAL _NOT ,
module$contents$Blockly$Python _Python . ORDER _LOGICAL _NOT ] , [ module$contents$Blockly$Python _Python . ORDER _LOGICAL _AND , module$contents$Blockly$Python _Python . ORDER _LOGICAL _AND ] , [ module$contents$Blockly$Python _Python . ORDER _LOGICAL _OR , module$contents$Blockly$Python _Python . ORDER _LOGICAL _OR ] ] ; module$contents$Blockly$Python _Python . isInitialized = ! 1 ;
module$contents$Blockly$Python _Python . init = function ( a ) { Object . getPrototypeOf ( this ) . init . call ( this ) ; this . PASS = this . INDENT + "pass\n" ; this . nameDB _ ? this . nameDB _ . reset ( ) : this . nameDB _ = new $ . module$exports$Blockly$Names . Names ( this . RESERVED _WORDS _ ) ; this . nameDB _ . setVariableMap ( a . getVariableMap ( ) ) ; this . nameDB _ . populateVariables ( a ) ; this . nameDB _ . populateProcedures ( a ) ; for ( var b = [ ] , c = ( 0 , $ . module$exports$Blockly$Variables . allDeveloperVariables ) ( a ) , d = 0 ; d < c . length ; d ++ ) b . push ( this . nameDB _ . getName ( c [ d ] , $ . module$exports$Blockly$Names . Names . DEVELOPER _VARIABLE _TYPE ) +
" = None" ) ; a = ( 0 , $ . module$exports$Blockly$Variables . allUsedVarModels ) ( a ) ; for ( c = 0 ; c < a . length ; c ++ ) b . push ( this . nameDB _ . getName ( a [ c ] . getId ( ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) + " = None" ) ; this . definitions _ . variables = b . join ( "\n" ) ; this . isInitialized = ! 0 } ;
module$contents$Blockly$Python _Python . finish = function ( a ) { var b = [ ] , c = [ ] , d ; for ( d in this . definitions _ ) { var e = this . definitions _ [ d ] ; e . match ( /^(from\s+\S+\s+)?import\s+\S+/ ) ? b . push ( e ) : c . push ( e ) } a = Object . getPrototypeOf ( this ) . finish . call ( this , a ) ; this . isInitialized = ! 1 ; this . nameDB _ . reset ( ) ; return ( b . join ( "\n" ) + "\n\n" + c . join ( "\n\n" ) ) . replace ( /\n\n+/g , "\n\n" ) . replace ( /\n*$/ , "\n\n\n" ) + a } ; module$contents$Blockly$Python _Python . scrubNakedValue = function ( a ) { return a + "\n" } ;
module$contents$Blockly$Python _Python . quote _ = function ( a ) { a = a . replace ( /\\/g , "\\\\" ) . replace ( /\n/g , "\\\n" ) ; var b = "'" ; - 1 !== a . indexOf ( "'" ) && ( - 1 === a . indexOf ( '"' ) ? b = '"' : a = a . replace ( /'/g , "\\'" ) ) ; return b + a + b } ; module$contents$Blockly$Python _Python . multiline _quote _ = function ( a ) { return a . split ( /\n/g ) . map ( this . quote _ ) . join ( " + '\\n' + \n" ) } ;
module$contents$Blockly$Python _Python . scrub _ = function ( a , b , c ) { var d = "" ; if ( ! a . outputConnection || ! a . outputConnection . targetConnection ) { var e = a . getCommentText ( ) ; e && ( e = ( 0 , $ . module$exports$Blockly$utils$string . wrap ) ( e , this . COMMENT _WRAP - 3 ) , d += this . prefixLines ( e + "\n" , "# " ) ) ; for ( var f = 0 ; f < a . inputList . length ; f ++ ) a . inputList [ f ] . type === $ . module$exports$Blockly$inputTypes . inputTypes . VALUE && ( e = a . inputList [ f ] . connection . targetBlock ( ) ) && ( e = this . allNestedComments ( e ) ) && ( d += this . prefixLines ( e , "# " ) ) } a = a . nextConnection &&
a . nextConnection . targetBlock ( ) ; c = c ? "" : this . blockToCode ( a ) ; return d + b + c } ; module$contents$Blockly$Python _Python . getAdjustedInt = function ( a , b , c , d ) { c = c || 0 ; a . workspace . options . oneBasedIndex && c -- ; var e = a . workspace . options . oneBasedIndex ? "1" : "0" ; a = this . valueToCode ( a , b , c ? this . ORDER _ADDITIVE : this . ORDER _NONE ) || e ; ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( a ) ? ( a = parseInt ( a , 10 ) + c , d && ( a = - a ) ) : ( a = 0 < c ? "int(" + a + " + " + c + ")" : 0 > c ? "int(" + a + " - " + - c + ")" : "int(" + a + ")" , d && ( a = "-" + a ) ) ; return a } ; $ . Blockly . Python = module$contents$Blockly$Python _Python ; var module$exports$Blockly$Python$variables = { } ; $ . Blockly . Python . variables _get = function ( a ) { return [ $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "VAR" ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) , $ . Blockly . Python . ORDER _ATOMIC ] } ; $ . Blockly . Python . variables _set = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "0" ; return $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "VAR" ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) + " = " + b + "\n" } ; var module$exports$Blockly$Python$variablesDynamic = { } ; $ . Blockly . Python . variables _get _dynamic = $ . Blockly . Python . variables _get ; $ . Blockly . Python . variables _set _dynamic = $ . Blockly . Python . variables _set ; var module$exports$Blockly$Python$texts = { } ; $ . Blockly . Python . text = function ( a ) { return [ $ . Blockly . Python . quote _ ( a . getFieldValue ( "TEXT" ) ) , $ . Blockly . Python . ORDER _ATOMIC ] } ; $ . Blockly . Python . text _multiline = function ( a ) { a = $ . Blockly . Python . multiline _quote _ ( a . getFieldValue ( "TEXT" ) ) ; var b = - 1 !== a . indexOf ( "+" ) ? $ . Blockly . Python . ORDER _ADDITIVE : $ . Blockly . Python . ORDER _ATOMIC ; return [ a , b ] } ;
var module$contents$Blockly$Python$texts _strRegExp = /^\s*'([^']|\\')*'\s*$/ , module$contents$Blockly$Python$texts _forceString = function ( a ) { return module$contents$Blockly$Python$texts _strRegExp . test ( a ) ? [ a , $ . Blockly . Python . ORDER _ATOMIC ] : [ "str(" + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . text _join = function ( a ) { switch ( a . itemCount _ ) { case 0 : return [ "''" , $ . Blockly . Python . ORDER _ATOMIC ] ; case 1 : return a = $ . Blockly . Python . valueToCode ( a , "ADD0" , $ . Blockly . Python . ORDER _NONE ) || "''" , module$contents$Blockly$Python$texts _forceString ( a ) ; case 2 : var b = $ . Blockly . Python . valueToCode ( a , "ADD0" , $ . Blockly . Python . ORDER _NONE ) || "''" ; a = $ . Blockly . Python . valueToCode ( a , "ADD1" , $ . Blockly . Python . ORDER _NONE ) || "''" ; return [ module$contents$Blockly$Python$texts _forceString ( b ) [ 0 ] + " + " + module$contents$Blockly$Python$texts _forceString ( a ) [ 0 ] ,
$ . Blockly . Python . ORDER _ADDITIVE ] ; default : b = [ ] ; for ( var c = 0 ; c < a . itemCount _ ; c ++ ) b [ c ] = $ . Blockly . Python . valueToCode ( a , "ADD" + c , $ . Blockly . Python . ORDER _NONE ) || "''" ; a = $ . Blockly . Python . nameDB _ . getDistinctName ( "x" , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ; return [ "''.join([str(" + a + ") for " + a + " in [" + b . join ( ", " ) + "]])" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } } ;
$ . Blockly . Python . text _append = function ( a ) { var b = $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "VAR" ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ; a = $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _NONE ) || "''" ; return b + " = str(" + b + ") + " + module$contents$Blockly$Python$texts _forceString ( a ) [ 0 ] + "\n" } ; $ . Blockly . Python . text _length = function ( a ) { return [ "len(" + ( $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "''" ) + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . text _isEmpty = function ( a ) { return [ "not len(" + ( $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "''" ) + ")" , $ . Blockly . Python . ORDER _LOGICAL _NOT ] } ;
$ . Blockly . Python . text _indexOf = function ( a ) { var b = "FIRST" === a . getFieldValue ( "END" ) ? "find" : "rfind" , c = $ . Blockly . Python . valueToCode ( a , "FIND" , $ . Blockly . Python . ORDER _NONE ) || "''" ; b = ( $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ) + "." + b + "(" + c + ")" ; return a . workspace . options . oneBasedIndex ? [ b + " + 1" , $ . Blockly . Python . ORDER _ADDITIVE ] : [ b , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . text _charAt = function ( a ) { var b = a . getFieldValue ( "WHERE" ) || "FROM_START" , c = $ . Blockly . Python . valueToCode ( a , "VALUE" , "RANDOM" === b ? $ . Blockly . Python . ORDER _NONE : $ . Blockly . Python . ORDER _MEMBER ) || "''" ; switch ( b ) { case "FIRST" : return [ c + "[0]" , $ . Blockly . Python . ORDER _MEMBER ] ; case "LAST" : return [ c + "[-1]" , $ . Blockly . Python . ORDER _MEMBER ] ; case "FROM_START" : return a = $ . Blockly . Python . getAdjustedInt ( a , "AT" ) , [ c + "[" + a + "]" , $ . Blockly . Python . ORDER _MEMBER ] ; case "FROM_END" : return a = $ . Blockly . Python . getAdjustedInt ( a ,
2022-06-07 11:14:29 +00:00
"AT" , 1 , ! 0 ) , [ c + "[" + a + "]" , $ . Blockly . Python . ORDER _MEMBER ] ; case "RANDOM" : return $ . Blockly . Python . definitions _ . import _random = "import random" , [ $ . Blockly . Python . provideFunction _ ( "text_random_letter" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(text):\n x = int(random.random() * len(text))\n return text[x]\n" ) + "(" + c + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } throw Error ( "Unhandled option (text_charAt)." ) ; } ;
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . text _getSubstring = function ( a ) { var b = a . getFieldValue ( "WHERE1" ) , c = a . getFieldValue ( "WHERE2" ) , d = $ . Blockly . Python . valueToCode ( a , "STRING" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ; switch ( b ) { case "FROM_START" : b = $ . Blockly . Python . getAdjustedInt ( a , "AT1" ) ; 0 === b && ( b = "" ) ; break ; case "FROM_END" : b = $ . Blockly . Python . getAdjustedInt ( a , "AT1" , 1 , ! 0 ) ; break ; case "FIRST" : b = "" ; break ; default : throw Error ( "Unhandled option (text_getSubstring)" ) ; } switch ( c ) { case "FROM_START" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT2" ,
1 ) ; break ; case "FROM_END" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT2" , 0 , ! 0 ) ; ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( String ( a ) ) ? 0 === a && ( a = "" ) : ( $ . Blockly . Python . definitions _ . import _sys = "import sys" , a += " or sys.maxsize" ) ; break ; case "LAST" : a = "" ; break ; default : throw Error ( "Unhandled option (text_getSubstring)" ) ; } return [ d + "[" + b + " : " + a + "]" , $ . Blockly . Python . ORDER _MEMBER ] } ;
$ . Blockly . Python . text _changeCase = function ( a ) { var b = { UPPERCASE : ".upper()" , LOWERCASE : ".lower()" , TITLECASE : ".title()" } [ a . getFieldValue ( "CASE" ) ] ; return [ ( $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ) + b , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ; $ . Blockly . Python . text _trim = function ( a ) { var b = { LEFT : ".lstrip()" , RIGHT : ".rstrip()" , BOTH : ".strip()" } [ a . getFieldValue ( "MODE" ) ] ; return [ ( $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ) + b , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . text _print = function ( a ) { return "print(" + ( $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _NONE ) || "''" ) + ")\n" } ;
2022-06-07 11:14:29 +00:00
$ . Blockly . Python . text _prompt _ext = function ( a ) { var b = $ . Blockly . Python . provideFunction _ ( "text_prompt" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(msg):\n try:\n return raw_input(msg)\n except NameError:\n return input(msg)\n" ) ; var c = a . getField ( "TEXT" ) ? $ . Blockly . Python . quote _ ( a . getFieldValue ( "TEXT" ) ) : $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _NONE ) || "''" ; b = b + "(" + c + ")" ; "NUMBER" === a . getFieldValue ( "TYPE" ) && ( b = "float(" + b + ")" ) ; return [ b , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . text _prompt = $ . Blockly . Python . text _prompt _ext ; $ . Blockly . Python . text _count = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ; a = $ . Blockly . Python . valueToCode ( a , "SUB" , $ . Blockly . Python . ORDER _NONE ) || "''" ; return [ b + ".count(" + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . text _replace = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _MEMBER ) || "''" , c = $ . Blockly . Python . valueToCode ( a , "FROM" , $ . Blockly . Python . ORDER _NONE ) || "''" ; a = $ . Blockly . Python . valueToCode ( a , "TO" , $ . Blockly . Python . ORDER _NONE ) || "''" ; return [ b + ".replace(" + c + ", " + a + ")" , $ . Blockly . Python . ORDER _MEMBER ] } ; $ . Blockly . Python . text _reverse = function ( a ) { return [ ( $ . Blockly . Python . valueToCode ( a , "TEXT" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ) + "[::-1]" , $ . Blockly . Python . ORDER _MEMBER ] } ; var module$exports$Blockly$Python$procedures = { } ;
$ . Blockly . Python . procedures _defreturn = function ( a ) { for ( var b = [ ] , c = a . workspace , d = ( 0 , $ . module$exports$Blockly$Variables . allUsedVarModels ) ( c ) || [ ] , e = 0 , f ; f = d [ e ] ; e ++ ) f = f . name , - 1 === a . getVars ( ) . indexOf ( f ) && b . push ( $ . Blockly . Python . nameDB _ . getName ( f , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ) ; c = ( 0 , $ . module$exports$Blockly$Variables . allDeveloperVariables ) ( c ) ; for ( d = 0 ; d < c . length ; d ++ ) b . push ( $ . Blockly . Python . nameDB _ . getName ( c [ d ] , $ . module$exports$Blockly$Names . NameType . DEVELOPER _VARIABLE ) ) ; c = b . length ? $ . Blockly . Python . INDENT +
"global " + b . join ( ", " ) + "\n" : "" ; b = $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "NAME" ) , $ . module$exports$Blockly$Names . NameType . PROCEDURE ) ; d = "" ; $ . Blockly . Python . STATEMENT _PREFIX && ( d += $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _PREFIX , a ) ) ; $ . Blockly . Python . STATEMENT _SUFFIX && ( d += $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _SUFFIX , a ) ) ; d && ( d = $ . Blockly . Python . prefixLines ( d , $ . Blockly . Python . INDENT ) ) ; e = "" ; $ . Blockly . Python . INFINITE _LOOP _TRAP && ( e = $ . Blockly . Python . prefixLines ( $ . Blockly . Python . injectId ( $ . Blockly . Python . INFINITE _LOOP _TRAP ,
a ) , $ . Blockly . Python . INDENT ) ) ; f = $ . Blockly . Python . statementToCode ( a , "STACK" ) ; var g = $ . Blockly . Python . valueToCode ( a , "RETURN" , $ . Blockly . Python . ORDER _NONE ) || "" , h = "" ; f && g && ( h = d ) ; g ? g = $ . Blockly . Python . INDENT + "return " + g + "\n" : f || ( f = $ . Blockly . Python . PASS ) ; for ( var k = [ ] , l = a . getVars ( ) , m = 0 ; m < l . length ; m ++ ) k [ m ] = $ . Blockly . Python . nameDB _ . getName ( l [ m ] , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ; c = "def " + b + "(" + k . join ( ", " ) + "):\n" + c + d + e + f + h + g ; c = $ . Blockly . Python . scrub _ ( a , c ) ; $ . Blockly . Python . definitions _ [ "%" + b ] = c ;
return null } ; $ . Blockly . Python . procedures _defnoreturn = $ . Blockly . Python . procedures _defreturn ; $ . Blockly . Python . procedures _callreturn = function ( a ) { for ( var b = $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "NAME" ) , $ . module$exports$Blockly$Names . NameType . PROCEDURE ) , c = [ ] , d = a . getVars ( ) , e = 0 ; e < d . length ; e ++ ) c [ e ] = $ . Blockly . Python . valueToCode ( a , "ARG" + e , $ . Blockly . Python . ORDER _NONE ) || "None" ; return [ b + "(" + c . join ( ", " ) + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . procedures _callnoreturn = function ( a ) { return $ . Blockly . Python . procedures _callreturn ( a ) [ 0 ] + "\n" } ;
$ . Blockly . Python . procedures _ifreturn = function ( a ) { var b = "if " + ( $ . Blockly . Python . valueToCode ( a , "CONDITION" , $ . Blockly . Python . ORDER _NONE ) || "False" ) + ":\n" ; $ . Blockly . Python . STATEMENT _SUFFIX && ( b += $ . Blockly . Python . prefixLines ( $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _SUFFIX , a ) , $ . Blockly . Python . INDENT ) ) ; a . hasReturnValue _ ? ( a = $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "None" , b += $ . Blockly . Python . INDENT + "return " + a + "\n" ) : b += $ . Blockly . Python . INDENT + "return\n" ; return b } ; var module$exports$Blockly$Python$math = { } ; $ . Blockly . Python . addReservedWords ( "math,random,Number" ) ; $ . Blockly . Python . math _number = function ( a ) { a = Number ( a . getFieldValue ( "NUM" ) ) ; if ( Infinity === a ) { a = 'float("inf")' ; var b = $ . Blockly . Python . ORDER _FUNCTION _CALL } else - Infinity === a ? ( a = '-float("inf")' , b = $ . Blockly . Python . ORDER _UNARY _SIGN ) : b = 0 > a ? $ . Blockly . Python . ORDER _UNARY _SIGN : $ . Blockly . Python . ORDER _ATOMIC ; return [ a , b ] } ;
$ . Blockly . Python . math _arithmetic = function ( a ) { var b = { ADD : [ " + " , $ . Blockly . Python . ORDER _ADDITIVE ] , MINUS : [ " - " , $ . Blockly . Python . ORDER _ADDITIVE ] , MULTIPLY : [ " * " , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] , DIVIDE : [ " / " , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] , POWER : [ " ** " , $ . Blockly . Python . ORDER _EXPONENTIATION ] } [ a . getFieldValue ( "OP" ) ] , c = b [ 0 ] ; b = b [ 1 ] ; var d = $ . Blockly . Python . valueToCode ( a , "A" , b ) || "0" ; a = $ . Blockly . Python . valueToCode ( a , "B" , b ) || "0" ; return [ d + c + a , b ] } ;
$ . Blockly . Python . math _single = function ( a ) { var b = a . getFieldValue ( "OP" ) ; if ( "NEG" === b ) { var c = $ . Blockly . Python . valueToCode ( a , "NUM" , $ . Blockly . Python . ORDER _UNARY _SIGN ) || "0" ; return [ "-" + c , $ . Blockly . Python . ORDER _UNARY _SIGN ] } $ . Blockly . Python . definitions _ . import _math = "import math" ; a = "SIN" === b || "COS" === b || "TAN" === b ? $ . Blockly . Python . valueToCode ( a , "NUM" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ) || "0" : $ . Blockly . Python . valueToCode ( a , "NUM" , $ . Blockly . Python . ORDER _NONE ) || "0" ; switch ( b ) { case "ABS" : c = "math.fabs(" + a + ")" ; break ;
case "ROOT" : c = "math.sqrt(" + a + ")" ; break ; case "LN" : c = "math.log(" + a + ")" ; break ; case "LOG10" : c = "math.log10(" + a + ")" ; break ; case "EXP" : c = "math.exp(" + a + ")" ; break ; case "POW10" : c = "math.pow(10," + a + ")" ; break ; case "ROUND" : c = "round(" + a + ")" ; break ; case "ROUNDUP" : c = "math.ceil(" + a + ")" ; break ; case "ROUNDDOWN" : c = "math.floor(" + a + ")" ; break ; case "SIN" : c = "math.sin(" + a + " / 180.0 * math.pi)" ; break ; case "COS" : c = "math.cos(" + a + " / 180.0 * math.pi)" ; break ; case "TAN" : c = "math.tan(" + a + " / 180.0 * math.pi)" } if ( c ) return [ c , $ . Blockly . Python . ORDER _FUNCTION _CALL ] ;
switch ( b ) { case "ASIN" : c = "math.asin(" + a + ") / math.pi * 180" ; break ; case "ACOS" : c = "math.acos(" + a + ") / math.pi * 180" ; break ; case "ATAN" : c = "math.atan(" + a + ") / math.pi * 180" ; break ; default : throw Error ( "Unknown math operator: " + b ) ; } return [ c , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] } ;
$ . Blockly . Python . math _constant = function ( a ) { var b = { PI : [ "math.pi" , $ . Blockly . Python . ORDER _MEMBER ] , E : [ "math.e" , $ . Blockly . Python . ORDER _MEMBER ] , GOLDEN _RATIO : [ "(1 + math.sqrt(5)) / 2" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] , SQRT2 : [ "math.sqrt(2)" , $ . Blockly . Python . ORDER _MEMBER ] , SQRT1 _2 : [ "math.sqrt(1.0 / 2)" , $ . Blockly . Python . ORDER _MEMBER ] , INFINITY : [ "float('inf')" , $ . Blockly . Python . ORDER _ATOMIC ] } ; a = a . getFieldValue ( "CONSTANT" ) ; "INFINITY" !== a && ( $ . Blockly . Python . definitions _ . import _math = "import math" ) ; return b [ a ] } ;
2022-06-07 11:14:29 +00:00
$ . Blockly . Python . math _number _property = function ( a ) { var b = { EVEN : [ " % 2 == 0" , $ . Blockly . Python . ORDER _MULTIPLICATIVE , $ . Blockly . Python . ORDER _RELATIONAL ] , ODD : [ " % 2 == 1" , $ . Blockly . Python . ORDER _MULTIPLICATIVE , $ . Blockly . Python . ORDER _RELATIONAL ] , WHOLE : [ " % 1 == 0" , $ . Blockly . Python . ORDER _MULTIPLICATIVE , $ . Blockly . Python . ORDER _RELATIONAL ] , POSITIVE : [ " > 0" , $ . Blockly . Python . ORDER _RELATIONAL , $ . Blockly . Python . ORDER _RELATIONAL ] , NEGATIVE : [ " < 0" , $ . Blockly . Python . ORDER _RELATIONAL , $ . Blockly . Python . ORDER _RELATIONAL ] ,
DIVISIBLE _BY : [ null , $ . Blockly . Python . ORDER _MULTIPLICATIVE , $ . Blockly . Python . ORDER _RELATIONAL ] , PRIME : [ null , $ . Blockly . Python . ORDER _NONE , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } , c = a . getFieldValue ( "PROPERTY" ) ; b = $ . $jscomp . makeIterator ( b [ c ] ) ; var d = b . next ( ) . value , e = b . next ( ) . value ; b = b . next ( ) . value ; e = $ . Blockly . Python . valueToCode ( a , "NUMBER_TO_CHECK" , e ) || "0" ; if ( "PRIME" === c ) $ . Blockly . Python . definitions _ . import _math = "import math" , $ . Blockly . Python . definitions _ . from _numbers _import _Number = "from numbers import Number" ,
a = $ . Blockly . Python . provideFunction _ ( "math_isPrime" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(n):\n # https://en.wikipedia.org/wiki/Primality_test#Naive_methods\n # If n is not a number but a string, try parsing it.\n if not isinstance(n, Number):\n try:\n n = float(n)\n except:\n return False\n if n == 2 or n == 3:\n return True\n # False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3.\n if n <= 1 or n % 1 != 0 or n % 2 == 0 or n % 3 == 0:\n return False\n # Check all the numbers of form 6k +/- 1, up to sqrt(n).\n for x in range(6, int(math.sqrt(n)) + 2, 6):\n if n % (x - 1) == 0 or n % (x + 1) == 0:\n return False\n return True\n" ) +
"(" + e + ")" ; else if ( "DIVISIBLE_BY" === c ) { a = $ . Blockly . Python . valueToCode ( a , "DIVISOR" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ) || "0" ; if ( "0" === a ) return [ "False" , $ . Blockly . Python . ORDER _ATOMIC ] ; a = e + " % " + a + " == 0" } else a = e + d ; return [ a , b ] } ;
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . math _change = function ( a ) { $ . Blockly . Python . definitions _ . from _numbers _import _Number = "from numbers import Number" ; var b = $ . Blockly . Python . valueToCode ( a , "DELTA" , $ . Blockly . Python . ORDER _ADDITIVE ) || "0" ; a = $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "VAR" ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ; return a + " = (" + a + " if isinstance(" + a + ", Number) else 0) + " + b + "\n" } ; $ . Blockly . Python . math _round = $ . Blockly . Python . math _single ; $ . Blockly . Python . math _trig = $ . Blockly . Python . math _single ;
2022-06-07 11:14:29 +00:00
$ . Blockly . Python . math _on _list = function ( a ) { var b = a . getFieldValue ( "OP" ) ; a = $ . Blockly . Python . valueToCode ( a , "LIST" , $ . Blockly . Python . ORDER _NONE ) || "[]" ; switch ( b ) { case "SUM" : b = "sum(" + a + ")" ; break ; case "MIN" : b = "min(" + a + ")" ; break ; case "MAX" : b = "max(" + a + ")" ; break ; case "AVERAGE" : $ . Blockly . Python . definitions _ . from _numbers _import _Number = "from numbers import Number" ; b = $ . Blockly . Python . provideFunction _ ( "math_mean" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(myList):\n localList = [e for e in myList if isinstance(e, Number)]\n if not localList: return\n return float(sum(localList)) / len(localList)\n" ) +
"(" + a + ")" ; break ; case "MEDIAN" : $ . Blockly . Python . definitions _ . from _numbers _import _Number = "from numbers import Number" ; b = $ . Blockly . Python . provideFunction _ ( "math_median" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(myList):\n localList = sorted([e for e in myList if isinstance(e, Number)])\n if not localList: return\n if len(localList) % 2 == 0:\n return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0\n else:\n return localList[(len(localList) - 1) // 2]\n" ) +
"(" + a + ")" ; break ; case "MODE" : b = $ . Blockly . Python . provideFunction _ ( "math_modes" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + '(some_list):\n modes = []\n # Using a lists of [item, count] to keep count rather than dict\n # to avoid "unhashable" errors when the counted item is itself a list or dict.\n counts = []\n maxCount = 1\n for item in some_list:\n found = False\n for count in counts:\n if count[0] == item:\n count[1] += 1\n maxCount = max(maxCount, count[1])\n found = True\n if not found:\n counts.append([item, 1])\n for counted_item, item_count in counts:\n if item_count == maxCount:\n modes.append(counted_item)\n return modes\n' ) +
"(" + a + ")" ; break ; case "STD_DEV" : $ . Blockly . Python . definitions _ . import _math = "import math" ; b = $ . Blockly . Python . provideFunction _ ( "math_standard_deviation" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(numbers):\n n = len(numbers)\n if n == 0: return\n mean = float(sum(numbers)) / n\n variance = sum((x - mean) ** 2 for x in numbers) / n\n return math.sqrt(variance)\n" ) + "(" + a + ")" ; break ; case "RANDOM" : $ . Blockly . Python . definitions _ . import _random = "import random" ; b = "random.choice(" + a + ")" ; break ; default : throw Error ( "Unknown operator: " +
b ) ; } return [ b , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ; $ . Blockly . Python . math _modulo = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "DIVIDEND" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ) || "0" ; a = $ . Blockly . Python . valueToCode ( a , "DIVISOR" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ) || "0" ; return [ b + " % " + a , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] } ;
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . math _constrain = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "0" , c = $ . Blockly . Python . valueToCode ( a , "LOW" , $ . Blockly . Python . ORDER _NONE ) || "0" ; a = $ . Blockly . Python . valueToCode ( a , "HIGH" , $ . Blockly . Python . ORDER _NONE ) || "float('inf')" ; return [ "min(max(" + b + ", " + c + "), " + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . math _random _int = function ( a ) { $ . Blockly . Python . definitions _ . import _random = "import random" ; var b = $ . Blockly . Python . valueToCode ( a , "FROM" , $ . Blockly . Python . ORDER _NONE ) || "0" ; a = $ . Blockly . Python . valueToCode ( a , "TO" , $ . Blockly . Python . ORDER _NONE ) || "0" ; return [ "random.randint(" + b + ", " + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ; $ . Blockly . Python . math _random _float = function ( a ) { $ . Blockly . Python . definitions _ . import _random = "import random" ; return [ "random.random()" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . math _atan2 = function ( a ) { $ . Blockly . Python . definitions _ . import _math = "import math" ; var b = $ . Blockly . Python . valueToCode ( a , "X" , $ . Blockly . Python . ORDER _NONE ) || "0" ; return [ "math.atan2(" + ( $ . Blockly . Python . valueToCode ( a , "Y" , $ . Blockly . Python . ORDER _NONE ) || "0" ) + ", " + b + ") / math.pi * 180" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] } ; var module$exports$Blockly$Python$loops = { } ;
$ . Blockly . Python . controls _repeat _ext = function ( a ) { var b = a . getField ( "TIMES" ) ? String ( parseInt ( a . getFieldValue ( "TIMES" ) , 10 ) ) : $ . Blockly . Python . valueToCode ( a , "TIMES" , $ . Blockly . Python . ORDER _NONE ) || "0" ; b = ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( b ) ? parseInt ( b , 10 ) : "int(" + b + ")" ; var c = $ . Blockly . Python . statementToCode ( a , "DO" ) ; c = $ . Blockly . Python . addLoopTrap ( c , a ) || $ . Blockly . Python . PASS ; return "for " + $ . Blockly . Python . nameDB _ . getDistinctName ( "count" , $ . module$exports$Blockly$Names . NameType . VARIABLE ) + " in range(" +
b + "):\n" + c } ; $ . Blockly . Python . controls _repeat = $ . Blockly . Python . controls _repeat _ext ; $ . Blockly . Python . controls _whileUntil = function ( a ) { var b = "UNTIL" === a . getFieldValue ( "MODE" ) , c = $ . Blockly . Python . valueToCode ( a , "BOOL" , b ? $ . Blockly . Python . ORDER _LOGICAL _NOT : $ . Blockly . Python . ORDER _NONE ) || "False" , d = $ . Blockly . Python . statementToCode ( a , "DO" ) ; d = $ . Blockly . Python . addLoopTrap ( d , a ) || $ . Blockly . Python . PASS ; b && ( c = "not " + c ) ; return "while " + c + ":\n" + d } ;
$ . Blockly . Python . controls _for = function ( a ) { var b = $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "VAR" ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) , c = $ . Blockly . Python . valueToCode ( a , "FROM" , $ . Blockly . Python . ORDER _NONE ) || "0" , d = $ . Blockly . Python . valueToCode ( a , "TO" , $ . Blockly . Python . ORDER _NONE ) || "0" , e = $ . Blockly . Python . valueToCode ( a , "BY" , $ . Blockly . Python . ORDER _NONE ) || "1" , f = $ . Blockly . Python . statementToCode ( a , "DO" ) ; f = $ . Blockly . Python . addLoopTrap ( f , a ) || $ . Blockly . Python . PASS ; var g = "" ; a = function ( ) { return $ . Blockly . Python . provideFunction _ ( "upRange" ,
2022-06-07 11:14:29 +00:00
"\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(start, stop, step):\n while start <= stop:\n yield start\n start += abs(step)\n" ) } ; var h = function ( ) { return $ . Blockly . Python . provideFunction _ ( "downRange" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(start, stop, step):\n while start >= stop:\n yield start\n start -= abs(step)\n" ) } ; if ( ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( c ) && ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( d ) && ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( e ) ) c =
2022-01-03 14:02:41 +00:00
Number ( c ) , d = Number ( d ) , e = Math . abs ( Number ( e ) ) , 0 === c % 1 && 0 === d % 1 && 0 === e % 1 ? ( c <= d ? ( d ++ , a = 0 === c && 1 === e ? d : c + ", " + d , 1 !== e && ( a += ", " + e ) ) : ( d -- , a = c + ", " + d + ", -" + e ) , a = "range(" + a + ")" ) : ( a = c < d ? a ( ) : h ( ) , a += "(" + c + ", " + d + ", " + e + ")" ) ; else { var k = function ( l , m ) { ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( l ) ? l = Number ( l ) : l . match ( /^\w+$/ ) ? l = "float(" + l + ")" : ( m = $ . Blockly . Python . nameDB _ . getDistinctName ( b + m , $ . module$exports$Blockly$Names . NameType . VARIABLE ) , g += m + " = float(" + l + ")\n" , l = m ) ; return l } ; c = k ( c , "_start" ) ; d = k ( d , "_end" ) ;
e = k ( e , "_inc" ) ; "number" === typeof c && "number" === typeof d ? ( a = c < d ? a ( ) : h ( ) , a += "(" + c + ", " + d + ", " + e + ")" ) : a = "(" + c + " <= " + d + ") and " + a ( ) + "(" + c + ", " + d + ", " + e + ") or " + h ( ) + "(" + c + ", " + d + ", " + e + ")" } return g += "for " + b + " in " + a + ":\n" + f } ;
$ . Blockly . Python . controls _forEach = function ( a ) { var b = $ . Blockly . Python . nameDB _ . getName ( a . getFieldValue ( "VAR" ) , $ . module$exports$Blockly$Names . NameType . VARIABLE ) , c = $ . Blockly . Python . valueToCode ( a , "LIST" , $ . Blockly . Python . ORDER _RELATIONAL ) || "[]" , d = $ . Blockly . Python . statementToCode ( a , "DO" ) ; d = $ . Blockly . Python . addLoopTrap ( d , a ) || $ . Blockly . Python . PASS ; return "for " + b + " in " + c + ":\n" + d } ;
$ . Blockly . Python . controls _flow _statements = function ( a ) { var b = "" ; $ . Blockly . Python . STATEMENT _PREFIX && ( b += $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _PREFIX , a ) ) ; $ . Blockly . Python . STATEMENT _SUFFIX && ( b += $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _SUFFIX , a ) ) ; if ( $ . Blockly . Python . STATEMENT _PREFIX ) { var c = a . getSurroundLoop ( ) ; c && ! c . suppressPrefixSuffix && ( b += $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _PREFIX , c ) ) } switch ( a . getFieldValue ( "FLOW" ) ) { case "BREAK" : return b + "break\n" ; case "CONTINUE" : return b +
"continue\n" } throw Error ( "Unknown flow statement." ) ; } ; var module$exports$Blockly$Python$logic = { } ;
$ . Blockly . Python . controls _if = function ( a ) { var b = 0 , c = "" ; $ . Blockly . Python . STATEMENT _PREFIX && ( c += $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _PREFIX , a ) ) ; do { var d = $ . Blockly . Python . valueToCode ( a , "IF" + b , $ . Blockly . Python . ORDER _NONE ) || "False" ; var e = $ . Blockly . Python . statementToCode ( a , "DO" + b ) || $ . Blockly . Python . PASS ; $ . Blockly . Python . STATEMENT _SUFFIX && ( e = $ . Blockly . Python . prefixLines ( $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _SUFFIX , a ) , $ . Blockly . Python . INDENT ) + e ) ; c += ( 0 === b ? "if " : "elif " ) + d + ":\n" +
e ; b ++ } while ( a . getInput ( "IF" + b ) ) ; if ( a . getInput ( "ELSE" ) || $ . Blockly . Python . STATEMENT _SUFFIX ) e = $ . Blockly . Python . statementToCode ( a , "ELSE" ) || $ . Blockly . Python . PASS , $ . Blockly . Python . STATEMENT _SUFFIX && ( e = $ . Blockly . Python . prefixLines ( $ . Blockly . Python . injectId ( $ . Blockly . Python . STATEMENT _SUFFIX , a ) , $ . Blockly . Python . INDENT ) + e ) , c += "else:\n" + e ; return c } ; $ . Blockly . Python . controls _ifelse = $ . Blockly . Python . controls _if ;
$ . Blockly . Python . logic _compare = function ( a ) { var b = { EQ : "==" , NEQ : "!=" , LT : "<" , LTE : "<=" , GT : ">" , GTE : ">=" } [ a . getFieldValue ( "OP" ) ] , c = $ . Blockly . Python . ORDER _RELATIONAL , d = $ . Blockly . Python . valueToCode ( a , "A" , c ) || "0" ; a = $ . Blockly . Python . valueToCode ( a , "B" , c ) || "0" ; return [ d + " " + b + " " + a , c ] } ;
$ . Blockly . Python . logic _operation = function ( a ) { var b = "AND" === a . getFieldValue ( "OP" ) ? "and" : "or" , c = "and" === b ? $ . Blockly . Python . ORDER _LOGICAL _AND : $ . Blockly . Python . ORDER _LOGICAL _OR , d = $ . Blockly . Python . valueToCode ( a , "A" , c ) ; a = $ . Blockly . Python . valueToCode ( a , "B" , c ) ; if ( d || a ) { var e = "and" === b ? "True" : "False" ; d || ( d = e ) ; a || ( a = e ) } else a = d = "False" ; return [ d + " " + b + " " + a , c ] } ; $ . Blockly . Python . logic _negate = function ( a ) { return [ "not " + ( $ . Blockly . Python . valueToCode ( a , "BOOL" , $ . Blockly . Python . ORDER _LOGICAL _NOT ) || "True" ) , $ . Blockly . Python . ORDER _LOGICAL _NOT ] } ;
$ . Blockly . Python . logic _boolean = function ( a ) { return [ "TRUE" === a . getFieldValue ( "BOOL" ) ? "True" : "False" , $ . Blockly . Python . ORDER _ATOMIC ] } ; $ . Blockly . Python . logic _null = function ( a ) { return [ "None" , $ . Blockly . Python . ORDER _ATOMIC ] } ;
$ . Blockly . Python . logic _ternary = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "IF" , $ . Blockly . Python . ORDER _CONDITIONAL ) || "False" , c = $ . Blockly . Python . valueToCode ( a , "THEN" , $ . Blockly . Python . ORDER _CONDITIONAL ) || "None" ; a = $ . Blockly . Python . valueToCode ( a , "ELSE" , $ . Blockly . Python . ORDER _CONDITIONAL ) || "None" ; return [ c + " if " + b + " else " + a , $ . Blockly . Python . ORDER _CONDITIONAL ] } ; var module$exports$Blockly$Python$lists = { } ; $ . Blockly . Python . lists _create _empty = function ( a ) { return [ "[]" , $ . Blockly . Python . ORDER _ATOMIC ] } ; $ . Blockly . Python . lists _create _with = function ( a ) { for ( var b = Array ( a . itemCount _ ) , c = 0 ; c < a . itemCount _ ; c ++ ) b [ c ] = $ . Blockly . Python . valueToCode ( a , "ADD" + c , $ . Blockly . Python . ORDER _NONE ) || "None" ; return [ "[" + b . join ( ", " ) + "]" , $ . Blockly . Python . ORDER _ATOMIC ] } ;
$ . Blockly . Python . lists _repeat = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "ITEM" , $ . Blockly . Python . ORDER _NONE ) || "None" ; a = $ . Blockly . Python . valueToCode ( a , "NUM" , $ . Blockly . Python . ORDER _MULTIPLICATIVE ) || "0" ; return [ "[" + b + "] * " + a , $ . Blockly . Python . ORDER _MULTIPLICATIVE ] } ; $ . Blockly . Python . lists _length = function ( a ) { return [ "len(" + ( $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "[]" ) + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . lists _isEmpty = function ( a ) { return [ "not len(" + ( $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "[]" ) + ")" , $ . Blockly . Python . ORDER _LOGICAL _NOT ] } ;
2022-06-07 11:14:29 +00:00
$ . Blockly . Python . lists _indexOf = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "FIND" , $ . Blockly . Python . ORDER _NONE ) || "[]" , c = $ . Blockly . Python . valueToCode ( a , "VALUE" , $ . Blockly . Python . ORDER _NONE ) || "''" , d = " -1" , e = "" , f = " - 1" ; a . workspace . options . oneBasedIndex && ( d = " 0" , e = " + 1" , f = "" ) ; return [ ( "FIRST" === a . getFieldValue ( "END" ) ? $ . Blockly . Python . provideFunction _ ( "first_index" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(my_list, elem):\n try: index = my_list.index(elem)" + e + "\n except: index =" + d +
"\n return index\n" ) : $ . Blockly . Python . provideFunction _ ( "last_index" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(my_list, elem):\n try: index = len(my_list) - my_list[::-1].index(elem)" + f + "\n except: index =" + d + "\n return index\n" ) ) + "(" + c + ", " + b + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . lists _getIndex = function ( a ) { var b = a . getFieldValue ( "MODE" ) || "GET" , c = a . getFieldValue ( "WHERE" ) || "FROM_START" , d = $ . Blockly . Python . valueToCode ( a , "VALUE" , "RANDOM" === c ? $ . Blockly . Python . ORDER _NONE : $ . Blockly . Python . ORDER _MEMBER ) || "[]" ; switch ( c ) { case "FIRST" : if ( "GET" === b ) return [ d + "[0]" , $ . Blockly . Python . ORDER _MEMBER ] ; if ( "GET_REMOVE" === b ) return [ d + ".pop(0)" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] ; if ( "REMOVE" === b ) return d + ".pop(0)\n" ; break ; case "LAST" : if ( "GET" === b ) return [ d + "[-1]" , $ . Blockly . Python . ORDER _MEMBER ] ;
if ( "GET_REMOVE" === b ) return [ d + ".pop()" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] ; if ( "REMOVE" === b ) return d + ".pop()\n" ; break ; case "FROM_START" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT" ) ; if ( "GET" === b ) return [ d + "[" + a + "]" , $ . Blockly . Python . ORDER _MEMBER ] ; if ( "GET_REMOVE" === b ) return [ d + ".pop(" + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] ; if ( "REMOVE" === b ) return d + ".pop(" + a + ")\n" ; break ; case "FROM_END" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT" , 1 , ! 0 ) ; if ( "GET" === b ) return [ d + "[" + a + "]" , $ . Blockly . Python . ORDER _MEMBER ] ; if ( "GET_REMOVE" ===
2022-06-07 11:14:29 +00:00
b ) return [ d + ".pop(" + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] ; if ( "REMOVE" === b ) return d + ".pop(" + a + ")\n" ; break ; case "RANDOM" : $ . Blockly . Python . definitions _ . import _random = "import random" ; if ( "GET" === b ) return [ "random.choice(" + d + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] ; d = $ . Blockly . Python . provideFunction _ ( "lists_remove_random_item" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(myList):\n x = int(random.random() * len(myList))\n return myList.pop(x)\n" ) + "(" + d + ")" ; if ( "GET_REMOVE" === b ) return [ d ,
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . ORDER _FUNCTION _CALL ] ; if ( "REMOVE" === b ) return d + "\n" } throw Error ( "Unhandled combination (lists_getIndex)." ) ; } ;
$ . Blockly . Python . lists _setIndex = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "LIST" , $ . Blockly . Python . ORDER _MEMBER ) || "[]" , c = a . getFieldValue ( "MODE" ) || "GET" , d = a . getFieldValue ( "WHERE" ) || "FROM_START" , e = $ . Blockly . Python . valueToCode ( a , "TO" , $ . Blockly . Python . ORDER _NONE ) || "None" ; switch ( d ) { case "FIRST" : if ( "SET" === c ) return b + "[0] = " + e + "\n" ; if ( "INSERT" === c ) return b + ".insert(0, " + e + ")\n" ; break ; case "LAST" : if ( "SET" === c ) return b + "[-1] = " + e + "\n" ; if ( "INSERT" === c ) return b + ".append(" + e + ")\n" ; break ; case "FROM_START" : a =
$ . Blockly . Python . getAdjustedInt ( a , "AT" ) ; if ( "SET" === c ) return b + "[" + a + "] = " + e + "\n" ; if ( "INSERT" === c ) return b + ".insert(" + a + ", " + e + ")\n" ; break ; case "FROM_END" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT" , 1 , ! 0 ) ; if ( "SET" === c ) return b + "[" + a + "] = " + e + "\n" ; if ( "INSERT" === c ) return b + ".insert(" + a + ", " + e + ")\n" ; break ; case "RANDOM" : $ . Blockly . Python . definitions _ . import _random = "import random" ; b . match ( /^\w+$/ ) ? a = "" : ( a = $ . Blockly . Python . nameDB _ . getDistinctName ( "tmp_list" , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ,
d = a + " = " + b + "\n" , b = a , a = d ) ; d = $ . Blockly . Python . nameDB _ . getDistinctName ( "tmp_x" , $ . module$exports$Blockly$Names . NameType . VARIABLE ) ; a += d + " = int(random.random() * len(" + b + "))\n" ; if ( "SET" === c ) return a + ( b + "[" + d + "] = " + e + "\n" ) ; if ( "INSERT" === c ) return a + ( b + ".insert(" + d + ", " + e + ")\n" ) } throw Error ( "Unhandled combination (lists_setIndex)." ) ; } ;
$ . Blockly . Python . lists _getSublist = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "LIST" , $ . Blockly . Python . ORDER _MEMBER ) || "[]" , c = a . getFieldValue ( "WHERE1" ) , d = a . getFieldValue ( "WHERE2" ) ; switch ( c ) { case "FROM_START" : c = $ . Blockly . Python . getAdjustedInt ( a , "AT1" ) ; 0 === c && ( c = "" ) ; break ; case "FROM_END" : c = $ . Blockly . Python . getAdjustedInt ( a , "AT1" , 1 , ! 0 ) ; break ; case "FIRST" : c = "" ; break ; default : throw Error ( "Unhandled option (lists_getSublist)" ) ; } switch ( d ) { case "FROM_START" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT2" , 1 ) ;
break ; case "FROM_END" : a = $ . Blockly . Python . getAdjustedInt ( a , "AT2" , 0 , ! 0 ) ; ( 0 , $ . module$exports$Blockly$utils$string . isNumber ) ( String ( a ) ) ? 0 === a && ( a = "" ) : ( $ . Blockly . Python . definitions _ . import _sys = "import sys" , a += " or sys.maxsize" ) ; break ; case "LAST" : a = "" ; break ; default : throw Error ( "Unhandled option (lists_getSublist)" ) ; } return [ b + "[" + c + " : " + a + "]" , $ . Blockly . Python . ORDER _MEMBER ] } ;
2022-06-07 11:14:29 +00:00
$ . Blockly . Python . lists _sort = function ( a ) { var b = $ . Blockly . Python . valueToCode ( a , "LIST" , $ . Blockly . Python . ORDER _NONE ) || "[]" , c = a . getFieldValue ( "TYPE" ) ; a = "1" === a . getFieldValue ( "DIRECTION" ) ? "False" : "True" ; return [ $ . Blockly . Python . provideFunction _ ( "lists_sort" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + '(my_list, type, reverse):\n def try_float(s):\n try:\n return float(s)\n except:\n return 0\n key_funcs = {\n "NUMERIC": try_float,\n "TEXT": str,\n "IGNORE_CASE": lambda s: str(s).lower()\n }\n key_func = key_funcs[type]\n list_cpy = list(my_list)\n return sorted(list_cpy, key=key_func, reverse=reverse)\n' ) +
"(" + b + ', "' + c + '", ' + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
2022-01-03 14:02:41 +00:00
$ . Blockly . Python . lists _split = function ( a ) { var b = a . getFieldValue ( "MODE" ) ; if ( "SPLIT" === b ) b = $ . Blockly . Python . valueToCode ( a , "INPUT" , $ . Blockly . Python . ORDER _MEMBER ) || "''" , a = $ . Blockly . Python . valueToCode ( a , "DELIM" , $ . Blockly . Python . ORDER _NONE ) , a = b + ".split(" + a + ")" ; else if ( "JOIN" === b ) b = $ . Blockly . Python . valueToCode ( a , "INPUT" , $ . Blockly . Python . ORDER _NONE ) || "[]" , a = ( $ . Blockly . Python . valueToCode ( a , "DELIM" , $ . Blockly . Python . ORDER _MEMBER ) || "''" ) + ".join(" + b + ")" ; else throw Error ( "Unknown mode: " + b ) ; return [ a , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . lists _reverse = function ( a ) { return [ "list(reversed(" + ( $ . Blockly . Python . valueToCode ( a , "LIST" , $ . Blockly . Python . ORDER _NONE ) || "[]" ) + "))" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ; var module$exports$Blockly$Python$colour = { } ; $ . Blockly . Python . colour _picker = function ( a ) { return [ $ . Blockly . Python . quote _ ( a . getFieldValue ( "COLOUR" ) ) , $ . Blockly . Python . ORDER _ATOMIC ] } ; $ . Blockly . Python . colour _random = function ( a ) { $ . Blockly . Python . definitions _ . import _random = "import random" ; return [ "'#%06x' % random.randint(0, 2**24 - 1)" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
2022-06-07 11:14:29 +00:00
$ . Blockly . Python . colour _rgb = function ( a ) { var b = $ . Blockly . Python . provideFunction _ ( "colour_rgb" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(r, g, b):\n r = round(min(100, max(0, r)) * 2.55)\n g = round(min(100, max(0, g)) * 2.55)\n b = round(min(100, max(0, b)) * 2.55)\n return '#%02x%02x%02x' % (r, g, b)\n" ) , c = $ . Blockly . Python . valueToCode ( a , "RED" , $ . Blockly . Python . ORDER _NONE ) || 0 , d = $ . Blockly . Python . valueToCode ( a , "GREEN" , $ . Blockly . Python . ORDER _NONE ) || 0 ; a = $ . Blockly . Python . valueToCode ( a , "BLUE" ,
$ . Blockly . Python . ORDER _NONE ) || 0 ; return [ b + "(" + c + ", " + d + ", " + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ;
$ . Blockly . Python . colour _blend = function ( a ) { var b = $ . Blockly . Python . provideFunction _ ( "colour_blend" , "\ndef " + $ . Blockly . Python . FUNCTION _NAME _PLACEHOLDER _ + "(colour1, colour2, ratio):\n r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)\n g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)\n b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)\n ratio = min(1, max(0, ratio))\n r = round(r1 * (1 - ratio) + r2 * ratio)\n g = round(g1 * (1 - ratio) + g2 * ratio)\n b = round(b1 * (1 - ratio) + b2 * ratio)\n return '#%02x%02x%02x' % (r, g, b)\n" ) , c =
$ . Blockly . Python . valueToCode ( a , "COLOUR1" , $ . Blockly . Python . ORDER _NONE ) || "'#000000'" , d = $ . Blockly . Python . valueToCode ( a , "COLOUR2" , $ . Blockly . Python . ORDER _NONE ) || "'#000000'" ; a = $ . Blockly . Python . valueToCode ( a , "RATIO" , $ . Blockly . Python . ORDER _NONE ) || 0 ; return [ b + "(" + c + ", " + d + ", " + a + ")" , $ . Blockly . Python . ORDER _FUNCTION _CALL ] } ; var module$exports$Blockly$Python$all = { } ;
$ . Blockly . Python . _ _namespace _ _ = $ ;
2022-01-03 14:02:41 +00:00
return $ . Blockly . Python ;
2021-08-28 14:28:26 +00:00
} ) ) ;
//# sourceMappingURL=python_compressed.js.map