Builds the more compact fmtstrs by using fromstr( of the control sequences)
8279
def _getitem_normalized(self, index):
        """"""
        index = normalize_slice(len(self), index)
        counter = 0
        output = ''
        for fs in self.chunks:
            if index.start < counter + len(fs) and index.stop > counter:
                s_part = fs.s[max(0, index.start - counter):index.stop - counter]
                piece = Chunk(s_part, fs.atts).color_str
                output += piece
            counter += len(fs)
            if index.stop < counter:
                break
        return fmtstr(output)
803959
def _paramstr(ins):
    
    (tmp, output) = _str_oper(ins.quad[1])
    output.pop()  # Remove a register flag (useless here)
    tmp = ins.quad[1][0] in ('#', '_')  # Determine if the string must be duplicated

    if tmp:
        output.append('call __LOADSTR')  # Must be duplicated
        REQUIRES.add('loadstr.asm')

    output.append('push hl')
    return output
1359881
def fmt(self):
      """"""
      lines = [ ]
      def write (line):
        lines.append(line)
      if self._defaults:
          write("[%s]\n" % DEFAULTSECT)
          for (key, value) in self._defaults.items():
              write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
          write("\n")
      for section in self._sections:
          write("[%s]\n" % section)
          for (key, value) in self._sections[section].items():
              if key == "__name__":
                  continue
              if (value is not None) or (self._optcre == self.OPTCRE):
                  key = " = ".join((key, str(value).replace('\n', '\n\t')))
              write("%s\n" % (key))
          write("\n")
      return "".join(lines)
180565
function rtrim(str, targetStr) {
    var retStr = "";
    var regStr;

    if (typeof str != "string") {
        return retStr;
    }

    if (typeof targetStr != "string" || !targetStr) {
        targetStr = "\\s";
    }

    regStr = "(.*?)" + targetStr + "*$";
    regStr = new RegExp(regStr);

    str = str.replace(regStr, "$1");
    return str;
}
554978
def _fmt_fields(fld_vals, fld2fmt):
    """"""
    vals = []
    for fld, val in fld_vals:
        if fld in fld2fmt:
            val = fld2fmt[fld].format(val)
        vals.append(val)
    return vals
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))
1224643
def chkstr(s, v):
    
    if type(s) != str:
        raise TypeError("{var} must be str".format(var=v))
    if not s:
        raise ValueError("{var} cannot be empty".format(var=v))
397211
def FromString(cls, indata):
        

        lines = [x.strip() for x in indata.split("\n") if not x.startswith('#') and not x.strip() == ""]

        if len(lines) < 3:
            raise DataError("Invalid CommandFile string that did not contain 3 header lines", lines=lines)

        fmt_line, version_line, ascii_line = lines[:3]

        if not version_line.startswith("Format: "):
            raise DataError("Invalid format version that did not start with 'Format: '", line=version_line)

        version = version_line[8:]

        if ascii_line != "Type: ASCII":
            raise DataError("Unknown file type line (expected Type: ASCII)", line=ascii_line)

        cmds = [cls.decode(x) for x in lines[3:]]
        return CommandFile(fmt_line, version, cmds)
610036
function handleStrs(strs, opts) {
  const len = longest(strs)
  const text = strs
    .map(pad(len, opts.justify))
    .map(wrap(opts))
    .join('')
  return {len, text}
}
430911
def make_format_op_generator(fmt_string):
    
    def gen(arg_types):
        converted_arg_types = list(map(get_op_format_from_const_ty, arg_types))
        op = fmt_string.format(arg_t=converted_arg_types)
        return op
    return gen
459704
def readfmt(stream, fmt):
    """"""
    size = struct.calcsize(fmt)
    blob = stream.read(size)
    return struct.unpack(fmt, blob)
25554
def getstr_data(self, name, vals):
        """"""
        fld2val = self.get_fld2val(name, vals)
        return self.fmt.format(**fld2val)
77415
def fmtd_sub_expr_str(self):
        """"""
        result = u"{}({}".format(self.normalized_func,
                                 self._metric_name)

        if self._dimensions is not None:
            result += "{" + self.dimensions_str + "}"

        if self._period != _DEFAULT_PERIOD:
            result += ", {}".format(self._period)

        result += ")"

        result += " {} {}".format(self._operator,
                                  self._threshold)

        if self._periods != _DEFAULT_PERIODS:
            result += " times {}".format(self._periods)

        return result
1087070
function buf2str(buf) {
  var CHUNKSIZE=16384;
  if (buf.length < CHUNKSIZE) {
    return String.fromCharCode.apply(String, buf);
  }
  // special case for large strings, to avoid busting the stack.
  var result = '';
  for (var i = 0; i < buf.length; i += CHUNKSIZE) {
    result += String.fromCharCode.apply(String, buf.slice(i, i+CHUNKSIZE));
  }
  return result;
}
151889
def _generate_struct_deserializer(self, struct):
        """"""
        struct_name = fmt_class_prefix(struct)

        with self.block_func(
                func='deserialize',
                args=fmt_func_args_declaration([('valueDict',
                                                 'NSDictionary<NSString *, id> *')]),
                return_type='{} *'.format(struct_name),
                class_func=True):
            if not struct.all_fields and not struct.has_enumerated_subtypes():
                self.emit('#pragma unused(valueDict)')

            def emit_struct_deserialize_logic(struct):
                for field in struct.all_fields:
                    data_type, nullable = unwrap_nullable(field.data_type)
                    input_value = 'valueDict[@"{}"]'.format(field.name)

                    if is_primitive_type(data_type):
                        deserialize_call = input_value
                    else:
                        deserialize_call = self._fmt_serialization_call(
                            field.data_type, input_value, False)

                    if nullable or field.has_default:
                        default_value = fmt_default_value(
                            field) if field.has_default else 'nil'
                        if is_primitive_type(data_type):
                            deserialize_call = '{} ?: {}'.format(
                                input_value, default_value)
                        else:
                            deserialize_call = '{} ? {} : {}'.format(
                                input_value, deserialize_call, default_value)

                    self.emit('{}{} = {};'.format(
                        fmt_type(field.data_type),
                        fmt_var(field.name), deserialize_call))

                self.emit()

                deserialized_obj_args = [(fmt_var(f.name), fmt_var(f.name))
                                         for f in struct.all_fields]
                init_call = fmt_func_call(
                    caller=fmt_alloc_call(caller=struct_name),
                    callee=self._cstor_name_from_fields(struct.all_fields),
                    args=fmt_func_args(deserialized_obj_args))
                self.emit('return {};'.format(init_call))

            if not struct.has_enumerated_subtypes():
                emit_struct_deserialize_logic(struct)
            else:
                for tags, subtype in struct.get_all_subtypes_with_tags():
                    assert len(tags) == 1, tags
                    tag = tags[0]

                    base_string = 'if ([valueDict[@".tag"] isEqualToString:@"{}"])'
                    with self.block(base_string.format(tag)):
                        caller = fmt_serial_class(fmt_class_prefix(subtype))
                        args = fmt_func_args([('value', 'valueDict')])
                        deserialize_call = fmt_func_call(
                            caller=caller, callee='deserialize', args=args)
                        self.emit('return {};'.format(deserialize_call))

                self.emit()

                if struct.is_catch_all():
                    emit_struct_deserialize_logic(struct)
                else:
                    description_str = (
                        '[NSString stringWithFormat:@"Tag has an invalid '
                        'value: \\\"%@\\\".", valueDict[@".tag"]]')
                    self._generate_throw_error('InvalidTag', description_str)
        self.emit()
370020
def _prtstr(self, obj, dashes):
        """"""
        self.prt.write('{DASHES:{N}}'.format(
            DASHES=self.fmt_dashes.format(DASHES=dashes, ID=obj.item_id),
            N=self.dash_len))
        self.prt.write("{INFO}\n".format(INFO=str(obj)))
858133
def from_cstr_to_pystr(data, length):
    
    if PY3:
        res = []
        for i in range(length.value):
            try:
                res.append(str(data[i].decode('ascii')))
            except UnicodeDecodeError:
                res.append(str(data[i].decode('utf-8')))
    else:
        res = []
        for i in range(length.value):
            try:
                res.append(str(data[i].decode('ascii')))
            except UnicodeDecodeError:
                # pylint: disable=undefined-variable
                res.append(unicode(data[i].decode('utf-8')))
    return res