code: def apply_and_save(self):
          
          patches = self.patches
  
          content = None
          with open(self.IN_PATH) as f_in:
              # As setup.py.in file size is 2.4 KByte.
              # it's fine to read entire content.
              content = f_in.read()
  
          # Replace words.
          for key in self.replaced_word_dict:
              content = content.replace(key, self.replaced_word_dict[key])
  
          # Apply patches.
          out_patches = []
          for patch in patches:
              pattern = re.compile(patch['src'], re.MULTILINE)
              (content, subs_num) = re.subn(pattern, patch['dest'],
                                            content)
              if subs_num > 0:
                  patch['applied'] = True
              out_patches.append(patch)
  
          for patch in out_patches:
              if patch.get('required') and not patch.get('applied'):
                  Log.warn('Patch not applied {0}'.format(patch['src']))
  
          with open(self.OUT_PATH, 'w') as f_out:
              f_out.write(content)
  
          self.pathces = out_patches
          # Release content data to make it released by GC quickly.
          content = None
docs: Apply replaced words and patches, and save setup.py file.