Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1288

Show
Ignore:
Timestamp:
08/28/06 13:39:08
Author:
fumanchu
Message:

Tweaks to docs, line lengths, tests, and number of serving lookups.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/LICENSE.txt

    r768 r1288  
    1 Copyright (c) 2004-2005, CherryPy Team (team@cherrypy.org) 
     1Copyright (c) 2004-2006, CherryPy Team (team@cherrypy.org) 
    22All rights reserved. 
    33 
  • trunk/cherrypy/__init__.py

    r1285 r1288  
    139139        return expose_(func) 
    140140    else: 
    141         # expose is being called as a decorator 
    142141        if alias is None: 
    143             alias = func 
    144         return expose_ 
     142            # expose is being called as a decorator "@expose" 
     143            func.exposed = True 
     144            return func 
     145        else: 
     146            # expose is returning a decorator "@expose(alias=...)" 
     147            return expose_ 
    145148 
    146149 
  • trunk/cherrypy/_cpconfig.py

    r1285 r1288  
    170170        elif namespace == "log": 
    171171            setattr(cherrypy.log, atoms[1], v) 
    172      
    173     def wrap(**kwargs): 
    174         """Decorator to set _cp_config on a handler using the given kwargs.""" 
    175         def wrapper(f): 
    176             if not hasattr(f, "_cp_config"): 
    177                 f._cp_config = {} 
    178             f._cp_config.update(kwargs) 
    179             return f 
    180         return wrapper 
    181     wrap = staticmethod(wrap) 
    182172 
    183173 
  • trunk/cherrypy/_cprequest.py

    r1285 r1288  
    240240        resource, vpath = self.find_handler(path_info) 
    241241         
    242         # Decode any leftover %2F in the virtual_path atoms. 
    243         vpath = [x.replace("%2F", "/") for x in vpath] 
    244          
    245242        if resource: 
    246243            # Set Allow header 
     
    252249             
    253250            # Find the subhandler 
    254             meth = cherrypy.request.method.upper() 
     251            meth = request.method.upper() 
    255252            func = getattr(resource, meth, None) 
    256253            if func is None and meth == "HEAD": 
    257254                func = getattr(resource, "GET", None) 
    258255            if func: 
     256                # Decode any leftover %2F in the virtual_path atoms. 
     257                vpath = [x.replace("%2F", "/") for x in vpath] 
    259258                request.handler = LateParamPageHandler(func, *vpath) 
    260259            else: 
  • trunk/cherrypy/lib/caching.py

    r1278 r1288  
    2828     
    2929    def _key(self): 
    30         return cherrypy.request.config.get("tools.caching.key", cherrypy.request.browser_url) 
     30        return cherrypy.request.config.get("tools.caching.key", 
     31                                           cherrypy.request.browser_url) 
    3132    key = property(_key) 
    3233     
     
    9091 
    9192def get(): 
     93    request = cherrypy.request 
    9294    # Ignore POST, PUT, DELETE. 
    9395    # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10. 
    94     invalid = cherrypy.request.config.get("tools.caching.invalid_methods", 
    95                                           ("POST", "PUT", "DELETE")) 
    96     if cherrypy.request.method in invalid: 
    97         cherrypy.request.cached = c = False 
     96    invalid = request.config.get("tools.caching.invalid_methods", 
     97                                 ("POST", "PUT", "DELETE")) 
     98    if request.method in invalid: 
     99        request.cached = c = False 
    98100    else: 
    99101        cache_data = cherrypy._cache.get() 
    100         cherrypy.request.cached = c = bool(cache_data) 
     102        request.cached = c = bool(cache_data) 
    101103     
    102104    if c: 
     
    183185    """ 
    184186     
     187    response = cherrypy.response 
     188     
    185189    cacheable = False 
    186190    if not force: 
    187191        # some header names that indicate that the response can be cached 
    188192        for indicator in ('Etag', 'Last-Modified', 'Age', 'Expires'): 
    189             if indicator in cherrypy.response.headers: 
     193            if indicator in response.headers: 
    190194                cacheable = True 
    191195                break 
     
    196200         
    197201        if secs == 0: 
    198             if force or "Pragma" not in cherrypy.response.headers: 
    199                 cherrypy.response.headers["Pragma"] = "no-cache" 
     202            if force or "Pragma" not in response.headers: 
     203                response.headers["Pragma"] = "no-cache" 
    200204            if cherrypy.request.protocol >= (1, 1): 
    201                 if force or "Cache-Control" not in cherrypy.response.headers: 
    202                     cherrypy.response.headers["Cache-Control"] = "no-cache" 
    203          
    204         expiry = http.HTTPDate(cherrypy.response.time + secs) 
    205         if force or "Expires" not in cherrypy.response.headers: 
    206             cherrypy.response.headers["Expires"] = expiry 
     205                if force or "Cache-Control" not in response.headers: 
     206                    response.headers["Cache-Control"] = "no-cache" 
     207         
     208        expiry = http.HTTPDate(response.time + secs) 
     209        if force or "Expires" not in response.headers: 
     210            response.headers["Expires"] = expiry 
  • trunk/cherrypy/lib/cptools.py

    r1276 r1288  
    1616    checks will be performed against If-Match or If-None-Match headers. 
    1717    """ 
     18    response = cherrypy.response 
     19     
    1820    # Guard against being run twice. 
    19     if hasattr(cherrypy.response, "ETag"): 
     21    if hasattr(response, "ETag"): 
    2022        return 
    2123     
    22     etag = cherrypy.response.headers.get('ETag') 
     24    etag = response.headers.get('ETag') 
    2325     
    2426    if (not etag) and autotags: 
    2527        import md5 
    26         etag = '"%s"' % md5.new(cherrypy.response.collapse_body()).hexdigest() 
    27         cherrypy.response.headers['ETag'] = etag 
     28        etag = '"%s"' % md5.new(response.collapse_body()).hexdigest() 
     29        response.headers['ETag'] = etag 
    2830     
    2931    if etag: 
    30         cherrypy.response.ETag = etag 
    31          
    32         status, reason, msg = _http.valid_status(cherrypy.response.status) 
    33          
    34         conditions = cherrypy.request.headers.elements('If-Match') or [] 
     32        response.ETag = etag 
     33         
     34        status, reason, msg = _http.valid_status(response.status) 
     35         
     36        request = cherrypy.request 
     37         
     38        conditions = request.headers.elements('If-Match') or [] 
    3539        conditions = [str(x) for x in conditions] 
    3640        if conditions and not (conditions == ["*"] or etag in conditions): 
     
    3842                raise cherrypy.HTTPError(412) 
    3943         
    40         conditions = cherrypy.request.headers.elements('If-None-Match') or [] 
     44        conditions = request.headers.elements('If-None-Match') or [] 
    4145        conditions = [str(x) for x in conditions] 
    4246        if conditions == ["*"] or etag in conditions: 
    4347            if status >= 200 and status < 299: 
    44                 if cherrypy.request.method in ("GET", "HEAD"): 
     48                if request.method in ("GET", "HEAD"): 
    4549                    raise cherrypy.HTTPRedirect([], 304) 
    4650                else: 
     
    5357    will be performed. 
    5458    """ 
    55     lastmod = cherrypy.response.headers.get('Last-Modified') 
     59    response = cherrypy.response 
     60    lastmod = response.headers.get('Last-Modified') 
    5661    if lastmod: 
    57         status, reason, msg = _http.valid_status(cherrypy.response.status) 
    58          
    59         since = cherrypy.request.headers.get('If-Unmodified-Since') 
     62        status, reason, msg = _http.valid_status(response.status) 
     63         
     64        request = cherrypy.request 
     65         
     66        since = request.headers.get('If-Unmodified-Since') 
    6067        if since and since != lastmod: 
    6168            if (status >= 200 and status < 299) or status == 412: 
    6269                raise cherrypy.HTTPError(412) 
    6370         
    64         since = cherrypy.request.headers.get('If-Modified-Since') 
     71        since = request.headers.get('If-Modified-Since') 
    6572        if since and since == lastmod: 
    6673            if (status >= 200 and status < 299) or status == 304: 
    67                 if cherrypy.request.method in ("GET", "HEAD"): 
     74                if request.method in ("GET", "HEAD"): 
    6875                    raise cherrypy.HTTPRedirect([], 304) 
    6976                else: 
     
    211218    their own right. 
    212219    """ 
    213     if hasattr(cherrypy.request, "virtual_prefix"): 
     220    request = cherrypy.request 
     221     
     222    if hasattr(request, "virtual_prefix"): 
    214223        return 
    215224     
    216     domain = cherrypy.request.headers.get('Host', '') 
     225    domain = request.headers.get('Host', '') 
    217226    if use_x_forwarded_host: 
    218         domain = cherrypy.request.headers.get("X-Forwarded-Host", domain) 
    219      
    220     cherrypy.request.virtual_prefix = prefix = domains.get(domain, "") 
     227        domain = request.headers.get("X-Forwarded-Host", domain) 
     228     
     229    request.virtual_prefix = prefix = domains.get(domain, "") 
    221230    if prefix: 
    222         raise cherrypy.InternalRedirect(_http.urljoin(prefix, cherrypy.request.path_info)) 
     231        raise cherrypy.InternalRedirect(_http.urljoin(prefix, request.path_info)) 
    223232 
    224233def log_traceback(): 
  • trunk/cherrypy/lib/wsgiapp.py

    r1275 r1288  
    1818    """ 
    1919     
     20    request = cherrypy.request 
     21     
    2022    # create and populate the wsgi environ 
    2123    environ = dict() 
    2224    environ["wsgi.version"] = (1,0) 
    23     environ["wsgi.url_scheme"] = cherrypy.request.scheme 
    24     environ["wsgi.input"] = cherrypy.request.rfile 
     25    environ["wsgi.url_scheme"] = request.scheme 
     26    environ["wsgi.input"] = request.rfile 
    2527    environ["wsgi.errors"] = sys.stderr 
    2628    environ["wsgi.multithread"] = True 
    2729    environ["wsgi.multiprocess"] = False 
    2830    environ["wsgi.run_once"] = False 
    29     environ["REQUEST_METHOD"] = cherrypy.request.method 
    30     environ["SCRIPT_NAME"] = cherrypy.request.script_name 
    31     environ["PATH_INFO"] = cherrypy.request.path_info 
    32     environ["QUERY_STRING"] = cherrypy.request.query_string 
    33     environ["SERVER_PROTOCOL"] = cherrypy.request.protocol 
    34     environ["SERVER_NAME"] = cherrypy.request.local.name 
    35     environ["SERVER_PORT"] = cherrypy.request.local.port 
    36     environ["REMOTE_HOST"] = cherrypy.request.remote.name 
    37     environ["REMOTE_ADDR"] = cherrypy.request.remote.ip 
    38     environ["REMOTE_PORT"] = cherrypy.request.remote.port 
     31    environ["REQUEST_METHOD"] = request.method 
     32    environ["SCRIPT_NAME"] = request.script_name 
     33    environ["PATH_INFO"] = request.path_info 
     34    environ["QUERY_STRING"] = request.query_string 
     35    environ["SERVER_PROTOCOL"] = request.protocol 
     36    environ["SERVER_NAME"] = request.local.name 
     37    environ["SERVER_PORT"] = request.local.port 
     38    environ["REMOTE_HOST"] = request.remote.name 
     39    environ["REMOTE_ADDR"] = request.remote.ip 
     40    environ["REMOTE_PORT"] = request.remote.port 
    3941    # then all the http headers 
    40     headers = cherrypy.request.headers 
     42    headers = request.headers 
    4143    environ["CONTENT_TYPE"] = headers.get("Content-type", "") 
    4244    environ["CONTENT_LENGTH"] = headers.get("Content-length", "") 
  • trunk/cherrypy/test/test_config.py

    r1281 r1288  
    1515                      'bar': 'that'} 
    1616         
     17        # @cherrypy.expose(alias=('global_', 'xyz')) 
    1718        def index(self, key): 
    1819            return cherrypy.request.config.get(key, "None") 
    19         index.exposed = True 
    20         global_ = index 
    21         xyz = index 
     20        index = cherrypy.expose(index, alias=('global_', 'xyz')) 
    2221     
    2322    class Foo: 
  • trunk/cherrypy/test/test_conn.py

    r1286 r1288  
    44import httplib 
    55import socket 
     6import sys 
    67import time 
    78 
     
    152153            conn._send_output() 
    153154            response = conn.response_class(conn.sock, method="GET") 
    154             self.assertRaises(socket.error, response.begin) 
     155            try: 
     156                response.begin() 
     157            except: 
     158                if not isinstance(sys.exc_info()[1], 
     159                                  (socket.error, httplib.BadStatusLine)): 
     160                    self.fail("Writing to timed out socket didn't fail" 
     161                              " as it should have: %s" % sys.exc_info()[1]) 
     162            else: 
     163                self.fail("Writing to timed out socket didn't fail" 
     164                          " as it should have.") 
    155165             
    156166            conn.close() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets