Ticket #6017: lax-option-parser.patch

File lax-option-parser.patch, 2.9 KB (added by Todd O'Bryan, 17 years ago)
  • django/core/management/__init__.py

    Property changes on: .
    ___________________________________________________________________
    Name: svn:ignore
       - build
    dist
    *.egg-info
    MANIFEST
    *.pyc
    
       + build
    dist
    *.egg-info
    MANIFEST
    *.pyc
    .settings
    .project
    .pydevproject
    
    
     
    135135    """
    136136    def error(self, msg):
    137137        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)
    138164
    139165class ManagementUtility(object):
    140166    """
  • tests/regressiontests/core_management/tests.py

     
     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"""
     15 No newline at end of file
Back to Top