diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index baf3baa5f0..b7c0ff8c5c 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -152,7 +152,7 @@ class BaseHandler(object): try: response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) finally: - receivers = signals.got_request_exception.send(sender=self.__class__, request=request) + signals.got_request_exception.send(sender=self.__class__, request=request) except exceptions.PermissionDenied: logger.warning( 'Forbidden (Permission denied): %s' % request.path, @@ -168,14 +168,14 @@ class BaseHandler(object): response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) finally: - receivers = signals.got_request_exception.send( + signals.got_request_exception.send( sender=self.__class__, request=request) except SystemExit: # Allow sys.exit() to actually exit. See tickets #1023 and #4701 raise except: # Handle everything else, including SuspiciousOperation, etc. # Get the exception info now, in case another exception is thrown later. - receivers = signals.got_request_exception.send(sender=self.__class__, request=request) + signals.got_request_exception.send(sender=self.__class__, request=request) response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) finally: # Reset URLconf for this thread on the way out for complete @@ -188,7 +188,7 @@ class BaseHandler(object): response = middleware_method(request, response) response = self.apply_response_fixes(request, response) except: # Any exception should be gathered and handled - receivers = signals.got_request_exception.send(sender=self.__class__, request=request) + signals.got_request_exception.send(sender=self.__class__, request=request) response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) return response diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index c66a0b0e29..ea494c7f0a 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -420,7 +420,7 @@ def setup_environ(settings_mod, original_settings_path=None): # Import the project module. We add the parent directory to PYTHONPATH to # avoid some of the path errors new users can have. sys.path.append(os.path.join(project_directory, os.pardir)) - project_module = import_module(project_name) + import_module(project_name) sys.path.pop() return project_directory diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index 501c494c2b..0426d19aac 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -1,7 +1,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.management.base import BaseCommand, CommandError from django.core import serializers -from django.db import connections, router, DEFAULT_DB_ALIAS +from django.db import router, DEFAULT_DB_ALIAS from django.utils.datastructures import SortedDict from optparse import make_option @@ -28,12 +28,11 @@ class Command(BaseCommand): args = '[appname appname.ModelName ...]' def handle(self, *app_labels, **options): - from django.db.models import get_app, get_apps, get_models, get_model + from django.db.models import get_app, get_apps, get_model format = options.get('format','json') indent = options.get('indent',None) using = options.get('database', DEFAULT_DB_ALIAS) - connection = connections[using] excludes = options.get('exclude',[]) show_traceback = options.get('traceback', False) use_natural_keys = options.get('use_natural_keys', False) diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index e4ce462c20..a8c9456e63 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -44,7 +44,7 @@ class Command(NoArgsCommand): # XXX: (Temporary) workaround for ticket #1796: force early loading of all # models from installed apps. from django.db.models.loading import get_models - loaded_models = get_models() + get_models() use_plain = options.get('plain', False) @@ -72,12 +72,12 @@ class Command(NoArgsCommand): # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system # conventions and get $PYTHONSTARTUP first then import user. - if not use_plain: - pythonrc = os.environ.get("PYTHONSTARTUP") - if pythonrc and os.path.isfile(pythonrc): - try: - execfile(pythonrc) - except NameError: + if not use_plain: + pythonrc = os.environ.get("PYTHONSTARTUP") + if pythonrc and os.path.isfile(pythonrc): + try: + execfile(pythonrc) + except NameError: pass # This will import .pythonrc.py as a side-effect import user diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 298882f503..19b7ec2cd7 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -127,7 +127,6 @@ def sql_custom(app, style, connection): output = [] app_models = get_models(app) - app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql')) for model in app_models: output.extend(custom_sql_for_model(model, style, connection)) diff --git a/django/core/validators.py b/django/core/validators.py index d51949308f..51ea82fba2 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -51,7 +51,7 @@ class URLValidator(RegexValidator): r'(?::\d+)?' # optional port r'(?:/?|[/?]\S+)$', re.IGNORECASE) - def __init__(self, verify_exists=False, + def __init__(self, verify_exists=False, validator_user_agent=URL_VALIDATOR_USER_AGENT): super(URLValidator, self).__init__() self.verify_exists = verify_exists @@ -99,7 +99,7 @@ class URLValidator(RegexValidator): req.get_method = lambda: 'HEAD' #Create an opener that does not support local file access opener = urllib2.OpenerDirector() - + #Don't follow redirects, but don't treat them as errors either error_nop = lambda *args, **kwargs: True http_error_processor = urllib2.HTTPErrorProcessor() @@ -114,10 +114,11 @@ class URLValidator(RegexValidator): http_error_processor] try: import ssl - handlers.append(urllib2.HTTPSHandler()) - except: - #Python isn't compiled with SSL support + except ImportError: + # Python isn't compiled with SSL support pass + else: + handlers.append(urllib2.HTTPSHandler()) map(opener.add_handler, handlers) opener.http_error_301 = lambda: True if platform.python_version_tuple() >= (2, 6): @@ -133,7 +134,7 @@ class URLValidator(RegexValidator): def validate_integer(value): try: int(value) - except (ValueError, TypeError), e: + except (ValueError, TypeError): raise ValidationError('') class EmailValidator(RegexValidator): @@ -145,7 +146,6 @@ class EmailValidator(RegexValidator): # Trivial case failed. Try for possible IDN domain-part if value and u'@' in value: parts = value.split(u'@') - domain_part = parts[-1] try: parts[-1] = parts[-1].encode('idna') except UnicodeError: diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 21863e2a3f..3606942add 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -607,7 +607,8 @@ def unordered_list(value, autoescape=None): if second_item == []: return [first_item], True try: - it = iter(second_item) # see if second item is iterable + # see if second item is iterable + iter(second_item) except TypeError: return list_, False old_style_list = True diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index e7cfae430e..06838cf21c 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -51,7 +51,7 @@ def token_kwargs(bits, parser, support_legacy=False): kwargs = {} while bits: - if kwarg_format: + if kwarg_format: match = kwarg_re.match(bits[0]) if not match or not match.group(1): return kwargs @@ -276,7 +276,6 @@ class IfChangedNode(Node): compare_to = None if compare_to != self._last_seen: - firstloop = (self._last_seen == None) self._last_seen = compare_to content = self.nodelist_true.render(context) return content