<commit_before>import django
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from optparse import make_option
import os
import sys

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
            help='Tells Django to NOT use the auto-reloader.'),
        make_option('--adminmedia', dest='admin_media_path', default='',
            help='Specifies the directory from which to serve admin media.'),
    )
    help = "Starts a lightweight concurrent development web server."
    args = '[optional port number, or ipaddr:port]'

    if hasattr(settings, 'RUNSERVER_DEFAULT_ADDR'):
        DEFAULT_ADDR = settings.RUNSERVER_DEFAULT_ADDR
    else:
        DEFAULT_ADDR = '127.0.0.1'
    if hasattr(settings, 'RUNSERVER_DEFAULT_PORT'):
        DEFAULT_PORT = str(settings.RUNSERVER_DEFAULT_PORT)
    else:
        DEFAULT_PORT = '8000'
    
    #default to the new django1.4 style of admin staticfiles
    DJANGO_ADMIN_MEDIA_PATH = django.__path__[0] + '/contrib/admin/static/admin'
    if django.VERSION[0] == 1 and django.VERSION[1] < 4:
        DJANGO_ADMIN_MEDIA_PATH = django.__path__[0] + '/contrib/admin/media'

    # Validation is called explicitly each time the server is reloaded.
    requires_model_validation = False

    def handle(self, addrport='', *args, **options):
        import django
        from django.core.servers.basehttp import WSGIServerException
        from concurrent_server.servers import run
        from django.core.handlers.wsgi import WSGIHandler
        if args:
            raise CommandError('Usage is runserver %s' % self.args)
        if not addrport:
            addr = self.DEFAULT_ADDR
            port = self.DEFAULT_PORT
        else:
            try:
                addr, port = addrport.split(':')
            except ValueError:
                addr, port = '', addrport
        if not addr:
            addr = self.DEFAULT_ADDR

        if not port.isdigit():
            raise CommandError("%r is not a valid port number." % port)

        use_reloader = options.get('use_reloader', True)
        admin_media_path = options.get('admin_media_path', '')
        shutdown_message = options.get('shutdown_message', '')
        quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'

        def inner_run():
            from django.conf import settings
            from django.utils import translation
            print "Validating models..."
            self.validate(display_num_errors=True)
            print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
            print "Concurrent Development server is running at http://%s:%s/" % (addr, port)
            print "Quit the server with %s." % quit_command

            # django.core.management.base forces the locale to en-us. We should
            # set it up correctly for the first request (particularly important
            # in the "--noreload" case).
            translation.activate(settings.LANGUAGE_CODE)

            try:
                try:
                    from django.contrib.staticfiles.handlers import StaticFilesHandler
                    handler = StaticFilesHandler(WSGIHandler())
                except ImportError: # This is to old version of django
                    path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
                    from django.core.servers.basehttp import AdminMediaHandler
                    handler = AdminMediaHandler(WSGIHandler(), path)
                run(addr, int(port), handler)
            except WSGIServerException, e:
                # Use helpful error messages instead of ugly tracebacks.
                ERRORS = {
                    13: "You don't have permission to access that port.",
                    98: "That port is already in use.",
                    99: "That IP address can't be assigned-to.",
                }
                try:
                    error_text = ERRORS[e.args[0].args[0]]
                except (AttributeError, KeyError):
                    error_text = str(e)
                sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')<commit_msg>Use os.path instead of hardcoding Unix directory paths<commit_after>import django
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from optparse import make_option
import os
import sys


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
            help='Tells Django to NOT use the auto-reloader.'),
        make_option('--adminmedia', dest='admin_media_path', default='',
            help='Specifies the directory from which to serve admin media.'),
    )
    help = "Starts a lightweight concurrent development web server."
    args = '[optional port number, or ipaddr:port]'

    if hasattr(settings, 'RUNSERVER_DEFAULT_ADDR'):
        DEFAULT_ADDR = settings.RUNSERVER_DEFAULT_ADDR
    else:
        DEFAULT_ADDR = '127.0.0.1'
    if hasattr(settings, 'RUNSERVER_DEFAULT_PORT'):
        DEFAULT_PORT = str(settings.RUNSERVER_DEFAULT_PORT)
    else:
        DEFAULT_PORT = '8000'
    
    #default to the new django1.4 style of admin staticfiles
    DJANGO_ADMIN_MEDIA_PATH = django.__path__[0] + '/contrib/admin/static/admin'
    if django.VERSION[0] == 1 and django.VERSION[1] < 4:
        DJANGO_ADMIN_MEDIA_PATH = django.__path__[0] + '/contrib/admin/media'

    # Validation is called explicitly each time the server is reloaded.
    requires_model_validation = False

    def handle(self, addrport='', *args, **options):
        import django
        from django.core.servers.basehttp import WSGIServerException
        from concurrent_server.servers import run
        from django.core.handlers.wsgi import WSGIHandler
        if args:
            raise CommandError('Usage is runserver %s' % self.args)
        if not addrport:
            addr = self.DEFAULT_ADDR
            port = self.DEFAULT_PORT
        else:
            try:
                addr, port = addrport.split(':')
            except ValueError:
                addr, port = '', addrport
        if not addr:
            addr = self.DEFAULT_ADDR

        if not port.isdigit():
            raise CommandError("%r is not a valid port number." % port)

        use_reloader = options.get('use_reloader', True)
        admin_media_path = options.get('admin_media_path', '')
        shutdown_message = options.get('shutdown_message', '')
        quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'

        def inner_run():
            from django.conf import settings
            from django.utils import translation
            print "Validating models..."
            self.validate(display_num_errors=True)
            print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
            print "Concurrent Development server is running at http://%s:%s/" % (addr, port)
            print "Quit the server with %s." % quit_command

            # django.core.management.base forces the locale to en-us. We should
            # set it up correctly for the first request (particularly important
            # in the "--noreload" case).
            translation.activate(settings.LANGUAGE_CODE)

            try:
                try:
                    from django.contrib.staticfiles.handlers import StaticFilesHandler
                    handler = StaticFilesHandler(WSGIHandler())
                except ImportError:  # This is to old version of django
                    path = admin_media_path or os.path.join(django.__path__[0], 'contrib', 'admin', 'media')
                    from django.core.servers.basehttp import AdminMediaHandler
                    handler = AdminMediaHandler(WSGIHandler(), path)
                run(addr, int(port), handler)
            except WSGIServerException, e:
                # Use helpful error messages instead of ugly tracebacks.
                ERRORS = {
                    13: "You don't have permission to access that port.",
                    98: "That port is already in use.",
                    99: "That IP address can't be assigned-to.",
                }
                try:
                    error_text = ERRORS[e.args[0].args[0]]
                except (AttributeError, KeyError):
                    error_text = str(e)
                sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
{'fraction_non_alphanumeric': 0.09244956772334294, 'fraction_numerical': 0.006685878962536023, 'mean_word_length': 2.1979358643568006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6074944', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2238, 'n_words': 660}