parameters: (author, glob, comment_prefix)
docstring: Finds all glob-matching files under the current directory and inserts the
      copyright message, and license notice.  An MIT license or Khronos free
      use license (modified MIT) is replaced with an Apache 2 license.
  
      The copyright message goes into the first non-whitespace, non-shebang line
      in a file.  The license notice follows it.  Both are prefixed on each line
      by comment_prefix and a space.
docstring_summary: Finds all glob-matching files under the current directory and inserts the
      copyright message, and license notice.  An MIT license or Khronos free
      use license (modified MIT) is replaced with an Apache 2 license.
docstring_tokens: Finds all glob - matching files under the current directory and inserts the copyright message and license notice . An MIT license or Khronos free use license ( modified MIT ) is replaced with an Apache 2 license .
function: def insert_copyright(author, glob, comment_prefix):
      """Finds all glob-matching files under the current directory and inserts the
      copyright message, and license notice.  An MIT license or Khronos free
      use license (modified MIT) is replaced with an Apache 2 license.
  
      The copyright message goes into the first non-whitespace, non-shebang line
      in a file.  The license notice follows it.  Both are prefixed on each line
      by comment_prefix and a space.
      """
  
      copyright = comment('Copyright (c) {} {}'.format(CURRENT_YEAR, author),
                          comment_prefix) + '\n\n'
      licensed = comment(LICENSED, comment_prefix) + '\n\n'
      for file in filtered_descendants(glob):
          # Parsing states are:
          #   0 Initial: Have not seen a copyright declaration.
          #   1 Seen a copyright line and no other interesting lines
          #   2 In the middle of an MIT or Khronos free use license
          #   9 Exited any of the above
          state = 0
          update_file = False
          for line in fileinput.input(file, inplace=1):
              emit = True
              if state == 0:
                  if COPYRIGHT_RE.search(line):
                      state = 1
                  elif skip(line):
                      pass
                  else:
                      # Didn't see a copyright. Inject copyright and license.
                      sys.stdout.write(copyright)
                      sys.stdout.write(licensed)
                      # Assume there isn't a previous license notice.
                      state = 1
              elif state == 1:
                  if MIT_BEGIN_RE.search(line):
                      state = 2
                      emit = False
                  elif APACHE2_BEGIN_RE.search(line):
                      # Assume an Apache license is preceded by a copyright
                      # notice.  So just emit it like the rest of the file.
                      state = 9
              elif state == 2:
                  # Replace the MIT license with Apache 2
                  emit = False
                  if MIT_END_RE.search(line):
                      state = 9
                      sys.stdout.write(licensed)
              if emit:
                  sys.stdout.write(line)
function_tokens: def insert_copyright ( author , glob , comment_prefix ) : copyright = comment ( 'Copyright (c) {} {}' . format ( CURRENT_YEAR , author ) , comment_prefix ) + '\n\n' licensed = comment ( LICENSED , comment_prefix ) + '\n\n' for file in filtered_descendants ( glob ) : # Parsing states are: #   0 Initial: Have not seen a copyright declaration. #   1 Seen a copyright line and no other interesting lines #   2 In the middle of an MIT or Khronos free use license #   9 Exited any of the above state = 0 update_file = False for line in fileinput . input ( file , inplace = 1 ) : emit = True if state == 0 : if COPYRIGHT_RE . search ( line ) : state = 1 elif skip ( line ) : pass else : # Didn't see a copyright. Inject copyright and license. sys . stdout . write ( copyright ) sys . stdout . write ( licensed ) # Assume there isn't a previous license notice. state = 1 elif state == 1 : if MIT_BEGIN_RE . search ( line ) : state = 2 emit = False elif APACHE2_BEGIN_RE . search ( line ) : # Assume an Apache license is preceded by a copyright # notice.  So just emit it like the rest of the file. state = 9 elif state == 2 : # Replace the MIT license with Apache 2 emit = False if MIT_END_RE . search ( line ) : state = 9 sys . stdout . write ( licensed ) if emit : sys . stdout . write ( line )