Generate the node text given the format string 'fmt'
779929
def __get_node_text(self, diagram, node, fmt):
        '''
        
        '''
        fmt_proc = fmt

        # IF blocks
        while (1):
            if_block = re.search('<%if ([^%]*): ([^%]*)%>', fmt_proc)
            if (if_block == None):
                break

            # evaluate condition
            if_cond = if_block[1]
            if_val  = if_block[2]
            if (self.__eval_if_block(if_cond, node) == 0):
                if_val = ''
            fmt_proc = fmt_proc[:if_block.span()[0]] + if_val + fmt_proc[if_block.span()[1]:]

        # {node.ip} = best IP
        ip = node.get_ipaddr()
        fmt_proc = fmt_proc.replace('{node.ip}', ip)

        # stackwise
        stack_block = re.search('<%stack ([^%]*)%>', fmt_proc)
        if (stack_block != None):
            if (node.stack.count == 0):
                # no stackwise, remove this
                fmt_proc = fmt_proc[:stack_block.span()[0]] + fmt_proc[stack_block.span()[1]:]
            else:
                val = ''
                if (self.config.diagram.expand_stackwise == 0):
                    if (self.config.diagram.get_stack_members):
                        for smem in node.stack.members:
                            nval = stack_block[1]
                            nval = nval.replace('{stack.num}',    str(smem.num))
                            nval = nval.replace('{stack.plat}',   smem.plat)
                            nval = nval.replace('{stack.serial}', smem.serial)
                            nval = nval.replace('{stack.role}',   smem.role)
                            val += nval
                fmt_proc = fmt_proc[:stack_block.span()[0]] + val + fmt_proc[stack_block.span()[1]:]
        
        # loopbacks
        loopback_block = re.search('<%loopback ([^%]*)%>', fmt_proc)
        if (loopback_block != None):
            val = ''
            for lo in node.loopbacks:
                for lo_ip in lo.ips:
                    nval = loopback_block[1]
                    nval = nval.replace('{lo.name}', lo.name)
                    nval = nval.replace('{lo.ip}', lo_ip)
                    val += nval
            fmt_proc = fmt_proc[:loopback_block.span()[0]] + val + fmt_proc[loopback_block.span()[1]:]

        # SVIs
        svi_block = re.search('<%svi ([^%]*)%>', fmt_proc)
        if (svi_block != None):
            val = ''
            for svi in node.svis:
                for svi_ip in svi.ip:
                    nval = svi_block[1]
                    nval = nval.replace('{svi.vlan}', svi.vlan)
                    nval = nval.replace('{svi.ip}', svi_ip)
                    val += nval
            fmt_proc = fmt_proc[:svi_block.span()[0]] + val + fmt_proc[svi_block.span()[1]:]

        # replace {stack.} with magic
        fmt_proc = re.sub('{stack\.(([a-zA-Z])*)}', '$stack2354$\g<1>$stack2354$', fmt_proc)
        fmt_proc = re.sub('{vss\.(([a-zA-Z])*)}', '$vss2354$\g<1>$vss2354$', fmt_proc)

        # {node.} variables
        fmt_proc = fmt_proc.format(node=node)
        
        # replace magics
        fmt_proc = re.sub('\$stack2354\$(([a-zA-Z])*)\$stack2354\$', '{stack.\g<1>}', fmt_proc)
        fmt_proc = re.sub('\$vss2354\$(([a-zA-Z])*)\$vss2354\$', '{vss.\g<1>}', fmt_proc)

        return fmt_proc
1112016
def fmt_tag(cur_namespace, tag, val):
    
    if tag == 'type':
        fq_val = val
        if '.' not in val and cur_namespace is not None:
            fq_val = cur_namespace.name + '.' + fq_val
        return fq_val
    elif tag == 'route':
        if ':' in val:
            val, version = val.split(':', 1)
            version = int(version)
        else:
            version = 1
        return fmt_func(val, version) + "()"
    elif tag == 'link':
        anchor, link = val.rsplit(' ', 1)
        # There's no way to have links in TSDoc, so simply use JSDoc's formatting.
        # It's entirely possible some editors support this.
        return '[%s]{@link %s}' % (anchor, link)
    elif tag == 'val':
        # Value types seem to match JavaScript (true, false, null)
        return val
    elif tag == 'field':
        return val
    else:
        raise RuntimeError('Unknown doc ref tag %r' % tag)
28475
def _chk_flds_fmt(nt_fields, prtfmt):
    """"""
    fmtflds = get_fmtflds(prtfmt)
    missing_data = set(fmtflds).difference(set(nt_fields))
    # All data needed for print is present, return.
    if not missing_data:
        return
    #raise Exception('MISSING DATA({M}).'.format(M=" ".join(missing_data)))
    msg = ['CANNOT PRINT USING: "{PF}"'.format(PF=prtfmt.rstrip())]
    for fld in fmtflds:
        errmrk = "" if fld in nt_fields else "ERROR-->"
        msg.append("  {ERR:8} {FLD}".format(ERR=errmrk, FLD=fld))
    raise Exception('\n'.join(msg))
847346
static public function generate($type, $fmt = self::FMT_BYTE,
                                  $node = "", $ns = "") {
    $func = self::$m_generate[$type];
    if (!isset($func))
      return null;
    $conv = self::$m_convert[self::FMT_FIELD][$fmt];

    $uuid = self::$func($ns, $node);
    return self::$conv($uuid);
  }
