parameters: (name, map, encodingname, comments=1)
return_statement: return '\n'.join(l).expandtabs()
docstring: Returns Python source for the given map.
  
          Comments are included in the source, if comments is true (default).
docstring_summary: Returns Python source for the given map.
docstring_tokens: Returns Python source for the given map .
function: def codegen(name, map, encodingname, comments=1):
  
      """ Returns Python source for the given map.
  
          Comments are included in the source, if comments is true (default).
  
      """
      # Generate code
      decoding_map_code = python_mapdef_code(
          'decoding_map',
          map,
          comments=comments)
      decoding_table_code = python_tabledef_code(
          'decoding_table',
          map,
          comments=comments)
      encoding_map_code = python_mapdef_code(
          'encoding_map',
          codecs.make_encoding_map(map),
          comments=comments,
          precisions=(4, 2))
  
      if decoding_table_code:
          suffix = 'table'
      else:
          suffix = 'map'
  
      l = [
          '''\
  """ Python Character Mapping Codec %s generated from '%s' with gencodec.py.
  
  """#"
  
  import codecs
  
  ### Codec APIs
  
  class Codec(codecs.Codec):
  
      def encode(self,input,errors='strict'):
          return codecs.charmap_encode(input,errors,encoding_%s)
  
      def decode(self,input,errors='strict'):
          return codecs.charmap_decode(input,errors,decoding_%s)
  ''' % (encodingname, name, suffix, suffix)]
      l.append('''\
  class IncrementalEncoder(codecs.IncrementalEncoder):
      def encode(self, input, final=False):
          return codecs.charmap_encode(input,self.errors,encoding_%s)[0]
  
  class IncrementalDecoder(codecs.IncrementalDecoder):
      def decode(self, input, final=False):
          return codecs.charmap_decode(input,self.errors,decoding_%s)[0]''' %
          (suffix, suffix))
  
      l.append('''
  class StreamWriter(Codec,codecs.StreamWriter):
      pass
  
  class StreamReader(Codec,codecs.StreamReader):
      pass
  
  ### encodings module API
  
  def getregentry():
      return codecs.CodecInfo(
          name=%r,
          encode=Codec().encode,
          decode=Codec().decode,
          incrementalencoder=IncrementalEncoder,
          incrementaldecoder=IncrementalDecoder,
          streamreader=StreamReader,
          streamwriter=StreamWriter,
      )
  ''' % encodingname.replace('_', '-'))
  
      # Add decoding table or map (with preference to the table)
      if not decoding_table_code:
          l.append('''
  ### Decoding Map
  ''')
          l.extend(decoding_map_code)
      else:
          l.append('''
  ### Decoding Table
  ''')
          l.extend(decoding_table_code)
  
      # Add encoding map
      if decoding_table_code:
          l.append('''
  ### Encoding table
  encoding_table=codecs.charmap_build(decoding_table)
  ''')
      else:
          l.append('''
  ### Encoding Map
  ''')
          l.extend(encoding_map_code)
  
      # Final new-line
      l.append('')
  
      return '\n'.join(l).expandtabs()
function_tokens: def codegen ( name , map , encodingname , comments = 1 ) : # Generate code decoding_map_code = python_mapdef_code ( 'decoding_map' , map , comments = comments ) decoding_table_code = python_tabledef_code ( 'decoding_table' , map , comments = comments ) encoding_map_code = python_mapdef_code ( 'encoding_map' , codecs . make_encoding_map ( map ) , comments = comments , precisions = ( 4 , 2 ) ) if decoding_table_code : suffix = 'table' else : suffix = 'map' l = [ '''\
  """ Python Character Mapping Codec %s generated from '%s' with gencodec.py.
  
  """#"
  
  import codecs
  
  ### Codec APIs
  
  class Codec(codecs.Codec):
  
      def encode(self,input,errors='strict'):
          return codecs.charmap_encode(input,errors,encoding_%s)
  
      def decode(self,input,errors='strict'):
          return codecs.charmap_decode(input,errors,decoding_%s)
  ''' % ( encodingname , name , suffix , suffix ) ] l . append ( '''\
  class IncrementalEncoder(codecs.IncrementalEncoder):
      def encode(self, input, final=False):
          return codecs.charmap_encode(input,self.errors,encoding_%s)[0]
  
  class IncrementalDecoder(codecs.IncrementalDecoder):
      def decode(self, input, final=False):
          return codecs.charmap_decode(input,self.errors,decoding_%s)[0]''' % ( suffix , suffix ) ) l . append ( '''
  class StreamWriter(Codec,codecs.StreamWriter):
      pass
  
  class StreamReader(Codec,codecs.StreamReader):
      pass
  
  ### encodings module API
  
  def getregentry():
      return codecs.CodecInfo(
          name=%r,
          encode=Codec().encode,
          decode=Codec().decode,
          incrementalencoder=IncrementalEncoder,
          incrementaldecoder=IncrementalDecoder,
          streamreader=StreamReader,
          streamwriter=StreamWriter,
      )
  ''' % encodingname . replace ( '_' , '-' ) ) # Add decoding table or map (with preference to the table) if not decoding_table_code : l . append ( '''
  ### Decoding Map
  ''' ) l . extend ( decoding_map_code ) else : l . append ( '''
  ### Decoding Table
  ''' ) l . extend ( decoding_table_code ) # Add encoding map if decoding_table_code : l . append ( '''
  ### Encoding table
  encoding_table=codecs.charmap_build(decoding_table)
  ''' ) else : l . append ( '''
  ### Encoding Map
  ''' ) l . extend ( encoding_map_code ) # Final new-line l . append ( '' ) return '\n' . join ( l ) . expandtabs ( )