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

Changeset 1199

Show
Ignore:
Timestamp:
07/10/06 23:26:01
Author:
fumanchu
Message:

Precompile some regexes for a speed boost.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/http.py

    r1168 r1199  
    130130 
    131131 
     132q_separator = re.compile(r'; *q *=') 
     133 
    132134class AcceptElement(HeaderElement): 
    133135    """An element (with parameters) from an Accept-* header's element list.""" 
     
    137139        # The first "q" parameter (if any) separates the initial 
    138140        # parameter(s) (if any) from the accept-params. 
    139         atoms = re.split(r'; *q *=', elementstr, 1) 
     141        atoms = q_separator.split(elementstr, 1) 
    140142        initial_value = atoms.pop(0).strip() 
    141143        if atoms: 
     
    254256    return code, reason, message 
    255257 
     258 
     259quoted_slash = re.compile("(?i)%2F") 
     260 
    256261def parse_request_line(request_line): 
    257262    """Return (method, path, querystring, protocol) from a request_line.""" 
     
    276281    # 
    277282    # Note also that cgi.parse_qs will decode the querystring for us. 
    278     atoms = [unquote(x) for x in re.split("(?i)%2F", path)] 
     283    atoms = [unquote(x) for x in quoted_slash.split(path)] 
    279284    path = "%2F".join(atoms) 
    280285     
    281286    return method, path, qs, protocol 
     287 
     288 
     289image_map_pattern = re.compile(r"[0-9]+,[0-9]+") 
    282290 
    283291def parseQueryString(query_string, keep_blank_values=True): 
    284292    """Build a paramMap dictionary from a query_string.""" 
    285     if re.match(r"[0-9]+,[0-9]+", query_string): 
     293    if image_map_pattern.match(query_string): 
    286294        # Server-side image map. Map the coords to 'x' and 'y' 
    287295        # (like CGI::Request does). 

Hosted by WebFaction

Log in as guest/cpguest to create tickets