Given a namedtuple, return a format_field string.
770846
def mk_fmtfld(nt_item, joinchr=" ", eol="\n"):
    """"""
    fldstrs = []
    # Default formats based on fieldname
    fld2fmt = {
        'hdrgo' : lambda f: "{{{FLD}:1,}}".format(FLD=f),
        'dcnt' : lambda f: "{{{FLD}:6,}}".format(FLD=f),
        'level' : lambda f: "L{{{FLD}:02,}}".format(FLD=f),
        'depth' : lambda f: "D{{{FLD}:02,}}".format(FLD=f),
    }
    for fld in nt_item._fields:
        if fld in fld2fmt:
            val = fld2fmt[fld](fld)
        else:
            val = "{{{FLD}}}".format(FLD=fld)
        fldstrs.append(val)
    return "{LINE}{EOL}".format(LINE=joinchr.join(fldstrs), EOL=eol)
768338
def pyuri_formatter(namespace, value):
    
    if namespace[0]:
        return "%s_%s" %(namespace[0], value)
    else:
        return "pyuri_%s_%s" % (base64.b64encode(bytes(namespace[1],
                                                       "utf-8")).decode(),
                                value)
1279375
def concat_namedtuples(*tup, **kwargs):
    '''
    
    '''
    name = kwargs['name'] if 'name' in kwargs else None

    # filter out empty elements
    filtered = [i for i in filter(None, tup)]
    if filtered:
        if len(filtered) == 1:
            return filtered[0]
        else:
            fields = chain(*(t._fields for t in filtered))
            values = chain(*(t for t in filtered))
            if not name:
                name = 'SDMXNamedTuple'
            ConcatType = namedtuple_factory(name, fields)
            return ConcatType(*values)
    else:
        return ()
141323
def uri_from_fields(prefix, *fields):
        """"""
        string = '_'.join(AlignmentHelper.alpha_numeric(f.strip().lower(), '') for f in fields)

        if len(string) == len(fields) - 1:
            return ''

        return prefix + string
945604
def t_FIELD(t):
    '
    if t.value in u_ops:
        t.type = 'U_OP'
    elif t.value in b_ops:
        t.type = 'B_OP'
    return t
1243432
def nmltostring(nml):
    """"""
    if not isinstance(nml,dict):
      raise ValueError("nml should be a dict !")

    curstr = ""
    for key,group in nml.items():
       namelist = ["&" + key]
       for k, v in group.items():
         if isinstance(v, list) or isinstance(v, tuple):
           namelist.append(k + " = " + ",".join(map(str, v)) + ",")
         elif is_string(v):
           namelist.append(k + " = '" + str(v) + "',")
         else:
           namelist.append(k + " = " + str(v) + ",")
       namelist.append("/")

       curstr = curstr + "\n".join(namelist) + "\n"

    return curstr
982715
def dump(node):
    
    def _format(node):
        if isinstance(node, AST):
            return '%s(%s)' % (node.__class__.__name__,
                               ', '.join('%s=%s' % (a, _format(b))
                                         for a, b in iter_fields(node)))
        elif isinstance(node, list):
            return '[%s]' % ', '.join(_format(x) for x in node)
        return repr(node)
    if not isinstance(node, AST):
        raise TypeError('expected AST, got %r' % node.__class__.__name__)
    return _format(node)
172545
def format_field(self, value: Any, spec: str) -> str:
        """"""
        from cirq import ops  # HACK: avoids cyclic dependency.
        if isinstance(value, (float, int)):
            if isinstance(value, float):
                value = round(value, self.precision)
            if spec == 'half_turns':
                value = 'pi*{}'.format(value) if value != 0 else '0'
                spec = ''
        elif isinstance(value, ops.Qid):
            value = self.qubit_id_map[value]
        elif isinstance(value, str) and spec == 'meas':
            value = self.meas_key_id_map[value]
            spec = ''
        return super().format_field(value, spec)
198810
def get_formatter(name):
    
    if name in ('self', 'instance', 'this'):
        return af_self
    elif name == 'class':
        return af_class
    elif name in ('named', 'param', 'parameter'):
        return af_named
    elif name in ('default', 'optional'):
        return af_default
#    elif name in ('anonymous', 'arbitrary', 'unnamed'):
#        return af_anonymous
    elif name in ('keyword', 'pair', 'pairs'):
        return af_keyword
    else:
        raise ValueError('unknown trace formatter %r' % name)
860603
def format_field(self, value, format_spec):
        """"""
        if isinstance(value, MissingField):
            if format_spec is not None:
                value.format_spec = format_spec
            return str(value)

        return super(FormatterWrapper, self).format_field(value, format_spec)
53101
def format(self):
        
        if self.dynamic_version_of is not None:
            return self.dynamic_version_of.format

        if not self._format:
            self._format = '%s_%%s' % self.name
        return self._format
934907
def __get_wbfmt_format_txt(self, data_nt):
        """"""
        format_txt_val = getattr(data_nt, "format_txt")
        if format_txt_val == 1:
            return self.fmtname2wbfmtobj.get("very light grey")
        if format_txt_val == 2:
            return self.fmtname2wbfmtobj.get("light grey")
        return self.fmtname2wbfmtobj.get(format_txt_val)
973196
def astuple(self):
        
        return tuple(getattr(self, f.name) for f in fields(self))
809539
def parse_mailcap_nametemplate(tmplate='%s'):
    """"""
    nt_list = tmplate.split('%s')
    template_prefix = ''
    template_suffix = ''
    if len(nt_list) == 2:
        template_suffix = nt_list[1]
        template_prefix = nt_list[0]
    else:
        template_suffix = tmplate
    return (template_prefix, template_suffix)
611619
def format_value(obj, field_name):
    
    display_func = getattr(obj, 'get_%s_display' % field_name, None)
    if display_func:
        return display_func()
    value = getattr(obj, field_name)

    if isinstance(value, models.fields.files.FieldFile):
        if value:
            return mark_safe('<a href="%s">%s</a>' % (
                value.url,
                os.path.basename(value.name),
            ))
        else:
            return ''

    if isinstance(value, models.Model):
        return format_value_instance(value)

    if isinstance(value, models.Manager):
        return mark_safe(', '.join(
            [format_value_instance(instance) for instance in value.all()]
        ))
    if value is None:
        value = ""
    return value
141565
def make_from_namedtuple(t, **kwargs):
    
    d = t._asdict()
    d.update(kwargs)
    cls = type(t)
    return cls(**d)
393649
def get_fields(desc2nts):
        """"""
        if 'flat' in desc2nts:
            nts_flat = desc2nts.get('flat')
            if nts_flat:
                return nts_flat[0]._fields
        if 'sections' in desc2nts:
            nts_sections = desc2nts.get('sections')
            if nts_sections:
                return nts_sections[0][1][0]._fields