parameters: (typename, meta_field_names, sub_field_names, verbose=False)
return_statement: return result
docstring: Returns a new recstruct class with the requested fields.
docstring_summary: Returns a new recstruct class with the requested fields.
docstring_tokens: Returns a new recstruct class with the requested fields .
function: def recstruct(typename, meta_field_names, sub_field_names, verbose=False):
      """
      Returns a new recstruct class with the requested fields.
      """
  
      # Validate the field names.
  
      meta_field_names = _preprocess_names(meta_field_names)
      meta_arg_list_with_defaults = ''.join(x + ', ' for x in meta_field_names)
      meta_field_names = [s.split('=')[0] for s in meta_field_names] #strip off default values
      meta_arg_list = ''.join(x + ', ' for x in meta_field_names)
      sub_field_names = _preprocess_names(sub_field_names)
      names = [typename] + meta_field_names
      if len(sub_field_names) > 0 and sub_field_names[-1][0] == '*':
          names += sub_field_names[:-1] + [sub_field_names[-1][1:]]
      else:
          names += sub_field_names
      for name in names:
          if not all(c.isalnum() or c=='_' for c in name):
              raise ValueError('Type names and field names can only contain '
                               'alphanumeric characters and underscores: %r' % name)
          if _iskeyword(name):
              raise ValueError('Type names and field names cannot be a '
                               'keyword: %r' % name)
          if name[0].isdigit():
              raise ValueError('Type names and field names cannot start with '
                               'a number: %r' % name)
      seen = set()
      for name in names[1:]:
          if name.startswith('_'):
              raise ValueError('Field names cannot start with an underscore: '
                               '%r' % name)
          if name in seen:
              raise ValueError('Encountered duplicate field name: %r' % name)
          seen.add(name)
  
      # Fill-in the class template
  
      n_meta = len(meta_field_names)
      sub_arg_list = ', '.join(sub_field_names)
      field_defs = '\n'.join(
          [_meta_field_template.format(index=index, name=name)
           for index, name in enumerate(meta_field_names)] +
          [_sub_field_template.format(index=index + n_meta, name=name)
           for index, name in enumerate(sub_field_names)
           if name[0] != '*'] +
          [_variadic_field_template.format(index=index + n_meta, name=name[1:])
           for index, name in enumerate(sub_field_names)
           if name[0] == '*']
       )
      class_definition = _class_template.format(
          typename=typename,
          meta_field_names=meta_field_names,
          sub_field_names=sub_field_names,
          n_meta=n_meta,
          meta_arg_list=meta_arg_list,
          meta_arg_list_with_defaults=meta_arg_list_with_defaults,
          sub_arg_list=sub_arg_list,
          field_defs=field_defs,
      )
  
      if verbose:
          print class_definition
  
      # Execute the template string in a temporary namespace and support
      # tracing utilities by setting a value for
      # frame.f_globals['__name__']
  
      namespace = dict(
          __name__='{}__{}'.format(__name__, typename),
          _tuple=tuple,
          _itemgetter=_itemgetter,
          _property=property,
          _init=_init,
      )
      try:
          exec class_definition in namespace
      except SyntaxError as e:
          raise SyntaxError(e.message + ':\n' + class_definition)
      result = namespace[typename]
  
      # For pickling to work, the __module__ variable needs to be set to the frame
      # where the named tuple is created.  Bypass this step in environments where
      # sys._getframe is not defined (Jython for example) or sys._getframe is not
      # defined for arguments greater than 0 (IronPython).
      try:
          result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
      except (AttributeError, ValueError):
          pass
  
      return result
function_tokens: def recstruct ( typename , meta_field_names , sub_field_names , verbose = False ) : # Validate the field names. meta_field_names = _preprocess_names ( meta_field_names ) meta_arg_list_with_defaults = '' . join ( x + ', ' for x in meta_field_names ) meta_field_names = [ s . split ( '=' ) [ 0 ] for s in meta_field_names ] #strip off default values meta_arg_list = '' . join ( x + ', ' for x in meta_field_names ) sub_field_names = _preprocess_names ( sub_field_names ) names = [ typename ] + meta_field_names if len ( sub_field_names ) > 0 and sub_field_names [ - 1 ] [ 0 ] == '*' : names += sub_field_names [ : - 1 ] + [ sub_field_names [ - 1 ] [ 1 : ] ] else : names += sub_field_names for name in names : if not all ( c . isalnum ( ) or c == '_' for c in name ) : raise ValueError ( 'Type names and field names can only contain ' 'alphanumeric characters and underscores: %r' % name ) if _iskeyword ( name ) : raise ValueError ( 'Type names and field names cannot be a ' 'keyword: %r' % name ) if name [ 0 ] . isdigit ( ) : raise ValueError ( 'Type names and field names cannot start with ' 'a number: %r' % name ) seen = set ( ) for name in names [ 1 : ] : if name . startswith ( '_' ) : raise ValueError ( 'Field names cannot start with an underscore: ' '%r' % name ) if name in seen : raise ValueError ( 'Encountered duplicate field name: %r' % name ) seen . add ( name ) # Fill-in the class template n_meta = len ( meta_field_names ) sub_arg_list = ', ' . join ( sub_field_names ) field_defs = '\n' . join ( [ _meta_field_template . format ( index = index , name = name ) for index , name in enumerate ( meta_field_names ) ] + [ _sub_field_template . format ( index = index + n_meta , name = name ) for index , name in enumerate ( sub_field_names ) if name [ 0 ] != '*' ] + [ _variadic_field_template . format ( index = index + n_meta , name = name [ 1 : ] ) for index , name in enumerate ( sub_field_names ) if name [ 0 ] == '*' ] ) class_definition = _class_template . format ( typename = typename , meta_field_names = meta_field_names , sub_field_names = sub_field_names , n_meta = n_meta , meta_arg_list = meta_arg_list , meta_arg_list_with_defaults = meta_arg_list_with_defaults , sub_arg_list = sub_arg_list , field_defs = field_defs , ) if verbose : print class_definition # Execute the template string in a temporary namespace and support # tracing utilities by setting a value for # frame.f_globals['__name__'] namespace = dict ( __name__ = '{}__{}' . format ( __name__ , typename ) , _tuple = tuple , _itemgetter = _itemgetter , _property = property , _init = _init , ) try : exec class_definition in namespace except SyntaxError as e : raise SyntaxError ( e . message + ':\n' + class_definition ) result = namespace [ typename ] # For pickling to work, the __module__ variable needs to be set to the frame # where the named tuple is created.  Bypass this step in environments where # sys._getframe is not defined (Jython for example) or sys._getframe is not # defined for arguments greater than 0 (IronPython). try : result . __module__ = _sys . _getframe ( 1 ) . f_globals . get ( '__name__' , '__main__' ) except ( AttributeError , ValueError ) : pass return result