Changeset 28:db48fe4154b6

Show
Ignore:
Timestamp:
12/16/05 16:58:01 (3 years ago)
Author:
Allan Saddi <allan@saddi.com>
branch:
default
convert_revision:
svn:46762da8-4eb7-0310-94e9-d918b60927c8/flup/trunk@1833
Message:

Move custom 404 code out of resolvers and wholly into Publisher.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r27 r28  
    33        * Switch to setuptools for egg support. 
    44        * Add higher-level 404 error page support. Thanks to Scot Doyle 
    5           for suggesting the idea and providing code. 
     5          for suggesting the idea and providing code. If you previously 
     6          subclassed Publisher to provide a custom 404 error page, this 
     7          is now broken. It will have to be massaged to fit the new 
     8          calling convention. 
    69 
    7102005-11-28  Allan Saddi  <asaddi@kalahari.flup.org> 
  • flup/publisher.py

    r25 r28  
    422422    _transactionClass = Transaction 
    423423 
    424     def __init__(self, resolver, transactionClass=None): 
     424    def __init__(self, resolver, transactionClass=None, error404=None): 
    425425        self._resolver = resolver 
    426426 
    427427        if transactionClass is not None: 
    428428            self._transactionClass = transactionClass 
     429 
     430        if error404 is not None: 
     431            self._error404 = error404 
    429432 
    430433    def _get_resolver(self): 
     
    451454                                          redirect=redirect) 
    452455            if func is None: 
    453                 # See if there's a higher-level 404 page 
    454                 if hasattr(self._resolver, 'error404') and \ 
    455                    self._resolver.error404 is not None: 
    456                     func = self._resolver.error404 
    457                 else: 
    458                     return self._error404(environ, start_response) 
     456                func = self._error404 
    459457 
    460458            try: 
     
    485483        return transaction.response.body 
    486484 
    487     def _error404(self, environ, start_response): 
     485    def _error404(self, transaction): 
    488486        """Error page to display when resolver fails.""" 
    489         start_response('404 Not Found', [('Content-Type', 'text/html')]) 
    490         request_uri = environ.get('REQUEST_URI') 
     487        transaction.response.status = '404 Not Found' 
     488        request_uri = transaction.request.environ.get('REQUEST_URI') 
    491489        if request_uri is None: 
    492             request_uri = environ.get('SCRIPT_NAME', '') + \ 
    493                           environ.get('PATH_INFO', '') 
     490            request_uri = transaction.request.environ.get('SCRIPT_NAME', '') + \ 
     491                          transaction.request.environ.get('PATH_INFO', '') 
    494492        return ["""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
    495493<html><head> 
     
    500498<hr> 
    501499%s</body></html> 
    502 """ % (request_uri, environ.get('SERVER_SIGNATURE', ''))] 
     500""" % (request_uri, transaction.request.environ.get('SERVER_SIGNATURE', ''))] 
    503501 
    504502class File(object): 
  • flup/resolver/complex.py

    r25 r28  
    5555    _slashRE = re.compile(r'''/{2,}''') 
    5656 
    57     def __init__(self, **kw): 
    58         super(ComplexResolver, self).__init__(**kw) 
     57    def __init__(self): 
    5958        self.resolverMap = {} 
    6059 
  • flup/resolver/function.py

    r25 r28  
    4040    the ComplexResolver. 
    4141    """ 
    42     def __init__(self, func, **kw): 
    43         super(FunctionResolver, self).__init__(**kw) 
     42    def __init__(self, func): 
    4443        self._func = func 
    4544 
  • flup/resolver/importingmodule.py

    r25 r28  
    6363    index_page = 'index' 
    6464 
    65     def __init__(self, path, defaultModule=NoDefault, index=NoDefault, **kw): 
    66         super(ImportingModuleResolver, self).__init__(**kw) 
     65    def __init__(self, path, defaultModule=NoDefault, index=NoDefault): 
    6766        self.path = path 
    6867        if defaultModule is not NoDefault: 
  • flup/resolver/module.py

    r25 r28  
    5353    index_page = 'index' 
    5454     
    55     def __init__(self, module, index=NoDefault, **kw): 
    56         super(ModuleResolver, self).__init__(**kw) 
     55    def __init__(self, module, index=NoDefault): 
    5756        self.module = module 
    5857        if index is not NoDefault: 
  • flup/resolver/nopathinfo.py

    r25 r28  
    3838    slash. 
    3939    """ 
    40     def __init__(self, resolver, allowTrailingSlash=False, **kw): 
    41         super(NoPathInfoResolver, self).__init__(**kw) 
     40    def __init__(self, resolver, allowTrailingSlash=False): 
    4241        self._resolver = resolver 
    4342        self._allowTrailingSlash = allowTrailingSlash 
  • flup/resolver/objectpath.py

    r25 r28  
    5757 
    5858    def __init__(self, root, index=NoDefault, default=NoDefault, 
    59                  favorIndex=True, **kw): 
     59                 favorIndex=True): 
    6060        """ 
    6161        root is the root object of your URL hierarchy. In CherryPy, this 
     
    6767        True, the index method will be called. Otherwise, the default method. 
    6868        """ 
    69         super(ObjectPathResolver, self).__init__(**kw) 
    7069        self.root = root 
    7170        if index is not NoDefault: 
  • flup/resolver/resolver.py

    r25 r28  
    4444    When resolving an InternalRedirect, redirect will be True. 
    4545    """ 
    46     def __init__(self, error404=None): 
    47         self.error404 = error404 
    48  
    4946    def resolve(self, request, redirect=False): 
    5047        raise NotImplementedError, self.__class__.__name__ + '.resolve'