<s> from django_extensions . management . utils import setup_logger , signalcommand <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from optparse import make_option <EOL> from smtpd import SMTPServer <EOL> import sys <EOL> import asyncore <EOL> from logging import getLogger <EOL> logger = getLogger ( __name__ ) <EOL> class ExtensionDebuggingServer ( SMTPServer ) : <EOL> """<STR_LIT>""" <EOL> def process_message ( self , peer , mailfrom , rcpttos , data ) : <EOL> """<STR_LIT>""" <EOL> inheaders = <NUM_LIT:1> <EOL> lines = data . split ( '<STR_LIT:\n>' ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> for line in lines : <EOL> if inheaders and not line : <EOL> logger . info ( '<STR_LIT>' % peer [ <NUM_LIT:0> ] ) <EOL> inheaders = <NUM_LIT:0> <EOL> logger . info ( line ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = "<STR_LIT>" <EOL> args = '<STR_LIT>' <EOL> requires_model_validation = False <EOL> @ signalcommand <EOL> def handle ( self , addrport = '<STR_LIT>' , * args , ** options ) : <EOL> if args : <EOL> raise CommandError ( '<STR_LIT>' % self . args ) <EOL> if not addrport : <EOL> if options . get ( '<STR_LIT>' , False ) : <EOL> from django . conf import settings <EOL> addr = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> port = str ( getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> else : <EOL> addr = '<STR_LIT>' <EOL> port = '<STR_LIT>' <EOL> else : <EOL> try : <EOL> addr , port = addrport . split ( '<STR_LIT::>' ) <EOL> except ValueError : <EOL> addr , port = '<STR_LIT>' , addrport <EOL> if not addr : <EOL> addr = '<STR_LIT:127.0.0.1>' <EOL> if not port . isdigit ( ) : <EOL> raise CommandError ( "<STR_LIT>" % port ) <EOL> else : <EOL> port = int ( port ) <EOL> setup_logger ( logger , stream = self . stdout , filename = options . get ( '<STR_LIT>' , None ) ) <EOL> def inner_run ( ) : <EOL> quit_command = ( sys . platform == '<STR_LIT:win32>' ) and '<STR_LIT>' or '<STR_LIT>' <EOL> print ( "<STR_LIT>" % ( addr , port , quit_command ) ) <EOL> ExtensionDebuggingServer ( ( addr , port ) , None ) <EOL> asyncore . loop ( ) <EOL> try : <EOL> inner_run ( ) <EOL> except KeyboardInterrupt : <EOL> pass </s>
