Ticket #14332: uniform_addrport_handling.patch

File uniform_addrport_handling.patch, 6.7 KB (added by Fede Heinz, 14 years ago)

This patch implements the requested feature

  • django/core/management/commands/runserver.py

    diff -r c8000aad4c10 django/core/management/commands/runserver.py
    a b  
    1515            help='Allows serving static files even if DEBUG is True.'),
    1616        make_option('--adminmedia', dest='admin_media_path', default='',
    1717            help='Specifies the directory from which to serve admin media.'),
     18        make_option('--addrport', action='store', dest='addrport',
     19            type='string', default='',
     20            help='port number or ipaddr:port to run the server on'),
    1821    )
    1922    help = "Starts a lightweight Web server for development."
    2023    args = '[optional port number, or ipaddr:port]'
     
    2225    # Validation is called explicitly each time the server is reloaded.
    2326    requires_model_validation = False
    2427
    25     def handle(self, addrport='', *args, **options):
     28    def handle(self, *args, **options):
    2629        import django
    2730        from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    2831        from django.core.handlers.wsgi import WSGIHandler
    2932        from django.contrib.staticfiles.handlers import StaticFilesHandler
    30         if args:
     33        # addrport can be passed either as either positional or keyword option.
     34        # keyword supersedes positional
     35        addrport = options.get('addrport')
     36        if len(args) > 1:
    3137            raise CommandError('Usage is runserver %s' % self.args)
    32         if not addrport:
    33             addr = ''
    34             port = '8000'
    35         else:
    36             try:
    37                 addr, port = addrport.split(':')
    38             except ValueError:
    39                 addr, port = '', addrport
     38        addrport = addrport or (args and args[0]) or '8000'
     39        try:
     40            addr, port = addrport.split(':')
     41        except ValueError:
     42            addr, port = '', addrport
    4043        if not addr:
    4144            addr = '127.0.0.1'
    4245
  • django/core/management/commands/testserver.py

    diff -r c8000aad4c10 django/core/management/commands/testserver.py
    a b  
    11from django.core.management.base import BaseCommand
    22
    33from optparse import make_option
     4import re
    45
    56class Command(BaseCommand):
    67    option_list = BaseCommand.option_list + (
     
    1112            help='port number or ipaddr:port to run the server on'),
    1213    )
    1314    help = 'Runs a development server with data from the given fixture(s).'
    14     args = '[fixture ...]'
     15    args = '[optional port number, or ipaddr:port] [fixture ...]'
    1516
    1617    requires_model_validation = False
    1718
     
    2324        interactive = options.get('interactive', True)
    2425        addrport = options.get('addrport')
    2526
     27        # if no --addrport option specified, check to see whether first element
     28        # of fixture labels looks like [address:]port. If so, use it as an addrport
     29        # spec.
     30        if not addrport and len(fixture_labels) > 0:
     31            r = re.compile('(.+:)?\d+$')
     32            if r.match(fixture_labels[0]):
     33                addrport = fixture_labels[0]
     34                fixture_labels = fixture_labels[1:]
     35
    2636        # Create a test database.
    2737        db_name = connection.creation.create_test_db(verbosity=verbosity, autoclobber=not interactive)
    2838
  • docs/man/django-admin.1

    diff -r c8000aad4c10 docs/man/django-admin.1
    a b  
    7575.B runfcgi help
    7676for help on the KEY=val pairs.
    7777.TP
    78 .BI "runserver [" "\-\-noreload" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
     78.BI "runserver [" "\-\-noreload" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "\-\-addrport=port|ipaddr:port" "] [" "port|ipaddr:port" "]"
    7979Starts a lightweight Web server for development.
    8080.TP
    8181.BI "shell [" "\-\-plain" "]"
     
    132132Runs the test suite for the specified applications, or the entire project if
    133133no apps are specified
    134134.TP
    135 .BI "testserver [" "\-\-addrport=ipaddr|port" "] [" "fixture fixture ..." "]"
     135.BI "testserver [" "\-\-addrport=ipaddr|ipaddr:port" "] [" "ipaddr:port|port" "] [" "fixture fixture ..." "]"
    136136Runs the test suite for the specified applications, or the entire project if
    137137no apps are specified
    138138.TP
  • docs/ref/django-admin.txt

    diff -r c8000aad4c10 docs/ref/django-admin.txt
    a b  
    716716Port 8000 on IP address 1.2.3.4::
    717717
    718718        django-admin.py runserver 1.2.3.4:8000
     719        django-admin.py runserver --addrport=1.2.3.4:8000
    719720
    720721Port 7000 on IP address 127.0.0.1::
    721722
    722723    django-admin.py runserver 7000
     724    django-admin.py runserver --addrport=7000
    723725
    724726Port 7000 on IP address 1.2.3.4::
    725727
    726728    django-admin.py runserver 1.2.3.4:7000
     729    django-admin.py runserver --addrport=1.2.3.4:7000
    727730
    728731Serving static files with the development server
    729732~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    945948Use the :djadminopt:`--failfast` option to stop running tests and report the failure
    946949immediately after a test fails.
    947950
    948 testserver <fixture fixture ...>
     951testserver [ipaddr:port|port] <fixture fixture ...>
    949952--------------------------------
    950953
    951954.. django-admin:: testserver
     
    991994the default of 127.0.0.1:8000. This value follows exactly the same format and
    992995serves exactly the same function as the argument to the ``runserver`` command.
    993996
     997For consistency with the ``runserver`` command, you can also specify
     998the IP address and port before the list of fixtures. If testserver
     999finds something of the form ``ipaddress:port|port`` as the first item
     1000of the fixture list, it will take it to be an address specification.
     1001
    9941002Examples:
    9951003
    9961004To run the test server on port 7000 with ``fixture1`` and ``fixture2``::
    9971005
    9981006    django-admin.py testserver --addrport 7000 fixture1 fixture2
     1007    django-admin.py testserver 7000 fixture1 fixture2
    9991008    django-admin.py testserver fixture1 fixture2 --addrport 7000
    10001009
    1001 (The above statements are equivalent. We include both of them to demonstrate
    1002 that it doesn't matter whether the options come before or after the fixture
    1003 arguments.)
     1010(The above statements are equivalent. We include all of them to
     1011demonstrate that it doesn't matter whether the options come before or
     1012after the fixture arguments when you use the keyword argument form for
     1013the address specification, but it does matter if you omit the keyword.)
    10041014
    10051015To run on 1.2.3.4:7000 with a ``test`` fixture::
    10061016
    10071017    django-admin.py testserver --addrport 1.2.3.4:7000 test
     1018    django-admin.py testserver 1.2.3.4:7000 test
    10081019
    10091020.. versionadded:: 1.3
    10101021
Back to Top