old_contents: import logging
  import re
  
  from mopidy import settings
  
  logger = logging.getLogger('handler')
  
  class MpdHandler(object):
      def __init__(self):
          self.request_handlers = [
              (r'^currentsong$', self._currentsong),
              (r'^listplaylists$', self._listplaylists),
              (r'^lsinfo( "(?P<uri>[^"]*)")*$', self._lsinfo),
              (r'^ping$', self._ping),
              (r'^plchanges "(?P<version>\d+)"$', self._plchanges),
              (r'^status$', self._status),
          ]
  
      def handle_request(self, request):
          for request_pattern, request_handling_method in self.request_handlers:
              matches = re.match(request_pattern, request)
              if matches is not None:
                  groups = matches.groupdict()
                  return request_handling_method(**groups)
          logger.warning(u'Unhandled request: %s', request)
  
      def _currentsong(self):
          return None # TODO
  
      def _listplaylists(self):
          return None # TODO
  
      def _lsinfo(self, uri):
          if uri == u'/':
              return self._listplaylists()
          return None # TODO
  
      def _ping(self):
          return None
  
      def _plchanges(self, version):
          return None # TODO
  
      def _status(self):
          # TODO
          return [
              'volume: 0',
              'repeat: 0',
              'random: 0',
              'single: 0',
              'consume: 0',
              'playlist: 0',
              'playlistlength: 0',
              'xfade: 0',
              'state: stop',
          ]
  
new_contents: import logging
  import re
  
  from mopidy import settings
  
  logger = logging.getLogger('handler')
  
  global _request_handlers
  _request_handlers = {}
  
  def register(pattern):
      def decorator(func):
          global _request_handlers
          if pattern in _request_handlers:
              raise ValueError(u'Tried to redefine handler for %s with %s' % (
                  pattern, func))
          _request_handlers[pattern] = func
          return func
      return decorator
  
  class MpdHandler(object):
      def handle_request(self, request):
          for pattern in _request_handlers:
              matches = re.match(pattern, request)
              if matches is not None:
                  groups = matches.groupdict()
                  return _request_handlers[pattern](self, **groups)
          logger.warning(u'Unhandled request: %s', request)
  
      @register(r'^currentsong$')
      def _currentsong(self):
          return None # TODO
  
      @register(r'^listplaylists$')
      def _listplaylists(self):
          return None # TODO
  
      @register(r'^lsinfo( "(?P<uri>[^"]*)")*$')
      def _lsinfo(self, uri):
          if uri == u'/':
              return self._listplaylists()
          return None # TODO
  
      @register(r'^ping$')
      def _ping(self):
          return None
  
      @register(r'^plchanges "(?P<version>\d+)"$')
      def _plchanges(self, version):
          return None # TODO
  
      @register(r'^status$')
      def _status(self):
          # TODO
          return [
              'volume: 0',
              'repeat: 0',
              'random: 0',
              'single: 0',
              'consume: 0',
              'playlist: 0',
              'playlistlength: 0',
              'xfade: 0',
              'state: stop',
          ]
  
subject: Use a decorator to register the request handlers