<s> import HydrusConstants as HC <EOL> import HydrusServerResources <EOL> import traceback <EOL> from twisted . web . server import Request , Site <EOL> from twisted . web . resource import Resource <EOL> import HydrusData <EOL> import time <EOL> eris = '''<STR_LIT>''' + str ( HC . SOFTWARE_VERSION ) + '''<STR_LIT>''' <EOL> LOCAL_DOMAIN = HydrusServerResources . HydrusDomain ( True ) <EOL> REMOTE_DOMAIN = HydrusServerResources . HydrusDomain ( False ) <EOL> class HydrusRequest ( Request ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> Request . __init__ ( self , * args , ** kwargs ) <EOL> self . start_time = time . clock ( ) <EOL> self . is_hydrus_client = True <EOL> self . hydrus_args = None <EOL> self . hydrus_response_context = None <EOL> self . hydrus_request_data_usage = <NUM_LIT:0> <EOL> def finish ( self ) : <EOL> Request . finish ( self ) <EOL> host = self . getHost ( ) <EOL> status_text = '<STR_LIT>' <EOL> if self . hydrus_response_context is not None : <EOL> status_text = HydrusData . ToUnicode ( self . hydrus_response_context . GetStatusCode ( ) ) <EOL> message = str ( host . port ) + '<STR_LIT:U+0020>' + HydrusData . ToUnicode ( self . method ) + '<STR_LIT:U+0020>' + HydrusData . ToUnicode ( self . path ) + '<STR_LIT:U+0020>' + status_text + '<STR_LIT>' + HydrusData . ConvertTimeDeltaToPrettyString ( time . clock ( ) - self . start_time ) <EOL> HydrusData . Print ( message ) <EOL> class HydrusService ( Site ) : <EOL> def __init__ ( self , service_key , service_type , message ) : <EOL> self . _service_key = service_key <EOL> self . _service_type = service_type <EOL> self . _message = message <EOL> root = self . _InitRoot ( ) <EOL> Site . __init__ ( self , root ) <EOL> self . requestFactory = HydrusRequest <EOL> def _InitRoot ( self ) : <EOL> root = Resource ( ) <EOL> root . putChild ( '<STR_LIT>' , HydrusServerResources . HydrusResourceWelcome ( self . _service_type , self . _message ) ) <EOL> root . putChild ( '<STR_LIT>' , HydrusServerResources . hydrus_favicon ) <EOL> return root <EOL> '''<STR_LIT>''' </s>
