Changeset 881
- Timestamp:
- 10/15/05 18:10:35 (3 years ago)
- Files:
-
- django/branches/new-admin/django/conf/global_settings.py (modified) (1 diff)
- django/branches/new-admin/django/conf/project_template/settings/main.py (modified) (1 diff)
- django/branches/new-admin/django/core/db/backends/ado_mssql.py (copied) (copied from django/trunk/django/core/db/backends/ado_mssql.py)
- django/branches/new-admin/django/core/handlers/base.py (modified) (4 diffs)
- django/branches/new-admin/django/core/meta/__init__.py (modified) (1 diff)
- django/branches/new-admin/django/core/template/__init__.py (modified) (6 diffs)
- django/branches/new-admin/django/utils/decorators.py (modified) (1 diff)
- django/branches/new-admin/docs/middleware.txt (modified) (1 diff)
- django/branches/new-admin/tests/othertests/templates.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/new-admin/django/conf/global_settings.py
r876 r881 46 46 47 47 # Database connection info. 48 DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', or 'sqlite3'.49 DATABASE_NAME = '' 50 DATABASE_USER = '' 51 DATABASE_PASSWORD = '' 52 DATABASE_HOST = '' # Set to empty string for localhost. 53 DATABASE_PORT = '' # Set to empty string for default. 48 DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. 49 DATABASE_NAME = '' # Or path to database file if using sqlite3. 50 DATABASE_USER = '' # Not used with sqlite3. 51 DATABASE_PASSWORD = '' # Not used with sqlite3. 52 DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. 53 DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. 54 54 55 55 # Host for sending e-mail. django/branches/new-admin/django/conf/project_template/settings/main.py
r864 r881 11 11 LANGUAGE_CODE = 'en-us' 12 12 13 DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', or 'sqlite3'.13 DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. 14 14 DATABASE_NAME = '' # Or path to database file if using sqlite3. 15 15 DATABASE_USER = '' # Not used with sqlite3. django/branches/new-admin/django/core/handlers/base.py
r580 r881 3 3 class BaseHandler: 4 4 def __init__(self): 5 self._request_middleware = self._view_middleware = self._response_middleware = None5 self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None 6 6 7 7 def load_middleware(self): … … 16 16 self._view_middleware = [] 17 17 self._response_middleware = [] 18 self._exception_middleware = [] 18 19 for middleware_path in settings.MIDDLEWARE_CLASSES: 19 20 dot = middleware_path.rindex('.') … … 39 40 if hasattr(mw_instance, 'process_response'): 40 41 self._response_middleware.insert(0, mw_instance.process_response) 42 if hasattr(mw_instance, 'process_exception'): 43 self._exception_middleware.insert(0, mw_instance.process_exception) 41 44 42 45 def get_response(self, path, request): … … 62 65 return response 63 66 64 response = callback(request, **param_dict) 67 try: 68 response = callback(request, **param_dict) 69 except Exception, e: 70 # If the view raised an exception, run it through exception 71 # middleware, and if the exception middleware returns a 72 # response, use that. Otherwise, reraise the exception. 73 for middleware_method in self._exception_middleware: 74 response = middleware_method(request, e) 75 if response: 76 return response 77 raise e 65 78 66 79 # Complain if the view returned None (a common error). django/branches/new-admin/django/core/meta/__init__.py
r864 r881 692 692 693 693 # Give the class a docstring -- its definition. 694 new_class.__doc__ = "%s.%s(%s)" % (opts.module_name, name, ", ".join([f.name for f in opts.fields])) 694 if new_class.__doc__ is None: 695 new_class.__doc__ = "%s.%s(%s)" % (opts.module_name, name, ", ".join([f.name for f in opts.fields])) 695 696 696 697 # Create the standard, module-level API helper functions such django/branches/new-admin/django/core/template/__init__.py
r876 r881 191 191 self.contents[:20].replace('\n', '') 192 192 ) 193 194 def __repr__(self): 195 return '<%s token: "%s">' % ( 196 {TOKEN_TEXT:'Text', TOKEN_VAR:'Var', TOKEN_BLOCK:'Block'}[self.token_type], 197 self.contents[:].replace('\n', '') 198 ) 193 199 194 200 class Lexer(object): … … 229 235 linebreaks = self.find_linebreaks(self.template_string) 230 236 next_linebreak = linebreaks.next() 231 try: 232 for match in tag_re.finditer(self.template_string): 233 start, end = match.span() 234 if start > upto: 235 token_tups.append( (self.template_string[upto:start], line) ) 236 upto = start 237 238 while next_linebreak <= upto: 237 238 239 for match in tag_re.finditer(self.template_string): 240 start, end = match.span() 241 #print "%d:%d --- %s " % (start, end, self.template_string[start:end] ) 242 if start > upto: 243 token_tups.append( (self.template_string[upto:start], line) ) 244 upto = start 245 246 while next_linebreak <= upto: 247 try: 239 248 next_linebreak = linebreaks.next() 240 249 line += 1 241 242 token_tups.append( (self.template_string[start:end], line) ) 243 upto = end 244 245 while next_linebreak <= upto: 250 except StopIteration: 251 next_linebreak = len(self.template_string) 252 break 253 254 token_tups.append( (self.template_string[start:end], line) ) 255 upto = end 256 257 while next_linebreak <= upto: 258 try: 246 259 next_linebreak = linebreaks.next() 247 260 line += 1 248 except StopIteration: 249 pass 250 261 except StopIteration: 262 next_linebreak = len(self.template_string) 263 break 264 251 265 last_bit = self.template_string[upto:] 252 266 if len(last_bit): … … 261 275 return token 262 276 263 277 from pprint import pformat 264 278 class Parser(object): 265 279 def __init__(self, tokens): 266 280 self.tokens = tokens 281 #print pformat(self.tokens) 267 282 268 283 def parse(self, parse_until=[]): … … 297 312 298 313 if parse_until: 299 self.unclosed_block_tag(token )314 self.unclosed_block_tag(token, parse_until) 300 315 316 #print "-------------------------------" 317 #print pformat(nodelist) 318 #print "------------------------------" 301 319 return nodelist 302 320 … … 319 337 raise TemplateSyntaxError, "Invalid block tag: %s" % (command) 320 338 321 def unclosed_block_tag(self, token ):339 def unclosed_block_tag(self, token, parse_until): 322 340 raise TemplateSyntaxError, "Unclosed tags: %s " % ', '.join(parse_until) 323 341 … … 359 377 raise TemplateSyntaxError, "Invalid block tag: '%s' %s" % (command, self.format_source(token.source)) 360 378 361 def unclosed_block_tag(self, token ):379 def unclosed_block_tag(self, token, parse_until): 362 380 (command, (file,line)) = self.command_stack.pop() 363 381 msg = "Unclosed tag '%s' starting at %s, line %d. Looking for one of: %s " % \ django/branches/new-admin/django/utils/decorators.py
r854 r881 17 17 if result is not None: 18 18 return result 19 response = view_func(request, *args, **kwargs) 19 try: 20 response = view_func(request, *args, **kwargs) 21 except Exception, e: 22 if hasattr(middleware, 'process_exception'): 23 result = middleware.process_exception(request, e) 24 if result is not None: 25 return result 26 raise e 20 27 if hasattr(middleware, 'process_response'): 21 28 result = middleware.process_response(request, response) django/branches/new-admin/docs/middleware.txt
r819 r881 169 169 ``HttpResponse``. 170 170 171 process_exception 172 ----------------- 173 174 Interface: ``process_exception(self, request, exception)`` 175 176 ``request`` is an ``HttpRequest`` object. ``exception`` is an ``Exception`` 177 object raised by the view function. 178 179 Django calls ``process_exception()`` when a view raises an exception. 180 ``process_exception()`` should return either ``None`` or an ``HttpResponse`` 181 object. If it returns an ``HttpResponse`` object, the response will be returned 182 to the browser. Otherwise, default exception handling kicks in. 183 171 184 Guidelines 172 185 ---------- django/branches/new-admin/tests/othertests/templates.py
r876 r881 218 218 } 219 219 220 def cutdown(name): 221 global TEMPLATE_TESTS 222 TEMPLATE_TESTS = dict([ (name, TEMPLATE_TESTS[name])]) 223 print repr(TEMPLATE_TESTS[name]) 224 225 #cutdown('basic-syntax04') 226 220 227 # This replaces the standard template loader. 221 228 def test_template_loader(template_name, template_dirs=None): 222 229 try: 223 return TEMPLATE_TESTS[template_name][0]230 return ( TEMPLATE_TESTS[template_name][0] , "test:%s" % template_name ) 224 231 except KeyError: 225 232 raise template.TemplateDoesNotExist, template_name 226 233 227 234 def run_tests(verbosity=0, standalone=False): 228 loader.load_template_source, old_template_loader = test_template_loader, loader.load_template_source 235 # Register our custom template loader. 236 old_template_loaders = loader.template_source_loaders 237 loader.template_source_loaders = [test_template_loader] 238 229 239 failed_tests = [] 230 240 tests = TEMPLATE_TESTS.items() … … 249 259 print "Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output) 250 260 failed_tests.append(name) 251 loader. load_template_source = old_template_loader261 loader.template_source_loaders = old_template_loaders 252 262 253 263 if failed_tests and not standalone:
