<s> from django . http import HttpResponse , HttpResponseNotFound <EOL> from git . repo import Repo <EOL> from git . service import GIT_SERVICE_UPLOAD_PACK , GIT_SERVICE_RECEIVE_PACK <EOL> GIT_HTTP_INFO_REFS = <NUM_LIT:1> <EOL> GIT_HTTP_SERVICE_UPLOAD_PACK = <NUM_LIT:2> <EOL> GIT_HTTP_SERVICE_RECEIVE_PACK = <NUM_LIT:3> <EOL> def get_http_error ( exception ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in exception . args [ <NUM_LIT:0> ] : <EOL> return HttpResponseNotFound ( ) <EOL> class GitResponse ( HttpResponse ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . service = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . action = kwargs . pop ( '<STR_LIT:action>' , None ) <EOL> self . repository = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . data = kwargs . pop ( '<STR_LIT:data>' , None ) <EOL> super ( GitResponse , self ) . __init__ ( * args , ** kwargs ) <EOL> def get_packet_length ( self , packet ) : <EOL> """<STR_LIT>""" <EOL> hex = '<STR_LIT>' <EOL> length = len ( packet ) + <NUM_LIT:4> <EOL> prefix = hex [ int ( ( length >> <NUM_LIT:12> ) & <NUM_LIT> ) ] <EOL> prefix = prefix + hex [ int ( ( length >> <NUM_LIT:8> ) & <NUM_LIT> ) ] <EOL> prefix = prefix + hex [ int ( ( length >> <NUM_LIT:4> ) & <NUM_LIT> ) ] <EOL> prefix = prefix + hex [ int ( ( length ) & <NUM_LIT> ) ] <EOL> return prefix <EOL> def get_header_expires ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def get_header_pragma ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def get_header_cache_control ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def get_header_content_type ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . format ( self . service , self . action ) <EOL> def set_response_header ( self ) : <EOL> """<STR_LIT>""" <EOL> self . __setitem__ ( '<STR_LIT>' , self . get_header_expires ( ) ) <EOL> self . __setitem__ ( '<STR_LIT>' , self . get_header_pragma ( ) ) <EOL> self . __setitem__ ( '<STR_LIT>' , self . get_header_cache_control ( ) ) <EOL> self . __setitem__ ( '<STR_LIT:Content-Type>' , self . get_header_content_type ( ) ) <EOL> def set_response_first_line ( self ) : <EOL> """<STR_LIT>""" <EOL> first_line = '<STR_LIT>' . format ( self . service ) <EOL> prefix = self . get_packet_length ( first_line ) <EOL> self . write ( '<STR_LIT>' . format ( prefix , first_line ) ) <EOL> def set_response_payload ( self , payload_type ) : <EOL> """<STR_LIT>""" <EOL> if payload_type == GIT_HTTP_INFO_REFS : <EOL> self . write ( self . repository . get_info_refs ( self . service ) ) <EOL> elif payload_type == GIT_HTTP_SERVICE_RECEIVE_PACK : <EOL> self . write ( self . repository . commit ( self . data ) ) <EOL> elif payload_type == GIT_HTTP_SERVICE_UPLOAD_PACK : <EOL> self . write ( self . repository . pull ( self . data ) ) <EOL> def get_http_info_refs ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . set_response_header ( ) <EOL> self . set_response_first_line ( ) <EOL> self . set_response_payload ( GIT_HTTP_INFO_REFS ) <EOL> return self <EOL> except BaseException as e : <EOL> return get_http_error ( e ) <EOL> def get_http_service_rpc ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . set_response_header ( ) <EOL> if self . service == GIT_SERVICE_RECEIVE_PACK : <EOL> self . set_response_payload ( GIT_HTTP_SERVICE_RECEIVE_PACK ) <EOL> elif self . service == GIT_SERVICE_UPLOAD_PACK : <EOL> self . set_response_payload ( GIT_HTTP_SERVICE_UPLOAD_PACK ) <EOL> return self <EOL> except BaseException as e : <EOL> return get_http_error ( e ) </s>
