// Do not edit this file; automatically generated by build.py.
'use strict';


// Copyright 2012 Google Inc.  Apache License 2.0
Blockly.Pseudo=new Blockly.Generator("Pseudo");Blockly.Pseudo.addReservedWords("and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,not,or,pass,print,raise,return,try,while,with,yield,True,False,None,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,crime,stocks,earthquakes,books,weather,plt,math,abs,divmod,input,open,staticmethod,all,enumerate,int,ord,str,any,eval,isinstance,pow,sum,basestring,execfile,issubclass,print,super,bin,file,iter,property,tuple,bool,filter,len,range,type,bytearray,float,list,raw_input,unichr,callable,format,locals,reduce,unicode,chr,frozenset,long,reload,vars,classmethod,getattr,map,repr,xrange,cmp,globals,max,reversed,zip,compile,hasattr,memoryview,round,__import__,complex,hash,min,set,apply,delattr,help,next,setattr,buffer,dict,hex,object,slice,coerce,dir,id,oct,sorted,intern");
Blockly.Pseudo.ORDER_ATOMIC=0;Blockly.Pseudo.ORDER_COLLECTION=1;Blockly.Pseudo.ORDER_STRING_CONVERSION=1;Blockly.Pseudo.ORDER_MEMBER=2;Blockly.Pseudo.ORDER_FUNCTION_CALL=2;Blockly.Pseudo.ORDER_EXPONENTIATION=3;Blockly.Pseudo.ORDER_UNARY_SIGN=4;Blockly.Pseudo.ORDER_BITWISE_NOT=4;Blockly.Pseudo.ORDER_MULTIPLICATIVE=5;Blockly.Pseudo.ORDER_ADDITIVE=6;Blockly.Pseudo.ORDER_BITWISE_SHIFT=7;Blockly.Pseudo.ORDER_BITWISE_AND=8;Blockly.Pseudo.ORDER_BITWISE_XOR=9;Blockly.Pseudo.ORDER_BITWISE_OR=10;
Blockly.Pseudo.ORDER_RELATIONAL=11;Blockly.Pseudo.ORDER_LOGICAL_NOT=12;Blockly.Pseudo.ORDER_LOGICAL_AND=13;Blockly.Pseudo.ORDER_LOGICAL_OR=14;Blockly.Pseudo.ORDER_CONDITIONAL=15;Blockly.Pseudo.ORDER_LAMBDA=16;Blockly.Pseudo.ORDER_NONE=99;Blockly.Pseudo.PASS="    Do nothing.\n";Blockly.Pseudo.init=function(a){Blockly.Pseudo.definitions_=Object.create(null);Blockly.Pseudo.functionNames_=Object.create(null);Blockly.Pseudo.variableDB_?Blockly.Pseudo.variableDB_.reset():Blockly.Pseudo.variableDB_=new Blockly.Names(Blockly.Pseudo.RESERVED_WORDS_)};
Blockly.Pseudo.finish=function(a){var b=[],c=[],d;for(d in Blockly.Pseudo.definitions_){var e=Blockly.Pseudo.definitions_[d];e.match(/^(from\s+\S+\s+)?import\s+\S+/)?b.push(e):c.push(e)}delete Blockly.Pseudo.definitions_;delete Blockly.Pseudo.functionNames_;Blockly.Pseudo.variableDB_.reset();return(b.join("\n")+"\n"+c.join("\n\n")).replace(/\n\n+/g,"\n").replace(/\n*$/,"\n\n")+a};Blockly.Pseudo.scrubNakedValue=function(a){return a+"\n"};
Blockly.Pseudo.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n");if(-1<a.indexOf('"')&&-1==a.indexOf('"'))return"'"+a+"'";-1==a.indexOf('"')&&-1<a.indexOf('"')||(a=a.replace(/"/g,'\\"'));return'"'+a+'"'};
Blockly.Pseudo.scrub_=function(a,b){var c="";if(!a.outputConnection||!a.outputConnection.targetConnection){var d=a.getCommentText();d&&(c+=Blockly.Pseudo.prefixLines(d,"# ")+"\n");for(var e=0;e<a.inputList.length;e++)a.inputList[e].type==Blockly.INPUT_VALUE&&(d=a.inputList[e].connection.targetBlock())&&(d=Blockly.Pseudo.allNestedComments(d))&&(c+=Blockly.Pseudo.prefixLines(d,"# "))}e=a.nextConnection&&a.nextConnection.targetBlock();e=Blockly.Pseudo.blockToCode(e);return c+b+e};Blockly.Pseudo.colour={};Blockly.Pseudo.colour_picker=function(a){return["'"+a.getFieldValue("COLOUR")+"'",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.colour_random=function(a){Blockly.Pseudo.definitions_.import_random="import random";return["'#%06x' % random.randint(0, 2**24 - 1)",Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.colour_rgb=function(a){var b=Blockly.Pseudo.provideFunction_("colour_rgb",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(r, g, b):","  r = round(min(100, max(0, r)) * 2.55)","  g = round(min(100, max(0, g)) * 2.55)","  b = round(min(100, max(0, b)) * 2.55)","  return '#%02x%02x%02x' % (r, g, b)"]),c=Blockly.Pseudo.valueToCode(a,"RED",Blockly.Pseudo.ORDER_NONE)||0,d=Blockly.Pseudo.valueToCode(a,"GREEN",Blockly.Pseudo.ORDER_NONE)||0;a=Blockly.Pseudo.valueToCode(a,"BLUE",Blockly.Pseudo.ORDER_NONE)||
0;return[b+"("+c+", "+d+", "+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.colour_blend=function(a){var b=Blockly.Pseudo.provideFunction_("colour_blend",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(colour1, colour2, ratio):","  r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)","  g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)","  b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)","  ratio = min(1, max(0, ratio))","  r = round(r1 * (1 - ratio) + r2 * ratio)","  g = round(g1 * (1 - ratio) + g2 * ratio)","  b = round(b1 * (1 - ratio) + b2 * ratio)",
"  return '#%02x%02x%02x' % (r, g, b)"]),c=Blockly.Pseudo.valueToCode(a,"COLOUR1",Blockly.Pseudo.ORDER_NONE)||"'#000000'",d=Blockly.Pseudo.valueToCode(a,"COLOUR2",Blockly.Pseudo.ORDER_NONE)||"'#000000'";a=Blockly.Pseudo.valueToCode(a,"RATIO",Blockly.Pseudo.ORDER_NONE)||0;return[b+"("+c+", "+d+", "+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.corgis={};Blockly.Pseudo.weather_temperature=function(a){Blockly.Pseudo.definitions_.import_weather="Import the weather module (which provides access to US weather reports).";return["the current temperature for "+Blockly.Pseudo.quote_(a.getFieldValue("CITY")),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.weather_forecasts=function(a){Blockly.Pseudo.definitions_.import_weather="Import the weather module (which provides access to US weather reports).";return["the expected temperatures for "+(Blockly.Pseudo.quote_(a.getFieldValue("CITY"))+""),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.weather_highs_lows=function(a){Blockly.Pseudo.definitions_.import_weather="Import the weather module (which provides access to US weather reports).";return["the highs and lows for "+(Blockly.Pseudo.quote_(a.getFieldValue("CITY"))+""),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.weather_report=function(a){Blockly.Pseudo.definitions_.import_weather="Import the weather module (which provides access to US weather reports).";return["the complete weather report for "+(Blockly.Pseudo.quote_(a.getFieldValue("CITY"))+""),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.weather_report_forecasts=function(a){Blockly.Pseudo.definitions_.import_weather="Import the weather module (which provides access to US weather reports).";return["the complete weather forecast for "+(Blockly.Pseudo.quote_(a.getFieldValue("CITY"))+""),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.weather_all_forecasts=function(a){Blockly.Pseudo.definitions_.import_weather="Import the weather module (which provides access to US weather reports).";return["all of the forecasted weather reports",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.stocks_current=function(a){Blockly.Pseudo.definitions_.import_stocks="Import the stock module (which provides access to stock changes)";return["the current change in stock for "+Blockly.Pseudo.quote_(a.getFieldValue("TICKER")),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.stocks_past=function(a){Blockly.Pseudo.definitions_.import_stocks="Import the stock module (which provides access to stock changes)";return["the past change in stocks for "+Blockly.Pseudo.quote_(a.getFieldValue("TICKER")),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.earthquake_get=function(a){Blockly.Pseudo.definitions_.import_earthquakes="Import the earthquake module (which provides access to recent earthquakes)";return["the "+(Blockly.Pseudo.quote_(a.getFieldValue("PROPERTY"))+" of recent earthquakes"),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.earthquake_both=function(a){Blockly.Pseudo.definitions_.import_earthquakes="Import the earthquake module (which provides access to recent earthquakes)";return["both the magnitude and depth of recent earthquakes",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.earthquake_all=function(a){Blockly.Pseudo.definitions_.import_earthquakes="Import the earthquake module (which provides access to recent earthquakes)";return["all of the recent earthquakes",Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.crime_state=function(a){Blockly.Pseudo.definitions_.import_crime="Import the crime module (which provides access to historical crime records in the US)";var b="the "+a.getFieldValue("TYPE")+" property crimes of ";a=Blockly.Pseudo.quote_(a.getFieldValue("STATE"));return[b+a,Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.crime_year=function(a){Blockly.Pseudo.definitions_.import_crime="Import the crime module (which provides access to historical crime records in the US)";return["the crime reports in "+Blockly.Pseudo.quote_(a.getFieldValue("YEAR")),Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.crime_all=function(a){Blockly.Pseudo.definitions_.import_crime="Import the crime module (which provides access to historical crime records in the US)";return["all of the crime reports",Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.books_get=function(a){Blockly.Pseudo.definitions_.import_books="Import the books module (which provides access to a few example books)";return["all of the books",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.dicts={};Blockly.Pseudo.dict_get=function(a){var b=Blockly.Pseudo.valueToCode(a,"DICT",Blockly.Pseudo.ORDER_MEMBER)||"___";return[" the value of the key "+(Blockly.Pseudo.valueToCode(a,"ITEM",Blockly.Pseudo.ORDER_NONE)||"___")+" of "+b,Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.dict_get_literal=function(a){var b=Blockly.Pseudo.valueToCode(a,"DICT",Blockly.Pseudo.ORDER_MEMBER)||"___";return[" the value of the key "+Blockly.Pseudo.quote_(a.getFieldValue("ITEM"))+" of "+b,Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.dicts_create_with=function(a){Blockly.Pseudo.valueToCode(a,"keys",Blockly.Pseudo.ORDER_ATOMIC);for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++){var d=Blockly.Pseudo.quote_(a.getFieldValue("KEY"+c)),e=Blockly.Pseudo.valueToCode(a,"VALUE"+c,Blockly.Pseudo.ORDER_NONE)||"___";b[c]=d+": "+e}b="{"+b.join(", ")+"}";return[b,Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.dict_keys=function(a){return[(Blockly.Pseudo.valueToCode(a,"DICT",Blockly.Pseudo.ORDER_MEMBER)||"___")+".keys()",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.lists={};Blockly.Pseudo.lists_create_empty=function(a){return["a new empty list",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.lists_create_with=function(a){if(0<a.itemCount_){var b=Array(a.itemCount_);for(var c=0;c<a.itemCount_;c++)b[c]=Blockly.Pseudo.valueToCode(a,"ADD"+c,Blockly.Pseudo.ORDER_NONE)||"___";b="a new list of these elements: "+b.join(", ")}else b="a new empty list";return[b,Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.lists_repeat=function(a){var b=Blockly.Pseudo.valueToCode(a,"ITEM",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___";return["["+b+"] * "+a,Blockly.Pseudo.ORDER_MULTIPLICATIVE]};Blockly.Pseudo.lists_length=function(a){return["the length of "+(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___"),Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.lists_isEmpty=function(a){return["not len("+(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___")+")",Blockly.Pseudo.ORDER_LOGICAL_NOT]};
Blockly.Pseudo.lists_indexOf=function(a){var b=Blockly.Pseudo.valueToCode(a,"FIND",Blockly.Pseudo.ORDER_NONE)||"___",c=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_MEMBER)||"___";return[("FIRST"==a.getFieldValue("END")?Blockly.Pseudo.provideFunction_("first_index",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(myList, elem):","  try: theIndex = myList.index(elem) + 1","  except: theIndex = 0","  return theIndex"]):Blockly.Pseudo.provideFunction_("last_index",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+
"(myList, elem):","  try: theIndex = len(myList) - myList[::-1].index(elem)","  except: theIndex = 0","  return theIndex"]))+"("+c+", "+b+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.lists_index=function(a){var b=Blockly.Pseudo.valueToCode(a,"ITEM",Blockly.Pseudo.ORDER_UNARY_SIGN)||"___";return[(Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_MEMBER)||"___")+"["+b+"]",Blockly.Pseudo.ORDER_MEMBER]};
Blockly.Pseudo.lists_getIndex=function(a){var b=a.getFieldValue("MODE")||"GET",c=a.getFieldValue("WHERE")||"FROM_START",d=Blockly.Pseudo.valueToCode(a,"AT",Blockly.Pseudo.ORDER_UNARY_SIGN)||"___";a=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_MEMBER)||"___";if("FIRST"==c){if("GET"==b)return[a+"[0]",Blockly.Pseudo.ORDER_MEMBER];c=a+".pop(0)";if("GET_REMOVE"==b)return[c,Blockly.Pseudo.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+"\n"}else if("LAST"==c){if("GET"==b)return[a+"[-1]",Blockly.Pseudo.ORDER_MEMBER];
c=a+".pop()";if("GET_REMOVE"==b)return[c,Blockly.Pseudo.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+"\n"}else if("FROM_START"==c){d=Blockly.isNumber(d)?parseInt(d,10)-1:"int("+d+" - 1)";if("GET"==b)return[a+"["+d+"]",Blockly.Pseudo.ORDER_MEMBER];c=a+".pop("+d+")";if("GET_REMOVE"==b)return[c,Blockly.Pseudo.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+"\n"}else if("FROM_END"==c){if("GET"==b)return[a+"[-"+d+"]",Blockly.Pseudo.ORDER_MEMBER];c=a+".pop(-"+d+")";if("GET_REMOVE"==b)return[c,Blockly.Pseudo.ORDER_FUNCTION_CALL];
if("REMOVE"==b)return c+"\n"}else if("RANDOM"==c){Blockly.Pseudo.definitions_.import_random="import random";if("GET"==b)return["random.choice("+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL];c=Blockly.Pseudo.provideFunction_("lists_remove_random_item",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(myList):","  x = int(random.random() * len(myList))","  return myList.pop(x)"])+"("+a+")";if("GET_REMOVE"==b)return[c,Blockly.Pseudo.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+"\n"}throw"Unhandled combination (lists_getIndex).";
};
Blockly.Pseudo.lists_setIndex=function(a){var b=Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_MEMBER)||"___",c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START",e=Blockly.Pseudo.valueToCode(a,"AT",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"TO",Blockly.Pseudo.ORDER_NONE)||"___";if("FIRST"==d){if("SET"==c)return b+"[0] = "+a+"\n";if("INSERT"==c)return b+".insert(0, "+a+")\n"}else if("LAST"==d){if("SET"==c)return b+"[-1] = "+a+"\n";if("INSERT"==c)return b+
".append("+a+")\n"}else if("FROM_START"==d){e=Blockly.isNumber(e)?parseInt(e,10)-1:"int("+e+" - 1)";if("SET"==c)return b+"["+e+"] = "+a+"\n";if("INSERT"==c)return b+".insert("+e+", "+a+")\n"}else if("FROM_END"==d){if("SET"==c)return b+"[-"+e+"] = "+a+"\n";if("INSERT"==c)return b+".insert(-"+e+", "+a+")\n"}else if("RANDOM"==d){Blockly.Pseudo.definitions_.import_random="import random";b.match(/^\w+$/)?d="":(d=Blockly.Pseudo.variableDB_.getDistinctName("tmp_list",Blockly.Variables.NAME_TYPE),e=d+" = "+
b+"\n",b=d,d=e);e=Blockly.Pseudo.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE);d+=e+" = int(random.random() * len("+b+"))\n";if("SET"==c)return d+(b+"["+e+"] = "+a+"\n");if("INSERT"==c)return d+(b+".insert("+e+", "+a+")\n")}throw"Unhandled combination (lists_setIndex).";};
Blockly.Pseudo.lists_getSublist=function(a){var b=Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_MEMBER)||"___",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2"),e=Blockly.Pseudo.valueToCode(a,"AT1",Blockly.Pseudo.ORDER_ADDITIVE)||"___";a=Blockly.Pseudo.valueToCode(a,"AT2",Blockly.Pseudo.ORDER_ADDITIVE)||"___";"FIRST"==c||"FROM_START"==c&&"1"==e?e="":"FROM_START"==c?e=Blockly.isNumber(e)?parseInt(e,10)-1:"int("+e+" - 1)":"FROM_END"==c&&(e=Blockly.isNumber(e)?-parseInt(e,10):"-int("+
e+")");"LAST"==d||"FROM_END"==d&&"1"==a?a="":"FROM_START"==c?a=Blockly.isNumber(a)?parseInt(a,10):"int("+a+")":"FROM_END"==c&&(Blockly.isNumber(a)?(a=1-parseInt(a,10),0==a&&(a="")):(Blockly.Pseudo.definitions_.import_sys="import sys",a="int(1 - "+a+") or sys.maxsize"));return[b+"["+e+" : "+a+"]",Blockly.Pseudo.ORDER_MEMBER]};
Blockly.Pseudo.lists_split=function(a){var b=a.getFieldValue("MODE");if("SPLIT"==b)b=Blockly.Pseudo.valueToCode(a,"INPUT",Blockly.Pseudo.ORDER_MEMBER)||"___",a=Blockly.Pseudo.valueToCode(a,"DELIM",Blockly.Pseudo.ORDER_NONE),a=b+".split("+a+")";else if("JOIN"==b)b=Blockly.Pseudo.valueToCode(a,"INPUT",Blockly.Pseudo.ORDER_NONE)||"___",a=Blockly.Pseudo.valueToCode(a,"DELIM",Blockly.Pseudo.ORDER_MEMBER)||"___",a=a+".join("+b+")";else throw"Unknown mode: "+b;return[a,Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.lists_append=function(a){var b=Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_MEMBER)||"___";return"Append "+(Blockly.Pseudo.valueToCode(a,"ITEM",Blockly.Pseudo.ORDER_NONE)||"___")+" to "+b+" (which must be a list).\n"};Blockly.Pseudo.logic={};
Blockly.Pseudo.controls_if=function(a){var b=0,c=Blockly.Pseudo.valueToCode(a,"IF"+b,Blockly.Pseudo.ORDER_NONE)||"___",d=Blockly.Pseudo.statementToCode(a,"DO"+b)||Blockly.Pseudo.PASS,e="if "+c+":\n"+d;for(b=1;b<=a.elseifCount_;b++)c=Blockly.Pseudo.valueToCode(a,"IF"+b,Blockly.Pseudo.ORDER_NONE)||"___",d=Blockly.Pseudo.statementToCode(a,"DO"+b)||Blockly.Pseudo.PASS,e+="otherwise if "+c+":\n"+d;a.elseCount_&&(d=Blockly.Pseudo.statementToCode(a,"ELSE")||Blockly.Pseudo.PASS,e+="otherwise:\n"+d);return e};
Blockly.Pseudo.logic_compare=function(a){var b={EQ:" is equal to ",NEQ:" is not equal to ",LT:" is less than ",LTE:" is less than or equal to ",GT:" is greater than ",GTE:" is greater than or equal to "}[a.getFieldValue("OP")],c=Blockly.Pseudo.ORDER_RELATIONAL,d=Blockly.Pseudo.valueToCode(a,"A",c)||"___";a=Blockly.Pseudo.valueToCode(a,"B",c)||"___";return[d+" "+b+" "+a,c]};
Blockly.Pseudo.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"and":"or",c="and"==b?Blockly.Pseudo.ORDER_LOGICAL_AND:Blockly.Pseudo.ORDER_LOGICAL_OR,d=Blockly.Pseudo.valueToCode(a,"A",c);a=Blockly.Pseudo.valueToCode(a,"B",c);d||a?(d||(d="___"),a||(a="___")):a=d="___";return[d+" "+b+" "+a,c]};Blockly.Pseudo.logic_negate=function(a){return["not "+(Blockly.Pseudo.valueToCode(a,"BOOL",Blockly.Pseudo.ORDER_LOGICAL_NOT)||"___"),Blockly.Pseudo.ORDER_LOGICAL_NOT]};
Blockly.Pseudo.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"True":"False",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.logic_null=function(a){return["None",Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.logic_ternary=function(a){var b=Blockly.Pseudo.valueToCode(a,"IF",Blockly.Pseudo.ORDER_CONDITIONAL)||"___",c=Blockly.Pseudo.valueToCode(a,"THEN",Blockly.Pseudo.ORDER_CONDITIONAL)||"___";a=Blockly.Pseudo.valueToCode(a,"ELSE",Blockly.Pseudo.ORDER_CONDITIONAL)||"___";return[c+" if "+b+" else "+a,Blockly.Pseudo.ORDER_CONDITIONAL]};
Blockly.Pseudo.logic_isIn=function(a){var b="IN"==a.getFieldValue("OP")?"in":"not in",c=Blockly.Pseudo.ORDER_RELATIONAL,d=Blockly.Pseudo.valueToCode(a,"ITEM",c)||"___";a=Blockly.Pseudo.valueToCode(a,"LIST",c)||"___";return[d+" "+b+" "+a,c]};Blockly.Pseudo.loops={};Blockly.Pseudo.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(parseInt(a.getFieldValue("TIMES"),10)):Blockly.Pseudo.valueToCode(a,"TIMES",Blockly.Pseudo.ORDER_NONE)||"___";b=Blockly.isNumber(b)?parseInt(b,10):"int("+b+")";var c=Blockly.Pseudo.statementToCode(a,"DO");c=Blockly.Pseudo.addLoopTrap(c,a.id)||Blockly.Pseudo.PASS;return"for "+Blockly.Pseudo.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE)+" in range("+b+"):\n"+c};
Blockly.Pseudo.controls_repeat=Blockly.Pseudo.controls_repeat_ext;Blockly.Pseudo.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Pseudo.valueToCode(a,"BOOL",b?Blockly.Pseudo.ORDER_LOGICAL_NOT:Blockly.Pseudo.ORDER_NONE)||"___",d=Blockly.Pseudo.statementToCode(a,"DO");d=Blockly.Pseudo.addLoopTrap(d,a.id)||Blockly.Pseudo.PASS;b&&(c="not "+c);return"while "+c+":\n"+d};
Blockly.Pseudo.controls_while=function(a){var b=Blockly.Pseudo.valueToCode(a,"BOOL",Blockly.Pseudo.ORDER_NONE)||"___",c=Blockly.Pseudo.statementToCode(a,"DO");c=Blockly.Pseudo.addLoopTrap(c,a.id)||Blockly.Pseudo.PASS;return"while "+b+":\n"+c};
Blockly.Pseudo.controls_for=function(a){var b=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Pseudo.valueToCode(a,"FROM",Blockly.Pseudo.ORDER_NONE)||"___",d=Blockly.Pseudo.valueToCode(a,"TO",Blockly.Pseudo.ORDER_NONE)||"___",e=Blockly.Pseudo.valueToCode(a,"BY",Blockly.Pseudo.ORDER_NONE)||"___",f=Blockly.Pseudo.statementToCode(a,"DO");f=Blockly.Pseudo.addLoopTrap(f,a.id)||Blockly.Pseudo.PASS;var g="",h=function(){return Blockly.Pseudo.provideFunction_("upRange",
["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):","  while start <= stop:","    yield start","    start += abs(step)"])},k=function(){return Blockly.Pseudo.provideFunction_("downRange",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):","  while start >= stop:","    yield start","    start -= abs(step)"])};a=function(a,b,c){return"("+a+" <= "+b+") and "+h()+"("+a+", "+b+", "+c+") or "+k()+"("+a+", "+b+", "+c+")"};if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&
Blockly.isNumber(e))c=parseFloat(c),d=parseFloat(d),e=Math.abs(parseFloat(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?h():k(),a+="("+c+", "+d+", "+e+")");else{var l=function(a,c){if(Blockly.isNumber(a))a=parseFloat(a);else if(a.match(/^\w+$/))a="float("+a+")";else{var d=Blockly.Pseudo.variableDB_.getDistinctName(b+c,Blockly.Variables.NAME_TYPE);g+=d+" = float("+a+")\n";a=d}return a};c=l(c,"_start");d=l(d,"_end");
l(e,"_inc");a="number"==typeof c&&"number"==typeof d?c<d?h(c,d,e):k(c,d,e):a(c,d,e)}return g+="for "+b+" in "+a+":\n"+f};
Blockly.Pseudo.controls_forEach=function(a){var b=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_RELATIONAL)||"___",d=Blockly.Pseudo.statementToCode(a,"DO");d=Blockly.Pseudo.addLoopTrap(d,a.id)||Blockly.Pseudo.PASS;return"Create a new property named <u>"+b+"</u>.\nFor every element inside of the list "+c+", set "+b+" to that element's value and execute the following indented commands:\n"+d+"\n"};
Blockly.Pseudo.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"Stop this loop.\n";case "CONTINUE":return"Continue this loop, using the next value.\n"}throw"Unknown flow statement.";};Blockly.Pseudo.controls_pass=function(a){return"Do nothing.\n"};Blockly.Pseudo.math={};Blockly.Pseudo.addReservedWords("math,random");Blockly.Pseudo.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));return[a,0>a?Blockly.Pseudo.ORDER_UNARY_SIGN:Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.math_arithmetic=function(a){var b={ADD:[" added to ",Blockly.Pseudo.ORDER_ADDITIVE],MINUS:[" minus ",Blockly.Pseudo.ORDER_ADDITIVE],MULTIPLY:[" multiplied by ",Blockly.Pseudo.ORDER_MULTIPLICATIVE],DIVIDE:[" divided by ",Blockly.Pseudo.ORDER_MULTIPLICATIVE],POWER:[" raised to the power of ",Blockly.Pseudo.ORDER_EXPONENTIATION],MODULO:[" remainder ",Blockly.Pseudo.ORDER_MULTIPLICATIVE]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Pseudo.valueToCode(a,"A",b)||"___";a=Blockly.Pseudo.valueToCode(a,
"B",b)||"___";return[d+c+a,b]};
Blockly.Pseudo.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"==b){var c=Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_UNARY_SIGN)||"___";return["negative"+c,Blockly.Pseudo.ORDER_UNARY_SIGN]}"ABS"!=b&&"POW"!=b&&"ROUND"!=b&&(Blockly.Pseudo.definitions_.import_math="import math");a="SIN"==b||"COS"==b||"TAN"==b?Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___":Blockly.Pseudo.valueToCode(a,"NUM",Blockly.Pseudo.ORDER_NONE)||"___";switch(b){case "ABS":c=
"abs("+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="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.Pseudo.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"Unknown math operator: "+b;}return[c,Blockly.Pseudo.ORDER_MULTIPLICATIVE]};
Blockly.Pseudo.math_constant=function(a){var b={PI:["math.pi",Blockly.Pseudo.ORDER_MEMBER],E:["math.e",Blockly.Pseudo.ORDER_MEMBER],GOLDEN_RATIO:["(1 + math.sqrt(5)) / 2",Blockly.Pseudo.ORDER_MULTIPLICATIVE],SQRT2:["math.sqrt(2)",Blockly.Pseudo.ORDER_MEMBER],SQRT1_2:["math.sqrt(1.0 / 2)",Blockly.Pseudo.ORDER_MEMBER],INFINITY:["float('inf')",Blockly.Pseudo.ORDER_ATOMIC]};a=a.getFieldValue("CONSTANT");"INFINITY"!=a&&(Blockly.Pseudo.definitions_.import_math="import math");return b[a]};
Blockly.Pseudo.math_number_property=function(a){var b=Blockly.Pseudo.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return Blockly.Pseudo.definitions_.import_math="import math",[Blockly.Pseudo.provideFunction_("math_isPrime",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(n):","  # https://en.wikipedia.org/wiki/Primality_test#Naive_methods","  # If n is not a number but a string, try parsing it.","  if type(n) not in (int, float, long):",
"    try:","      n = float(n)","    except:","      return False","  if n == 2 or n == 3:","    return True","  # False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3.","  if n <= 1 or n % 1 != 0 or n % 2 == 0 or n % 3 == 0:","    return False","  # Check all the numbers of form 6k +/- 1, up to sqrt(n).","  for x in range(6, int(math.sqrt(n)) + 2, 6):","    if n % (x - 1) == 0 or n % (x + 1) == 0:","      return False","  return True"])+"("+b+")",Blockly.Pseudo.ORDER_FUNCTION_CALL];
switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Pseudo.valueToCode(a,"DIVISOR",Blockly.Pseudo.ORDER_MULTIPLICATIVE);if(!a||"0"==a)return["False",Blockly.Pseudo.ORDER_ATOMIC];d=b+" % "+a+" == 0"}return[d,Blockly.Pseudo.ORDER_RELATIONAL]};
Blockly.Pseudo.math_change=function(a){var b=Blockly.Pseudo.valueToCode(a,"DELTA",Blockly.Pseudo.ORDER_ADDITIVE)||"___";return"Increase <u>"+Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+"</u> by"+b+".\n"};Blockly.Pseudo.math_round=Blockly.Pseudo.math_single;Blockly.Pseudo.math_trig=Blockly.Pseudo.math_single;
Blockly.Pseudo.math_on_list=function(a){var b=a.getFieldValue("OP");a=Blockly.Pseudo.valueToCode(a,"LIST",Blockly.Pseudo.ORDER_NONE)||"___";switch(b){case "SUM":b="the sum of the list "+a;break;case "MIN":b="the lowest value of the list "+a;break;case "MAX":b="the highest value of the list "+a;break;case "AVERAGE":b=Blockly.Pseudo.provideFunction_("math_mean",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(myList):","  localList = [e for e in myList if type(e) in (int, float, long)]","  if not localList: return",
"  return float(sum(localList)) / len(localList)"]);b=b+"("+a+")";break;case "MEDIAN":b=Blockly.Pseudo.provideFunction_("math_median",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(myList):","  localList = sorted([e for e in myList if type(e) in (int, float, long)])","  if not localList: return","  if len(localList) % 2 == 0:","    return (localList[len(localList) / 2 - 1] + localList[len(localList) / 2]) / 2.0","  else:","    return localList[(len(localList) - 1) / 2]"]);b=b+"("+a+")";break;
case "MODE":b=Blockly.Pseudo.provideFunction_("math_modes",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(some_list):","  modes = []","  # Using a lists of [item, count] to keep count rather than dict",'  # to avoid "unhashable" errors when the counted item is itself a list or dict.',"  counts = []","  maxCount = 1","  for item in some_list:","    found = False","    for count in counts:","      if count[0] == item:","        count[1] += 1","        maxCount = max(maxCount, count[1])","        found = True",
"    if not found:","      counts.append([item, 1])","  for counted_item, item_count in counts:","    if item_count == maxCount:","      modes.append(counted_item)","  return modes"]);b=b+"("+a+")";break;case "STD_DEV":Blockly.Pseudo.definitions_.import_math="import math";b=Blockly.Pseudo.provideFunction_("math_standard_deviation",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(numbers):","  n = len(numbers)","  if n == 0: return","  mean = float(sum(numbers)) / n","  variance = sum((x - mean) ** 2 for x in numbers) / n",
"  return math.sqrt(variance)"]);b=b+"("+a+")";break;case "RANDOM":Blockly.Pseudo.definitions_.import_random="import random";b="random.choice("+a+")";break;default:throw"Unknown operator: "+b;}return[b,Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.math_modulo=function(a){var b=Blockly.Pseudo.valueToCode(a,"DIVIDEND",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___";a=Blockly.Pseudo.valueToCode(a,"DIVISOR",Blockly.Pseudo.ORDER_MULTIPLICATIVE)||"___";return[b+" % "+a,Blockly.Pseudo.ORDER_MULTIPLICATIVE]};
Blockly.Pseudo.math_constrain=function(a){var b=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___",c=Blockly.Pseudo.valueToCode(a,"LOW",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"HIGH",Blockly.Pseudo.ORDER_NONE)||"___";return["min(max("+b+", "+c+"), "+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.math_random_int=function(a){Blockly.Pseudo.definitions_.import_random="import random";var b=Blockly.Pseudo.valueToCode(a,"FROM",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"TO",Blockly.Pseudo.ORDER_NONE)||"___";return["random.randint("+b+", "+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.math_random_float=function(a){Blockly.Pseudo.definitions_.import_random="import random";return["random.random()",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.plot={};Blockly.Pseudo.plot_title=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";return"Set the title of the current plot to "+Blockly.Pseudo.quote_(a.getFieldValue("TEXT"))+".\n"};
Blockly.Pseudo.plot_line=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";return"Plot the list "+((Blockly.Pseudo.valueToCode(a,"y_values",Blockly.Pseudo.ORDER_NONE)||"___")+" onto the current canvas as a line.\n")};
Blockly.Pseudo.plot_lineXY=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";var b=Blockly.Pseudo.valueToCode(a,"x_values",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"y_values",Blockly.Pseudo.ORDER_NONE)||"___";return"Plot the list "+(b+","+a+" onto the current canvas as an XY Plot\n")};
Blockly.Pseudo.plot_scatter=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";var b=Blockly.Pseudo.valueToCode(a,"x_values",Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.valueToCode(a,"y_values",Blockly.Pseudo.ORDER_NONE)||"___";return"plt.scatter("+(b+","+a+")\n")};
Blockly.Pseudo.plot_show=function(a){Blockly.Pseudo.definitions_.import_matplotlib="Import the PyPlot package from the MatPlotLib module (which let's you do plotting).";return"Make the plot appear.\n"};Blockly.Pseudo.procedures={};
Blockly.Pseudo.procedures_defreturn=function(a){for(var b=[],c=b.length-1;0<=c;c--){var d=b[c];-1==a.arguments_.indexOf(d)?b[c]=Blockly.Pseudo.variableDB_.getName(d,Blockly.Variables.NAME_TYPE):b.splice(c,1)}b=b.length?"  global "+b.join(", ")+"\n":"";c=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE);d=Blockly.Pseudo.statementToCode(a,"STACK");Blockly.Pseudo.STATEMENT_PREFIX&&(d=Blockly.Pseudo.prefixLines(Blockly.Pseudo.STATEMENT_PREFIX.replace(/%1/g,"'"+a.id+
"'"),Blockly.Pseudo.INDENT)+d);Blockly.Pseudo.INFINITE_LOOP_TRAP&&(d=Blockly.Pseudo.INFINITE_LOOP_TRAP.replace(/%1/g,'"'+a.id+'"')+d);var e=Blockly.Pseudo.valueToCode(a,"RETURN",Blockly.Pseudo.ORDER_NONE)||"";e?e="Now the function is done, so it returns "+e+".\n":d||(d=Blockly.Pseudo.PASS);for(var f=[],g=0;g<a.arguments_.length;g++)f[g]="<u>"+Blockly.Pseudo.variableDB_.getName(a.arguments_[g],Blockly.Variables.NAME_TYPE)+"</u>";a=0<f.length?"The function can take the following parameters: "+f.join(", "):
"The function takes no parameters";return"Define a new function named <u>"+c+"</u>.\n"+a+".\nWhen called, it will do the following:\n"+b+d+e+"\n"};Blockly.Pseudo.procedures_defnoreturn=Blockly.Pseudo.procedures_defreturn;
Blockly.Pseudo.procedures_callreturn=function(a){for(var b=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Pseudo.valueToCode(a,"ARG"+d,Blockly.Pseudo.ORDER_NONE)||"___";return["the result of calling the function "+b+", with the following arguments: "+c.join(", "),Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.procedures_callnoreturn=function(a){for(var b=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Pseudo.valueToCode(a,"ARG"+d,Blockly.Pseudo.ORDER_NONE)||"___";return"Call the function "+b+", with the following arguments: "+c.join(", ")};
Blockly.Pseudo.procedures_ifreturn=function(a){var b="if "+(Blockly.Pseudo.valueToCode(a,"CONDITION",Blockly.Pseudo.ORDER_NONE)||"___")+":\n";a.hasReturnValue_?(a=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___",b+="  return "+a+"\n"):b+="  return\n";return b};Blockly.Pseudo.procedures_return=function(a){var b="Return";a.hasReturnValue_?(a=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___",b+=" "+a+".\n"):b+=".\n";return b};Blockly.Pseudo.texts={};Blockly.Pseudo.text=function(a){return[Blockly.Pseudo.quote_(a.getFieldValue("TEXT")),Blockly.Pseudo.ORDER_ATOMIC]};
Blockly.Pseudo.text_join=function(a){if(0==a.itemCount_)return["''",Blockly.Pseudo.ORDER_ATOMIC];if(1==a.itemCount_){var b=Blockly.Pseudo.valueToCode(a,"ADD0",Blockly.Pseudo.ORDER_NONE)||"___";return["str("+b+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]}if(2==a.itemCount_)return b=Blockly.Pseudo.valueToCode(a,"ADD0",Blockly.Pseudo.ORDER_NONE)||"___",a=Blockly.Pseudo.valueToCode(a,"ADD1",Blockly.Pseudo.ORDER_NONE)||"___",["str("+b+") + str("+a+")",Blockly.Pseudo.ORDER_UNARY_SIGN];b=[];for(var c=0;c<a.itemCount_;c++)b[c]=
Blockly.Pseudo.valueToCode(a,"ADD"+c,Blockly.Pseudo.ORDER_NONE)||"___";a=Blockly.Pseudo.variableDB_.getDistinctName("temp_value",Blockly.Variables.NAME_TYPE);b="''.join([str("+a+") for "+a+" in ["+b.join(", ")+"]])";return[b,Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.text_append=function(a){var b=Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);a=Blockly.Pseudo.valueToCode(a,"TEXT",Blockly.Pseudo.ORDER_NONE)||"___";return b+" = str("+b+") + str("+a+")\n"};
Blockly.Pseudo.text_length=function(a){return["len("+(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___")+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]};Blockly.Pseudo.text_isEmpty=function(a){return["not len("+(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___")+")",Blockly.Pseudo.ORDER_LOGICAL_NOT]};
Blockly.Pseudo.text_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"find":"rfind",c=Blockly.Pseudo.valueToCode(a,"FIND",Blockly.Pseudo.ORDER_NONE)||"___";return[(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_MEMBER)||"___")+"."+b+"("+c+") + 1",Blockly.Pseudo.ORDER_MEMBER]};
Blockly.Pseudo.text_charAt=function(a){var b=a.getFieldValue("WHERE")||"FROM_START",c=Blockly.Pseudo.valueToCode(a,"AT",Blockly.Pseudo.ORDER_UNARY_SIGN)||"1";a=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_MEMBER)||"___";switch(b){case "FIRST":return[a+"[0]",Blockly.Pseudo.ORDER_MEMBER];case "LAST":return[a+"[-1]",Blockly.Pseudo.ORDER_MEMBER];case "FROM_START":return c=Blockly.isNumber(c)?parseInt(c,10)-1:"int("+c+" - 1)",[a+"["+c+"]",Blockly.Pseudo.ORDER_MEMBER];case "FROM_END":return[a+
"[-"+c+"]",Blockly.Pseudo.ORDER_MEMBER];case "RANDOM":return Blockly.Pseudo.definitions_.import_random="import random",[Blockly.Pseudo.provideFunction_("text_random_letter",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(text):","  x = int(random.random() * len(text))","  return text[x];"])+"("+a+")",Blockly.Pseudo.ORDER_FUNCTION_CALL]}throw"Unhandled option (text_charAt).";};
Blockly.Pseudo.text_getSubstring=function(a){var b=Blockly.Pseudo.valueToCode(a,"STRING",Blockly.Pseudo.ORDER_MEMBER)||"___",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2"),e=Blockly.Pseudo.valueToCode(a,"AT1",Blockly.Pseudo.ORDER_ADDITIVE)||"1";a=Blockly.Pseudo.valueToCode(a,"AT2",Blockly.Pseudo.ORDER_ADDITIVE)||"1";"FIRST"==c||"FROM_START"==c&&"1"==e?e="":"FROM_START"==c?e=Blockly.isNumber(e)?parseInt(e,10)-1:"int("+e+" - 1)":"FROM_END"==c&&(e=Blockly.isNumber(e)?-parseInt(e,10):"-int("+
e+")");"LAST"==d||"FROM_END"==d&&"1"==a?a="":"FROM_START"==c?a=Blockly.isNumber(a)?parseInt(a,10):"int("+a+")":"FROM_END"==c&&(Blockly.isNumber(a)?(a=1-parseInt(a,10),0==a&&(a="")):(Blockly.Pseudo.definitions_.import_sys="import sys",a="int(1 - "+a+") or sys.maxsize"));return[b+"["+e+" : "+a+"]",Blockly.Pseudo.ORDER_MEMBER]};
Blockly.Pseudo.text_changeCase=function(a){var b={UPPERCASE:".upper()",LOWERCASE:".lower()",TITLECASE:".title()"}[a.getFieldValue("CASE")];return[(Blockly.Pseudo.valueToCode(a,"TEXT",Blockly.Pseudo.ORDER_MEMBER)||"___")+b,Blockly.Pseudo.ORDER_MEMBER]};Blockly.Pseudo.text_trim=function(a){var b={LEFT:".lstrip()",RIGHT:".rstrip()",BOTH:".strip()"}[a.getFieldValue("MODE")];return[(Blockly.Pseudo.valueToCode(a,"TEXT",Blockly.Pseudo.ORDER_MEMBER)||"___")+b,Blockly.Pseudo.ORDER_MEMBER]};
Blockly.Pseudo.text_print=function(a){return"Print "+(Blockly.Pseudo.valueToCode(a,"TEXT",Blockly.Pseudo.ORDER_NONE)||"___")+" to the printer.\n"};
Blockly.Pseudo.text_prompt_ext=function(a){var b=Blockly.Pseudo.provideFunction_("text_prompt",["def "+Blockly.Pseudo.FUNCTION_NAME_PLACEHOLDER_+"(msg):","  try:","    return raw_input(msg)","  except NameError:","    return input(msg)"]),c=a.getField("TEXT")?Blockly.Pseudo.quote_(a.getFieldValue("TEXT")):Blockly.Pseudo.valueToCode(a,"TEXT",Blockly.Pseudo.ORDER_NONE)||"___";b=b+"("+c+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="float("+b+")");return[b,Blockly.Pseudo.ORDER_FUNCTION_CALL]};
Blockly.Pseudo.text_print_multiple=function(a){for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++)b[c]=Blockly.Pseudo.valueToCode(a,"PRINT"+c,Blockly.Pseudo.ORDER_NONE)||"___";return"Print "+b.join(", ")+" to the printer.\n"};Blockly.Pseudo.text_prompt=Blockly.Pseudo.text_prompt_ext;Blockly.Pseudo.utility={};Blockly.Pseudo.raw_block=function(a){return a.getFieldValue("TEXT")+"\n"};Blockly.Pseudo.raw_expression=function(a){return[a.getFieldValue("TEXT"),Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.raw_empty=function(a){return(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_MEMBER)||"")+"\n"};Blockly.Pseudo.raw_table=function(a){return""};
Blockly.Pseudo.type_check=function(a){return["type("+(Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_MEMBER)||"___")+")",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.function_call=function(a){for(var b=a.getFieldValue("NAME"),c=a.hasReturn_,d=Array(a.itemCount_),e=0;e<a.itemCount_;e++)d[e]=Blockly.Pseudo.valueToCode(a,"ARGUMENT"+e,Blockly.Pseudo.ORDER_NONE)||"___";a=b+"("+d.join(", ")+")";return c?[a,Blockly.Pseudo.ORDER_ATOMIC]:a+"\n"};Blockly.Pseudo.variables={};Blockly.Pseudo.variables_get=function(a){return["the property <u>"+Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+"</u>",Blockly.Pseudo.ORDER_ATOMIC]};Blockly.Pseudo.variables_set=function(a){var b=Blockly.Pseudo.valueToCode(a,"VALUE",Blockly.Pseudo.ORDER_NONE)||"___";return"Set the property <u>"+Blockly.Pseudo.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+"</u> to "+b+".\n"};