old_contents: import os
  import stat
  import time
  
  from PyQt4.QtCore import SIGNAL
  from PyQt4.QtGui import QAction, QKeySequence, QMenu, QShortcut
  from aqt import mw
  
  
  def addMenu(name):
      if not hasattr(mw, 'customMenus'):
          mw.customMenus = {}
  
      if name not in mw.customMenus:
          menu = QMenu('&' + name, mw)
          mw.customMenus[name] = menu
          mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(),
                                     mw.customMenus[name])
  
  
  def addMenuItem(menuName, text, function, keys=None):
      action = QAction(text, mw)
  
      if keys:
          action.setShortcut(QKeySequence(keys))
  
      mw.connect(action, SIGNAL('triggered()'), function)
  
      if menuName == 'File':
          mw.form.menuCol.addAction(action)
      elif menuName == 'Edit':
          mw.form.menuEdit.addAction(action)
      elif menuName == 'Tools':
          mw.form.menuTools.addAction(action)
      elif menuName == 'Help':
          mw.form.menuHelp.addAction(action)
      else:
          addMenu(menuName)
          mw.customMenus[menuName].addAction(action)
  
  
  def addShortcut(function, keys):
      shortcut = QShortcut(QKeySequence(keys), mw)
      mw.connect(shortcut, SIGNAL('activated()'), function)
  
  
  def getField(note, fieldName):
      model = note.model()
      index, _ = mw.col.models.fieldMap(model)[fieldName]
      return note.fields[index]
  
  
  def setField(note, fieldName, content):
      model = note.model()
      index, _ = mw.col.models.fieldMap(model)[fieldName]
      note.fields[index] = content
  
  
  def updateModificationTime(path):
      accessTime = os.stat(path)[stat.ST_ATIME]
      modificationTime = time.time()
      os.utime(path, (accessTime, modificationTime))
  
new_contents: # -*- coding: utf-8 -*-
  
  from __future__ import unicode_literals
  import os
  import stat
  import time
  
  from PyQt4.QtCore import SIGNAL
  from PyQt4.QtGui import QAction, QKeySequence, QMenu, QShortcut
  from aqt import mw
  
  
  def addMenu(name):
      if not hasattr(mw, 'customMenus'):
          mw.customMenus = {}
  
      if name not in mw.customMenus:
          menu = QMenu('&' + name, mw)
          mw.customMenus[name] = menu
          mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(),
                                     mw.customMenus[name])
  
  
  def addMenuItem(menuName, text, function, keys=None):
      action = QAction(text, mw)
  
      if keys:
          action.setShortcut(QKeySequence(keys))
  
      mw.connect(action, SIGNAL('triggered()'), function)
  
      if menuName == 'File':
          mw.form.menuCol.addAction(action)
      elif menuName == 'Edit':
          mw.form.menuEdit.addAction(action)
      elif menuName == 'Tools':
          mw.form.menuTools.addAction(action)
      elif menuName == 'Help':
          mw.form.menuHelp.addAction(action)
      else:
          addMenu(menuName)
          mw.customMenus[menuName].addAction(action)
  
  
  def addShortcut(function, keys):
      shortcut = QShortcut(QKeySequence(keys), mw)
      mw.connect(shortcut, SIGNAL('activated()'), function)
  
  
  def getField(note, fieldName):
      model = note.model()
      index, _ = mw.col.models.fieldMap(model)[fieldName]
      return note.fields[index]
  
  
  def setField(note, fieldName, content):
      model = note.model()
      index, _ = mw.col.models.fieldMap(model)[fieldName]
      note.fields[index] = content
  
  
  def updateModificationTime(path):
      accessTime = os.stat(path)[stat.ST_ATIME]
      modificationTime = time.time()
      os.utime(path, (accessTime, modificationTime))
  
subject: Tweak unicode handling