<s> """<STR_LIT>""" <EOL> import sys <EOL> import UserDict <EOL> import urllib <EOL> from twisted . protocols import basic <EOL> from twisted . protocols import policies <EOL> from twisted . internet import protocol , defer <EOL> from twisted . python import log <EOL> def quote ( s ) : <EOL> return urllib . quote ( s ) <EOL> def unquote ( s ) : <EOL> return urllib . unquote ( s ) <EOL> class PostfixTCPMapServer ( basic . LineReceiver , policies . TimeoutMixin ) : <EOL> """<STR_LIT>""" <EOL> timeout = <NUM_LIT> <EOL> delimiter = '<STR_LIT:\n>' <EOL> def connectionMade ( self ) : <EOL> self . setTimeout ( self . timeout ) <EOL> def sendCode ( self , code , message = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> self . sendLine ( '<STR_LIT>' % ( code , message or '<STR_LIT>' ) ) <EOL> def lineReceived ( self , line ) : <EOL> self . resetTimeout ( ) <EOL> try : <EOL> request , params = line . split ( None , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> request = line <EOL> params = None <EOL> try : <EOL> f = getattr ( self , '<STR_LIT>' + request ) <EOL> except AttributeError : <EOL> self . sendCode ( <NUM_LIT> , '<STR_LIT>' ) <EOL> else : <EOL> try : <EOL> f ( params ) <EOL> except : <EOL> self . sendCode ( <NUM_LIT> , '<STR_LIT>' % ( request , sys . exc_info ( ) [ <NUM_LIT:1> ] ) ) <EOL> def do_get ( self , key ) : <EOL> if key is None : <EOL> self . sendCode ( <NUM_LIT> , '<STR_LIT>' % '<STR_LIT>' ) <EOL> else : <EOL> d = defer . maybeDeferred ( self . factory . get , key ) <EOL> d . addCallbacks ( self . _cbGot , self . _cbNot ) <EOL> d . addErrback ( log . err ) <EOL> def _cbNot ( self , fail ) : <EOL> self . sendCode ( <NUM_LIT> , fail . getErrorMessage ( ) ) <EOL> def _cbGot ( self , value ) : <EOL> if value is None : <EOL> self . sendCode ( <NUM_LIT> ) <EOL> else : <EOL> self . sendCode ( <NUM_LIT:200> , quote ( value ) ) <EOL> def do_put ( self , keyAndValue ) : <EOL> if keyAndValue is None : <EOL> self . sendCode ( <NUM_LIT> , '<STR_LIT>' % '<STR_LIT>' ) <EOL> else : <EOL> try : <EOL> key , value = keyAndValue . split ( None , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> self . sendCode ( <NUM_LIT> , '<STR_LIT>' % '<STR_LIT>' ) <EOL> else : <EOL> self . sendCode ( <NUM_LIT> , '<STR_LIT>' ) <EOL> class PostfixTCPMapDictServerFactory ( protocol . ServerFactory , <EOL> UserDict . UserDict ) : <EOL> """<STR_LIT>""" <EOL> protocol = PostfixTCPMapServer <EOL> class PostfixTCPMapDeferringDictServerFactory ( protocol . ServerFactory ) : <EOL> """<STR_LIT>""" <EOL> protocol = PostfixTCPMapServer <EOL> def __init__ ( self , data = None ) : <EOL> self . data = { } <EOL> if data is not None : <EOL> self . data . update ( data ) <EOL> def get ( self , key ) : <EOL> return defer . succeed ( self . data . get ( key ) ) </s>
