[Zope-dev] SiteAccess Newbie

Erich Seifert e.seifert@gmx.net
Fri, 09 Feb 2001 20:42:42 +0100


Hi,

I just implemented virtual hosting on our web server combining multiple virtual 
hosts and localization as described in the corresonding how-to. But it's very 
(very) slow. How can I speed it up?

Following the External Python Method I used for the Access Rule:

import string

def get_language(self, REQUEST):
  cookie = 'LANG'
  if self.REQUEST.cookies.has_key(cookie):
   lang = self.REQUEST.cookies[cookie]
  else:
   langs = string.split(self.REQUEST['HTTP_ACCEPT_LANGUAGE'], ',')
  for lang in langs:
   lang = string.strip(lang)
   if lang:
    lang = string.split(lang, ';')[0]
    break
  if not hasattr(self, lang):
   if string.find(lang,'-')>=0:
    lang = string.split(lang,'-')[0]
   if not hasattr(self, lang):
    lang = 'de'
  return lang

def localize(self, REQUEST):
  sitemap  = { ... }
  hostname = 
string.join(string.split(string.lower(string.split(self.REQUEST['HTTP_HOST'], 
':')[0]), '.')[-4:], '.')
  lang     = self.get_language(self.REQUEST)
  stack    = self.REQUEST['TraversalRequestNameStack']

  if stack and stack[-1]=='Z':
   stack.pop()
   self.REQUEST.setVirtualRoot('Z')
  else:
   if sitemap.has_key(hostname):
    self.REQUEST.set('SiteRootPATH', '/')
    self.REQUEST['TraversalRequestNameStack'].extend([lang, sitemap[hostname]])
   else:
    self.REQUEST.set('SiteRootPATH', '/')