old_contents: # -*- coding: utf8 -*-
  """Main module for libcrowds-analyst."""
  
  import os
  from flask import Flask, request
  from flask_wtf.csrf import CsrfProtect
  from flask.ext.z3950 import Z3950Manager
  from libcrowds_analyst import default_settings
  from libcrowds_analyst import view, auth
  
  
  
  def create_app():
      """Application factory."""
      app = Flask(__name__)
      app.config.from_object(default_settings)
      app.config.from_envvar('LIBCROWDS_ANALYST_SETTINGS', silent=True)
      if not os.environ.get('LIBCROWDS_ANALYST_SETTINGS'):  # pragma: no cover
          here = os.path.dirname(os.path.abspath(__file__))
          config_path = os.path.join(os.path.dirname(here), 'settings.py')
          if os.path.exists(config_path):
              app.config.from_pyfile(config_path)
      setup_csrf(app)
      setup_url_rules(app)
      setup_auth(app)
      setup_z3950_manager(app)
      return app
  
  
  def setup_csrf(app):
      """Setup csrf protection."""
      csrf = CsrfProtect(app)
      csrf.exempt(view.index)
  
  
  def setup_url_rules(app):
      """Setup URL rules"""
      rules = {'/': view.index,
               '/<short_name>': view.analyse_empty_result,
               '/<short_name>/<int:result_id>/edit': view.edit_result,
               '/<short_name>/reanalyse': view.reanalyse}
      for route, func in rules.items():
          app.add_url_rule(route, view_func=func, methods=['GET', 'POST'])
  
  
  def setup_auth(app):
      """Setup basic auth for all requests."""
      @app.before_request
      def requires_auth():
          if request.endpoint != 'index':
              cred = request.authorization
              if not cred or not auth.check_auth(cred.username, cred.password):
                  return auth.authenticate()
  
  
  def setup_z3950_manager(app):
      """Setup Flask-Z3950."""
      z3950_manager = Z3950Manager(app)
      z3950_manager.register_blueprint(url_prefix='/z3950')
  
new_contents: # -*- coding: utf8 -*-
  """Main module for libcrowds-analyst."""
  
  import os
  from flask import Flask, request
  from flask_wtf.csrf import CsrfProtect
  from flask.ext.z3950 import Z3950Manager
  from libcrowds_analyst import default_settings
  from libcrowds_analyst import view, auth
  
  
  
  def create_app():
      """Application factory."""
      app = Flask(__name__)
      app.config.from_object(default_settings)
      app.config.from_envvar('LIBCROWDS_ANALYST_SETTINGS', silent=True)
      if not os.environ.get('LIBCROWDS_ANALYST_SETTINGS'):  # pragma: no cover
          here = os.path.dirname(os.path.abspath(__file__))
          config_path = os.path.join(os.path.dirname(here), 'settings.py')
          if os.path.exists(config_path):
              app.config.from_pyfile(config_path)
      setup_csrf(app)
      setup_url_rules(app)
      setup_auth(app)
      setup_z3950_manager(app)
      return app
  
  
  def setup_csrf(app):
      """Setup csrf protection."""
      csrf = CsrfProtect(app)
      csrf.exempt(view.index)
  
  
  def setup_url_rules(app):
      """Setup URL rules"""
      rules = {'/': view.index,
               '/<short_name>/': view.analyse_empty_result,
               '/<short_name>/<int:result_id>/edit/': view.edit_result,
               '/<short_name>/reanalyse/': view.reanalyse}
      for route, func in rules.items():
          app.add_url_rule(route, view_func=func, methods=['GET', 'POST'])
  
  
  def setup_auth(app):
      """Setup basic auth for all requests."""
      @app.before_request
      def requires_auth():
          if request.endpoint != 'index':
              cred = request.authorization
              if not cred or not auth.check_auth(cred.username, cred.password):
                  return auth.authenticate()
  
  
  def setup_z3950_manager(app):
      """Setup Flask-Z3950."""
      z3950_manager = Z3950Manager(app)
      z3950_manager.register_blueprint(url_prefix='/z3950')
  
subject: Fix URL rules