Django

Code

Show
Ignore:
Timestamp:
03/07/08 21:46:33 (9 months ago)
Author:
gwilson
Message:

A few styling fixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/http/__init__.py

    r7204 r7205  
    44from urllib import urlencode 
    55from urlparse import urljoin 
    6 from django.utils.datastructures import MultiValueDict, FileDict 
    7 from django.utils.encoding import smart_str, iri_to_uri, force_unicode 
    8 from utils import * 
    9  
    10 RESERVED_CHARS="!*'();:@&=+$,/?%#[]" 
    11  
    126try: 
    137    # The mod_python version is more efficient, so try importing it first. 
     
    1610    from cgi import parse_qsl 
    1711 
     12from django.utils.datastructures import MultiValueDict, FileDict 
     13from django.utils.encoding import smart_str, iri_to_uri, force_unicode 
     14 
     15from utils import * 
     16 
     17RESERVED_CHARS="!*'();:@&=+$,/?%#[]" 
     18 
     19 
    1820class Http404(Exception): 
    1921    pass 
    2022 
    2123class HttpRequest(object): 
    22     "A basic HTTP request
     24    """A basic HTTP request.""
    2325 
    2426    # The encoding used in GET/POST dicts. None means use default setting. 
     
    4749 
    4850    def get_host(self): 
    49         "Returns the HTTP host using the environment or request headers.
     51        """Returns the HTTP host using the environment or request headers.""
    5052        # We try three options, in order of decreasing preference. 
    5153        if 'HTTP_X_FORWARDED_HOST' in self.META: 
     
    99101 
    100102def parse_file_upload(header_dict, post_data): 
    101     "Returns a tuple of (POST QueryDict, FILES MultiValueDict)
     103    """Returns a tuple of (POST QueryDict, FILES MultiValueDict).""
    102104    import email, email.Message 
    103105    from cgi import parse_header 
     
    131133    return POST, FILES 
    132134 
     135 
    133136class QueryDict(MultiValueDict): 
    134137    """ 
     
    149152        self._mutable = True 
    150153        for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 
    151             self.appendlist(force_unicode(key, encoding, errors='replace'), force_unicode(value, encoding, errors='replace')) 
     154            self.appendlist(force_unicode(key, encoding, errors='replace'), 
     155                            force_unicode(value, encoding, errors='replace')) 
    152156        self._mutable = mutable 
    153157 
    154158    def _assert_mutable(self): 
    155159        if not self._mutable: 
    156             raise AttributeError, "This QueryDict instance is immutable" 
     160            raise AttributeError("This QueryDict instance is immutable") 
    157161 
    158162    def __setitem__(self, key, value): 
     
    223227 
    224228    def copy(self): 
    225         "Returns a mutable copy of this object.
     229        """Returns a mutable copy of this object.""
    226230        return self.__deepcopy__({}) 
    227231 
     
    244248 
    245249class HttpResponse(object): 
    246     "A basic HTTP response, with content and dictionary-accessed headers
     250    """A basic HTTP response, with content and dictionary-accessed headers.""
    247251 
    248252    status_code = 200 
     
    273277 
    274278    def __str__(self): 
    275         "Full HTTP message, including headers
     279        """Full HTTP message, including headers.""
    276280        return '\n'.join(['%s: %s' % (key, value) 
    277281            for key, value in self._headers.values()]) \ 
     
    279283 
    280284    def _convert_to_ascii(self, *values): 
    281         "Convert all values to ascii strings
     285        """Converts all values to ascii strings.""
    282286        for value in values: 
    283287            if isinstance(value, unicode): 
     
    304308 
    305309    def has_header(self, header): 
    306         "Case-insensitive check for a header
     310        """Case-insensitive check for a header.""
    307311        return self._headers.has_key(header.lower()) 
    308312 
     
    315319        return self._headers.get(header.lower(), (None, alternate))[1] 
    316320 
    317     def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=False): 
     321    def set_cookie(self, key, value='', max_age=None, expires=None, path='/', 
     322                   domain=None, secure=False): 
    318323        self.cookies[key] = value 
    319324        if max_age is not None: 
     
    330335    def delete_cookie(self, key, path='/', domain=None): 
    331336        self.set_cookie(key, max_age=0, path=path, domain=domain, 
    332                 expires='Thu, 01-Jan-1970 00:00:00 GMT') 
     337                        expires='Thu, 01-Jan-1970 00:00:00 GMT') 
    333338 
    334339    def _get_content(self): 
     
    361366    def write(self, content): 
    362367        if not self._is_string: 
    363             raise Exception, "This %s instance is not writable" % self.__class__ 
     368            raise Exception("This %s instance is not writable" % self.__class__) 
    364369        self._container.append(content) 
    365370 
     
    369374    def tell(self): 
    370375        if not self._is_string: 
    371             raise Exception, "This %s instance cannot tell its position" % self.__class__ 
     376            raise Exception("This %s instance cannot tell its position" % self.__class__) 
    372377        return sum([len(chunk) for chunk in self._container]) 
    373378 
     
    426431def str_to_unicode(s, encoding): 
    427432    """ 
    428     Convert basestring objects to unicode, using the given encoding. Illegaly 
     433    Converts basestring objects to unicode, using the given encoding. Illegally 
    429434    encoded input characters are replaced with Unicode "unknown" codepoint 
    430435    (\ufffd). 
     
    436441    else: 
    437442        return s 
    438