<commit_before>
class ApplicationProxy(object):
  """
  helper class for different applications defined by a namespace and a loader function
  """
  def __init__(self, namespace, loader):
    self.namespace = namespace
    #number of suburls to pop
    self.peeks = namespace.count('/')
    self.loader = loader
    self._impl = None

  @property
  def app(self):
    #cache
    if self._impl is not None:
      return self._impl
    self._impl = self.loader()
    return self._impl

  def match(self, path):
    return path.startswith(self.namespace)

class PathDispatcher(object):
  """
  helper class to select an application by path
  """
  def __init__(self, default_app, applications):
    self.default_app = default_app

    self.applications = [ ApplicationProxy(key,value) for key,value in applications.iteritems()]
    #print self.applications
    from threading import Lock
    self.lock = Lock()

  def get_application(self, path):
    with self.lock:
      for app in self.applications:
        if app.match(path):
          return app

  def __call__(self, environ, start_response):
    from werkzeug.wsgi import pop_path_info, get_path_info

    app = self.get_application(get_path_info(environ))
    if app is not None:
      for i in range(app.peeks):
        pop_path_info(environ)
      app = app.app<commit_msg>bugfixing api namespace with similar prefix<commit_after>
class ApplicationProxy(object):
  """
  helper class for different applications defined by a namespace and a loader function
  """
  def __init__(self, namespace, loader):
    self.namespace = namespace
    #number of suburls to pop
    self.peeks = namespace.count('/')
    self.loader = loader
    self._impl = None

  @property
  def app(self):
    #cache
    if self._impl is not None:
      return self._impl
    self._impl = self.loader()
    return self._impl

  def match(self, path):
    return path.startswith(self.namespace+'/')

class PathDispatcher(object):
  """
  helper class to select an application by path
  """
  def __init__(self, default_app, applications):
    self.default_app = default_app

    self.applications = [ ApplicationProxy(key,value) for key,value in applications.iteritems()]
    #print self.applications
    from threading import Lock
    self.lock = Lock()

  def get_application(self, path):
    with self.lock:
      for app in self.applications:
        if app.match(path):
          return app

  def __call__(self, environ, start_response):
    from werkzeug.wsgi import pop_path_info, get_path_info

    app = self.get_application(get_path_info(environ))
    if app is not None:
      for i in range(app.peeks):
        pop_path_info(environ)
      app = app.app
{'fraction_non_alphanumeric': 0.09124629080118694, 'fraction_numerical': 0.0, 'mean_word_length': 3.207488299531981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5952480', 'n_tokens_mistral': 800, 'n_tokens_neox': 795, 'n_words': 242}