Ticket #6017: lax-option-parser.patch
| File lax-option-parser.patch, 2.9 kB (added by toddobryan, 2 years ago) |
|---|
-
django/core/management/__init__.py
old new 135 135 """ 136 136 def error(self, msg): 137 137 pass 138 139 def _process_args(self, largs, rargs, values): 140 """overrides OptionParser._process_args to just handle default 141 options and ignore args and other options. With the super class's 142 version, parsing stops at the first unrecognized option. 143 """ 144 while rargs: 145 arg = rargs[0] 146 try: 147 if arg[0:2] == "--" and len(arg) > 2: 148 # process a single long option (possibly with value(s)) 149 # the superclass code pops the arg off rargs 150 self._process_long_opt(rargs, values) 151 elif arg[:1] == "-" and len(arg) > 1: 152 # process a cluster of short options (possibly with 153 # value(s) for the last one only) 154 # the superclass code pops the arg off rargs 155 self._process_short_opts(rargs, values) 156 else: 157 # it's either a non-default option or an arg 158 # either way, add it to the args list so we can keep 159 # dealing with options 160 del rargs[0] 161 raise error 162 except: 163 largs.append(arg) 138 164 139 165 class ManagementUtility(object): 140 166 """ -
tests/regressiontests/core_management/tests.py
old new 1 """ 2 # Tests for LaxOptionParser 3 4 # make sure --settings and --pythonpath are gotten even if they're not first. 5 6 >>> from django.core.management import LaxOptionParser, get_version 7 >>> from django.core.management.base import BaseCommand 8 >>> parser = LaxOptionParser(version=get_version(), option_list=BaseCommand.option_list) 9 >>> options, args = parser.parse_args('django-admin.py command --option --settings=settingsmodule --pythonpath=/home/user/django-dir'.split()) 10 >>> print options 11 {'pythonpath': '/home/user/django-dir', 'settings': 'settingsmodule'} 12 >>> args 13 ['django-admin.py', 'command', '--option'] 14 """
