def _callbackParsePOSTArgs( self, request: HydrusServerRequest.HydrusRequest ):
     
     request.content.seek( 0 )
     
     if not request.requestHeaders.hasHeader( 'Content-Type' ):
         
         parsed_request_args = HydrusNetworkVariableHandling.ParsedRequestArguments()
         
     else:
         
         content_types = request.requestHeaders.getRawHeaders( 'Content-Type' )
         
         content_type = content_types[0]
         
         try:
             
             mime = HC.mime_enum_lookup[ content_type ]
             
         except:
             
             raise HydrusExceptions.BadRequestException( 'Did not recognise Content-Type header!' )
             
         
         total_bytes_read = 0
         
         if mime == HC.APPLICATION_JSON:
             
             json_string = request.content.read()
             
             total_bytes_read += len( json_string )
             
             parsed_request_args = HydrusNetworkVariableHandling.ParseNetworkBytesToParsedHydrusArgs( json_string )
             
         else:
             
             ( os_file_handle, temp_path ) = HydrusPaths.GetTempPath()
             
             request.temp_file_info = ( os_file_handle, temp_path )
             
             with open( temp_path, 'wb' ) as f:
                 
                 for block in HydrusPaths.ReadFileLikeAsBlocks( request.content ): 
                     
                     f.write( block )
                     
                     total_bytes_read += len( block )
                     
                 
             
             decompression_bombs_ok = self._DecompressionBombsOK( request )
             
             parsed_request_args = HydrusNetworkVariableHandling.ParseFileArguments( temp_path, decompression_bombs_ok )
             
         
         self._reportDataUsed( request, total_bytes_read )
         
     
     request.parsed_request_args = parsed_request_args
     
     return request
Ejemplo n.º 2
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        if 'subject_identifier' not in request.parsed_request_args:

            raise HydrusExceptions.BadRequestException(
                'I was expecting an account key, but did not get one!')

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetAccountKey()

        else:

            raise HydrusExceptions.BadRequestException(
                'The subject\'s account identifier did not include an account key!'
            )

        subject_account = HG.server_controller.Read('account',
                                                    self._service_key,
                                                    subject_account_key)

        account_info = HG.server_controller.Read('account_info',
                                                 self._service_key,
                                                 request.hydrus_account,
                                                 subject_account)

        body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'account_info': account_info})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context
Ejemplo n.º 3
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        services = request.parsed_request_args['services']

        unique_ports = {service.GetPort() for service in services}

        if len(unique_ports) < len(services):

            raise HydrusExceptions.BadRequestException(
                'It looks like some of those services share ports! Please give them unique ports!'
            )

        with HG.dirty_object_lock:

            HG.server_controller.SetServices(services)

            service_keys_to_access_keys = HG.server_controller.WriteSynchronous(
                'services', request.hydrus_account, services)

        body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'service_keys_to_access_keys': service_keys_to_access_keys})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context
 def _callbackParseGETArgs( self, request: HydrusServerRequest.HydrusRequest ):
     
     parsed_request_args = HydrusNetworkVariableHandling.ParseHydrusNetworkGETArgs( request.args )
     
     request.parsed_request_args = parsed_request_args
     
     return request
Ejemplo n.º 5
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        num = request.parsed_request_args['num']
        account_type_key = request.parsed_request_args['account_type_key']

        if 'expires' in request.parsed_request_args:

            expires = request.parsed_request_args['expires']

        else:

            expires = None

        registration_keys = HG.server_controller.Read('registration_keys',
                                                      self._service_key,
                                                      request.hydrus_account,
                                                      num, account_type_key,
                                                      expires)

        body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'registration_keys': registration_keys})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     account_types = HG.server_controller.Read( 'account_types', self._service_key, request.hydrus_account )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'account_types' : account_types } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     service_options = self._service.GetServiceOptions()
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'service_options' : service_options } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     account = request.hydrus_account
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'account' : account } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     # cache this
     petition_count_info = HG.server_controller.Read( 'num_petitions', self._service_key, request.hydrus_account )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'num_petitions' : petition_count_info } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     # fetch cached summary list
     # ( account_key, reason, size of petition )
     petition_summary_list = []
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'petition_summary_list' : petition_summary_list } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     since = request.parsed_request_args[ 'since' ]
     
     metadata_slice = self._service.GetMetadataSlice( since )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'metadata_slice' : metadata_slice } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     account_type_key = request.parsed_request_args[ 'account_type_key' ]
     
     registration_key = HG.server_controller.Read( 'auto_create_registration_key', self._service_key, account_type_key )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'registration_key' : registration_key } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     access_key = self._parseHydrusNetworkAccessKey( request )
     
     verified = HG.server_controller.Read( 'verify_access_key', self._service_key, access_key )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'verified' : verified } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     hash = request.parsed_request_args[ 'hash' ]
     
     ( ip, timestamp ) = HG.server_controller.Read( 'ip', self._service_key, request.hydrus_account, hash )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'ip' : ip, 'timestamp' : timestamp } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     updates = HG.server_controller.Read( 'immediate_update', self._service_key, request.hydrus_account )
     
     updates = HydrusSerialisable.SerialisableList( updates )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'updates' : updates } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     # rewangle this to take an id from the summary list. probably ( account_key, reason_id )
     # and combine petitioned and pending into the same petition
     content_type = request.parsed_request_args[ 'content_type' ]
     status = request.parsed_request_args[ 'status' ]
     
     petition = HG.server_controller.Read( 'petition', self._service_key, request.hydrus_account, content_type, status )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'petition' : petition } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Ejemplo n.º 17
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        if 'subject_identifier' not in request.parsed_request_args:

            raise HydrusExceptions.BadRequestException(
                'I was expecting an account identifier for the subject, but did not get one!'
            )

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetAccountKey()

            try:

                subject_account = HG.server_controller.Read(
                    'account', self._service_key, subject_account_key)

            except HydrusExceptions.InsufficientCredentialsException as e:

                raise HydrusExceptions.NotFoundException(e)

        elif subject_identifier.HasContent():

            subject_content = subject_identifier.GetContent()

            subject_account = HG.server_controller.Read(
                'account_from_content', self._service_key, subject_content)

        else:

            raise HydrusExceptions.BadRequestException(
                'The subject\'s account identifier did not include an account key or content!'
            )

        body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'account': subject_account})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context