894427
def fmt
      formated = {}
      attrs.each_key do |key|
        formated[camelize(key)] = attrs[key]
      end
      formated
    end
1052749
def fmt_title(text):
    
    text = text.strip()
    if len(text) == 0:  # if empty string, return it
        return text
    else:
        text = text.lower()  # lower all char
        # delete redundant empty space
        chunks = [chunk for chunk in text.split(" ") if len(chunk) >= 1]

        new_chunks = list()
        for chunk in chunks:
            if chunk not in _function_words:
                chunk = chunk[0].upper() + chunk[1:]
            new_chunks.append(chunk)

        new_chunks[0] = new_chunks[0][0].upper() + new_chunks[0][1:]

        return " ".join(new_chunks)
795535
def gen_output_fmt(self, fmt_list):
        """"""

        rexp_list = []
        for fmt in fmt_list:
            rexp_list.extend(self.gen_output_fmt_1(fmt))

        return rexp_list
23522
def format_string(m, l, capture, is_bytes):
    """"""

    for fmt_type, value in capture[1:]:
        if fmt_type == FMT_ATTR:
            # Attribute
            l = getattr(l, value)
        elif fmt_type == FMT_INDEX:
            # Index
            l = l[value]
        elif fmt_type == FMT_CONV:
            if is_bytes:
                # Conversion
                if value in ('r', 'a'):
                    l = repr(l).encode('ascii', 'backslashreplace')
                elif value == 's':
                    # If the object is not string or byte string already
                    l = _to_bstr(l)
            else:
                # Conversion
                if value == 'a':
                    l = ascii(l)
                elif value == 'r':
                    l = repr(l)
                elif value == 's':
                    # If the object is not string or byte string already
                    l = str(l)
        elif fmt_type == FMT_SPEC:
            # Integers and floats don't have an explicit 's' format type.
            if value[3] and value[3] == 's':
                if isinstance(l, int):  # pragma: no cover
                    raise ValueError("Unknown format code 's' for object of type 'int'")
                if isinstance(l, float):  # pragma: no cover
                    raise ValueError("Unknown format code 's' for object of type 'float'")

            # Ensure object is a byte string
            l = _to_bstr(l) if is_bytes else str(l)

            spec_type = value[1]
            if spec_type == '^':
                l = l.center(value[2], value[0])
            elif spec_type == ">":
                l = l.rjust(value[2], value[0])
            else:
                l = l.ljust(value[2], value[0])

    # Make sure the final object is a byte string
    return _to_bstr(l) if is_bytes else str(l)
1104027
def fmt(self, value):
        
        if isinstance(value, str):
            value = value.split(self.join_str)
        if not (value and isinstance(value, (list, tuple))):
            raise TypeError(
                ' '.join((
                    'Expecting str or list/tuple of formats {!r}.',
                    'Got: ({}) {!r}'
                )).format(
                    self.default_format,
                    type(value).__name__,
                    value,
                ))
        self._fmt = value
207641
def ustring(self,
                indent,
                color,
                msg,
                prefix='',
                suffix='',
                endc=None):
        ''''''
        if endc is None:
            endc = self.ENDC  # pylint: disable=no-member

        indent *= ' '
        fmt = u'{0}{1}{2}{3}{4}{5}'

        try:
            return fmt.format(indent, color, prefix, msg, endc, suffix)
        except UnicodeDecodeError:
            return fmt.format(indent, color, prefix, salt.utils.data.decode(msg), endc, suffix)
507116
def node_text(node):
    """"""

    if node.text:
        result = node.text
    else:
        result = ""
    for child in node:
        if child.tail is not None:
            result += child.tail
    return result
1367675
function nodeText (node) {
  return squashWhitespace(node.textContent)

  function squashWhitespace (string) {
    return string.replace(/\s{2,}/g, ' ').trim()
  }
}
796836
def fmt_text(text, bg = None, fg = None, attr = None, plain = False):
        
        if not plain:
            if fg is not None:
                text = TEXT_FORMATING['fg'][fg] + text
            if bg is not None:
                text = TEXT_FORMATING['bg'][bg] + text
            if attr is not None:
                text = TEXT_FORMATING['attr'][attr] + text
            if (fg is not None) or (bg is not None) or (attr is not None):
                text += TEXT_FORMATING['rst']
        return text
422994
function stringifyNode(node)
{
	var result = "<"+node.nodeName;
	var numAttrs = node.attrs.length;
	
	for (var i=0; i<numAttrs; i++)
	{
		result += " "+ node.attrs[i].name +'="'+ node.attrs[i].value +'"';
	}
	
	result += ">";
	
	return result;
}
823029
def innertext(node):
    """"""
    if not len(node):
        return node.text

    return (node.text or '') + ''.join([etree.tostring(c) for c in node]) + (node.tail or '')
650538
private String toText(AstNode node) throws IOException {
    StringBuilder out = new StringBuilder();
    if (node instanceof StringContentNode) {
      out.append(((StringContentNode)node).getContent());
    } else if (node instanceof ContentNode) {
      NodeList nodes = ((ContentNode) node).getContent();
      for (AstNode subNode : nodes) {
        out.append(toText(subNode));
      }
    }
    return out.toString();
  }
1303238
def _ensure_node(node: Union[str, AbstractNode]) -> AbstractNode:
    
    if isinstance(node, str):
        return Text(node)
    elif isinstance(node, Node):
        return node
    else:
        raise TypeError('Invalid type to append: {}'.format(node))