Django

Code

Changeset 7820

Show
Ignore:
Timestamp:
07/01/08 23:34:05 (3 months ago)
Author:
gwilson
Message:

Minor style fixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/test/client.py

    r7814 r7820  
    66except ImportError: 
    77    from StringIO import StringIO 
     8 
    89from django.conf import settings 
    910from django.contrib.auth import authenticate, login 
     
    2324MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY 
    2425 
     26 
    2527class FakePayload(object): 
    2628    """ 
     
    4244        return content 
    4345 
     46 
    4447class ClientHandler(BaseHandler): 
    4548    """ 
     
    6265            response = self.get_response(request) 
    6366 
    64             # Apply response middleware 
     67            # Apply response middleware. 
    6568            for middleware_method in self._response_middleware: 
    6669                response = middleware_method(request, response) 
     
    7275 
    7376def store_rendered_templates(store, signal, sender, template, context): 
    74     "A utility function for storing templates and contexts that are rendered" 
     77    """ 
     78    Stores templates and contexts that are rendered. 
     79    """ 
    7580    store.setdefault('template',[]).append(template) 
    7681    store.setdefault('context',[]).append(context) 
     
    7883def encode_multipart(boundary, data): 
    7984    """ 
    80     A simple method for encoding multipart POST data from a dictionary of 
    81     form values. 
     85    Encodes multipart POST data from a dictionary of form values. 
    8286 
    8387    The key will be used as the form data name; the value will be transmitted 
     
    9195            lines.extend([ 
    9296                '--' + boundary, 
    93                 'Content-Disposition: form-data; name="%s"; filename="%s"' % (to_str(key), to_str(os.path.basename(value.name))), 
     97                'Content-Disposition: form-data; name="%s"; filename="%s"' \ 
     98                    % (to_str(key), to_str(os.path.basename(value.name))), 
    9499                'Content-Type: application/octet-stream', 
    95100                '', 
     
    145150    def store_exc_info(self, *args, **kwargs): 
    146151        """ 
    147         Utility method that can be used to store exceptions when they are 
    148         generated by a view. 
     152        Stores exceptions when they are generated by a view. 
    149153        """ 
    150154        self.exc_info = sys.exc_info() 
    151155 
    152156    def _session(self): 
    153         "Obtain the current session variables" 
     157        """ 
     158        Obtains the current session variables. 
     159        """ 
    154160        if 'django.contrib.sessions' in settings.INSTALLED_APPS: 
    155161            engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 
     
    167173        using the arguments to the request. 
    168174        """ 
    169  
    170175        environ = { 
    171176            'HTTP_COOKIE':      self.cookies, 
     
    181186        environ.update(request) 
    182187 
    183         # Curry a data dictionary into an instance of 
    184         # the template renderer callback function 
     188        # Curry a data dictionary into an instance of the template renderer 
     189        # callback function. 
    185190        data = {} 
    186191        on_template_render = curry(store_rendered_templates, data) 
    187192        dispatcher.connect(on_template_render, signal=signals.template_rendered) 
    188193 
    189         # Capture exceptions created by the handler 
     194        # Capture exceptions created by the handler. 
    190195        dispatcher.connect(self.store_exc_info, signal=got_request_exception) 
    191196 
     
    210215            self.exc_info = None 
    211216            raise exc_info[1], None, exc_info[2] 
    212              
    213         # Save the client and request that stimulated the response 
     217 
     218        # Save the client and request that stimulated the response. 
    214219        response.client = self 
    215220        response.request = request 
    216221 
    217         # Add any rendered template detail to the response 
     222        # Add any rendered template detail to the response. 
    218223        # If there was only one template rendered (the most likely case), 
    219         # flatten the list to a single element 
     224        # flatten the list to a single element. 
    220225        for detail in ('template', 'context'): 
    221226            if data.get(detail): 
     
    227232                setattr(response, detail, None) 
    228233 
    229         # Update persistent cookie data 
     234        # Update persistent cookie data. 
    230235        if response.cookies: 
    231236            self.cookies.update(response.cookies) 
     
    234239 
    235240    def get(self, path, data={}, **extra): 
    236         "Request a response from the server using GET." 
     241        """ 
     242        Requests a response from the server using GET. 
     243        """ 
    237244        r = { 
    238245            'CONTENT_LENGTH':  None, 
     
    247254 
    248255    def post(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): 
    249         "Request a response from the server using POST." 
    250  
     256        """ 
     257        Requests a response from the server using POST. 
     258        """ 
    251259        if content_type is MULTIPART_CONTENT: 
    252260            post_data = encode_multipart(BOUNDARY, data) 
     
    266274 
    267275    def login(self, **credentials): 
    268         """Set the Client to appear as if it has sucessfully logged into a site. 
     276        """ 
     277        Sets the Client to appear as if it has successfully logged into a site. 
    269278 
    270279        Returns True if login is possible; False if the provided credentials 
     
    273282        """ 
    274283        user = authenticate(**credentials) 
    275         if user and user.is_active and 'django.contrib.sessions' in settings.INSTALLED_APPS: 
     284        if user and user.is_active \ 
     285                and 'django.contrib.sessions' in settings.INSTALLED_APPS: 
    276286            engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 
    277287 
    278             # Create a fake request to store login details 
     288            # Create a fake request to store login details. 
    279289            request = HttpRequest() 
    280290            request.session = engine.SessionStore() 
    281291            login(request, user) 
    282292 
    283             # Set the cookie to represent the session 
     293            # Set the cookie to represent the session. 
    284294            self.cookies[settings.SESSION_COOKIE_NAME] = request.session.session_key 
    285295            self.cookies[settings.SESSION_COOKIE_NAME]['max-age'] = None 
     
    289299            self.cookies[settings.SESSION_COOKIE_NAME]['expires'] = None 
    290300 
    291             # Save the session values 
     301            # Save the session values. 
    292302            request.session.save() 
    293303 
     
    297307 
    298308    def logout(self): 
    299         """Removes the authenticated user's cookies. 
     309        """ 
     310        Removes the authenticated user's cookies. 
    300311 
    301312        Causes the authenticated user to be logged out.