def render(self, get_params, module, _if=None):
enough = False<EOL>output = []<EOL>valid = None<EOL>if self.commands.show:<EOL><INDENT>valid = True<EOL><DEDENT>if self.parent and self.commands.soft and _if is None:<EOL><INDENT>return None, self<EOL><DEDENT>if _if:<EOL><INDENT>valid = True<EOL><DEDENT>elif self.commands._if:<EOL><INDENT>valid = self.check_valid(get_params)<EOL><DEDENT>if valid is not False:<EOL><INDENT>for item in self.content:<EOL><INDENT>if isinstance(item, Placeholder):<EOL><INDENT>sub_valid, sub_output, enough = item.get(get_params, self)<EOL>output.append(sub_output)<EOL><DEDENT>elif isinstance(item, Literal):<EOL><INDENT>sub_valid = None<EOL>enough = True<EOL>output.append(item.text)<EOL><DEDENT>elif isinstance(item, Block):<EOL><INDENT>sub_valid, sub_output = item.render(get_params, module)<EOL>if sub_valid is None:<EOL><INDENT>output.append(sub_output)<EOL><DEDENT>else:<EOL><INDENT>output.extend(sub_output)<EOL><DEDENT><DEDENT>valid = valid or sub_valid<EOL><DEDENT><DEDENT>if not valid:<EOL><INDENT>if self.next_block:<EOL><INDENT>valid, output = self.next_block.render(<EOL>get_params, module, _if=self.commands._if<EOL>)<EOL><DEDENT>elif self.parent is None and (<EOL>(not self.next_block and enough) or self.base_block<EOL>):<EOL><INDENT>valid = True<EOL><DEDENT>else:<EOL><INDENT>output = []<EOL><DEDENT><DEDENT>color = self.commands.color<EOL>if color and color[<NUM_LIT:0>] != "<STR_LIT:#>":<EOL><INDENT>color_name = "<STR_LIT>" % color<EOL>threshold_color_name = "<STR_LIT>" % color<EOL>color = (<EOL>getattr(module, color_name, None)<EOL>or getattr(module, threshold_color_name, None)<EOL>or getattr(module.py3, color_name.upper(), None)<EOL>)<EOL>if color == "<STR_LIT>":<EOL><INDENT>return False, []<EOL><DEDENT><DEDENT>text = u"<STR_LIT>"<EOL>out = []<EOL>if isinstance(output, str):<EOL><INDENT>output = [output]<EOL><DEDENT>if python2:<EOL><INDENT>conversion = unicode  <EOL>convertables = (str, bool, int, float, unicode)  <EOL><DEDENT>else:<EOL><INDENT>conversion = str<EOL>convertables = (str, bool, int, float, bytes)<EOL><DEDENT>first = True<EOL>last_block = None<EOL>for index, item in enumerate(output):<EOL><INDENT>is_block = isinstance(item, Block)<EOL>if not is_block and item:<EOL><INDENT>last_block = None<EOL><DEDENT>if isinstance(item, convertables) or item is None:<EOL><INDENT>text += conversion(item)<EOL>continue<EOL><DEDENT>elif text:<EOL><INDENT>if not first and (text == "<STR_LIT>" or out and out[-<NUM_LIT:1>].get("<STR_LIT>") == color):<EOL><INDENT>out[-<NUM_LIT:1>]["<STR_LIT>"] += text<EOL><DEDENT>else:<EOL><INDENT>part = {"<STR_LIT>": text}<EOL>if color:<EOL><INDENT>part["<STR_LIT>"] = color<EOL><DEDENT>out.append(part)<EOL><DEDENT>text = u"<STR_LIT>"<EOL><DEDENT>if isinstance(item, Composite):<EOL><INDENT>if color:<EOL><INDENT>item.composite_update(item, {"<STR_LIT>": color}, soft=True)<EOL><DEDENT>out.extend(item.get_content())<EOL><DEDENT>elif is_block:<EOL><INDENT>if not out:<EOL><INDENT>continue<EOL><DEDENT>for x in range(index + <NUM_LIT:1>, len(output)):<EOL><INDENT>if output[x] and not isinstance(output[x], Block):<EOL><INDENT>valid, _output = item.render(get_params, module, _if=True)<EOL>if _output and _output != last_block:<EOL><INDENT>last_block = _output<EOL>out.extend(_output)<EOL><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if item:<EOL><INDENT>out.append(item)<EOL><DEDENT><DEDENT>first = False<EOL><DEDENT>if text:<EOL><INDENT>part = {"<STR_LIT>": text}<EOL>if color:<EOL><INDENT>part["<STR_LIT>"] = color<EOL><DEDENT>out.append(part)<EOL><DEDENT>max_length = self.commands.max_length<EOL>min_length = self.commands.min_length<EOL>if max_length or min_length:<EOL><INDENT>for item in out:<EOL><INDENT>if max_length is not None:<EOL><INDENT>item["<STR_LIT>"] = item["<STR_LIT>"][:max_length]<EOL>max_length -= len(item["<STR_LIT>"])<EOL><DEDENT>if min_length:<EOL><INDENT>min_length -= len(item["<STR_LIT>"])<EOL><DEDENT><DEDENT>if min_length > <NUM_LIT:0>:<EOL><INDENT>out[<NUM_LIT:0>]["<STR_LIT>"] = u"<STR_LIT:U+0020>" * min_length + out[<NUM_LIT:0>]["<STR_LIT>"]<EOL>min_length = <NUM_LIT:0><EOL><DEDENT><DEDENT>return valid, out<EOL>
render the block and return the output.