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

Changeset 2431

Show
Ignore:
Timestamp:
06/14/09 13:57:47
Author:
fumanchu
Message:

Some syncs with python3.

Files:

Legend:

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

    r2429 r2431  
    77# to a public caning. 
    88 
     9from binascii import b2a_base64 
    910from BaseHTTPServer import BaseHTTPRequestHandler 
    1011response_codes = BaseHTTPRequestHandler.responses.copy() 
     
    375376    """ 
    376377     
     378    protocol=(1, 1) 
     379     
    377380    def elements(self, key): 
    378381        """Return a sorted list of HeaderElements for the given header.""" 
     
    381384        return header_elements(key, value) 
    382385     
    383     def output(self, protocol=(1, 1)): 
     386    def output(self): 
    384387        """Transform self into a list of (name, value) tuples.""" 
    385388        header_list = [] 
     
    392395             
    393396            if isinstance(v, unicode): 
    394                 # HTTP/1.0 says, "Words of *TEXT may contain octets  
    395                 # from character sets other than US-ASCII." and  
    396                 # "Recipients of header field TEXT containing octets  
    397                 # outside the US-ASCII character set may assume that  
    398                 # they represent ISO-8859-1 characters."  
    399                 try: 
    400                     v = v.encode("ISO-8859-1") 
    401                 except UnicodeEncodeError: 
    402                     if protocol == (1, 1): 
    403                         # Encode RFC-2047 TEXT  
    404                         # (e.g. u"\u8200" -> "=?utf-8?b?6IiA?=").  
    405                         # We do our own here instead of using the email module 
    406                         # because we never want to fold lines--folding has 
    407                         # been deprecated by the HTTP working group. 
    408                         from binascii import b2a_base64 
    409                         v = '=?utf-8?b?%s?=' % b2a_base64(v.encode('utf-8')).strip('\n') 
    410                     else: 
    411                         raise 
     397                v = self.encode(v) 
    412398            header_list.append((k, v)) 
    413399        return header_list 
    414  
    415  
     400     
     401    def encode(self, v): 
     402        """Return the given header value, encoded for HTTP output.""" 
     403        # HTTP/1.0 says, "Words of *TEXT may contain octets  
     404        # from character sets other than US-ASCII." and  
     405        # "Recipients of header field TEXT containing octets  
     406        # outside the US-ASCII character set may assume that  
     407        # they represent ISO-8859-1 characters."  
     408        try: 
     409            v = v.encode("ISO-8859-1") 
     410        except UnicodeEncodeError: 
     411            if self.protocol == (1, 1): 
     412                # Encode RFC-2047 TEXT  
     413                # (e.g. u"\u8200" -> "=?utf-8?b?6IiA?=").  
     414                # We do our own here instead of using the email module 
     415                # because we never want to fold lines--folding has 
     416                # been deprecated by the HTTP working group. 
     417                v = b2a_base64(v.encode('utf-8')) 
     418                v = ('=?utf-8?b?' + v.strip('\n') + '?=') 
     419            else: 
     420                raise 
     421        return v 
    416422 
    417423class Host(object): 
  • trunk/cherrypy/wsgiserver/__init__.py

    r2429 r2431  
    150150    apps: a dict or list of (path_prefix, app) pairs. 
    151151    """ 
    152  
     152     
    153153    def __init__(self, apps): 
    154154        try: 
     
    156156        except AttributeError: 
    157157            pass 
    158  
     158         
    159159        # Sort the apps by len(path), descending 
    160160        apps.sort(cmp=lambda x,y: cmp(len(x[0]), len(y[0]))) 
    161161        apps.reverse() 
    162  
     162   
    163163        # The path_prefix strings must start, but not end, with a slash. 
    164164        # Use "" instead of "/". 
     
    707707        except TypeError: 
    708708            if not isinstance(k, str): 
    709                 raise TypeError("WSGI response header key %r is not a string.") 
     709                raise TypeError("WSGI response header key %r is not a byte string.") 
    710710            if not isinstance(v, str): 
    711                 raise TypeError("WSGI response header value %r is not a string.") 
     711                raise TypeError("WSGI response header value %r is not a byte string.") 
    712712            else: 
    713713                raise 

Hosted by WebFaction

Log in as guest/cpguest to create tickets