def _GetJob(self, for_login=False):

        job = ClientNetworkingJobs.NetworkJobHydrus(MOCK_HYDRUS_SERVICE_KEY,
                                                    'GET', MOCK_HYDRUS_URL)

        job.SetForLogin(for_login)

        mock_controller = TestController.MockController()

        mock_service = ClientServices.GenerateService(MOCK_HYDRUS_SERVICE_KEY,
                                                      HC.TAG_REPOSITORY,
                                                      'test tag repo')

        mock_services_manager = TestController.MockServicesManager(
            (mock_service, ))

        mock_controller.services_manager = mock_services_manager

        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()
        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        engine = ClientNetworking.NetworkEngine(mock_controller,
                                                bandwidth_manager,
                                                session_manager,
                                                domain_manager, login_manager)

        job.engine = engine

        return job
Beispiel #2
0
    def GetURLId(self, url):

        result = self._Execute('SELECT url_id FROM urls WHERE url = ?;',
                               (url, )).fetchone()

        if result is None:

            try:

                domain = ClientNetworkingDomain.ConvertURLIntoDomain(url)

            except HydrusExceptions.URLClassException:

                domain = 'unknown.com'

            domain_id = self.GetURLDomainId(domain)

            self._Execute(
                'INSERT INTO urls ( domain_id, url ) VALUES ( ?, ? );',
                (domain_id, url))

            url_id = self._GetLastRowId()

        else:

            (url_id, ) = result

        return url_id
    def test_engine_shutdown_manual(self):

        mock_controller = TestController.MockController()
        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()
        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        engine = ClientNetworking.NetworkEngine(mock_controller,
                                                bandwidth_manager,
                                                session_manager,
                                                domain_manager, login_manager)

        self.assertFalse(engine.IsRunning())
        self.assertFalse(engine.IsShutdown())

        mock_controller.CallToThread(engine.MainLoop)

        time.sleep(0.1)

        self.assertTrue(engine.IsRunning())
        self.assertFalse(engine.IsShutdown())

        engine.Shutdown()

        time.sleep(0.1)

        self.assertFalse(engine.IsRunning())
        self.assertTrue(engine.IsShutdown())
Beispiel #4
0
 def _GetSessionNetworkContext( self, network_context ):
     
     # just in case one of these slips through somehow
     if network_context.context_type == CC.NETWORK_CONTEXT_DOMAIN:
         
         second_level_domain = ClientNetworkingDomain.ConvertDomainIntoSecondLevelDomain( network_context.context_data )
         
         network_context = ClientNetworkingContexts.NetworkContext( CC.NETWORK_CONTEXT_DOMAIN, second_level_domain )
         
     
     return network_context
Beispiel #5
0
 def _PrepEngine( self ):
     
     mock_controller = TestController.MockController()
     bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
     session_manager = ClientNetworkingSessions.NetworkSessionManager()
     domain_manager = ClientNetworkingDomain.NetworkDomainManager()
     login_manager = ClientNetworkingLogin.NetworkLoginManager()
     
     ClientDefaults.SetDefaultDomainManagerData( domain_manager )
     
     engine = ClientNetworking.NetworkEngine( mock_controller, bandwidth_manager, session_manager, domain_manager, login_manager )
     
     mock_controller.CallToThread( engine.MainLoop )
     
     return ( mock_controller, engine )
    def test_engine_simple_job(self):

        mock_controller = TestController.MockController()
        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()
        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        engine = ClientNetworking.NetworkEngine(mock_controller,
                                                bandwidth_manager,
                                                session_manager,
                                                domain_manager, login_manager)

        self.assertFalse(engine.IsRunning())
        self.assertFalse(engine.IsShutdown())

        mock_controller.CallToThread(engine.MainLoop)

        #

        with HTTMock(catch_all):

            with HTTMock(catch_wew_ok):

                job = ClientNetworkingJobs.NetworkJob('GET', MOCK_URL)

                engine.AddJob(job)

                time.sleep(0.25)

                self.assertTrue(job.IsDone())
                self.assertFalse(job.HasError())

                engine._new_work_to_do.set()

                time.sleep(0.25)

                self.assertEqual(len(engine._jobs_awaiting_validity), 0)
                self.assertEqual(len(engine._jobs_awaiting_bandwidth), 0)
                self.assertEqual(len(engine._jobs_awaiting_login), 0)
                self.assertEqual(len(engine._jobs_awaiting_slot), 0)
                self.assertEqual(len(engine._jobs_running), 0)

        #

        engine.Shutdown()
    def _GetJob(self, for_login=False):

        job = ClientNetworkingJobs.NetworkJob('GET', MOCK_URL)

        job.SetForLogin(for_login)

        mock_controller = TestController.MockController()
        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()
        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        engine = ClientNetworking.NetworkEngine(mock_controller,
                                                bandwidth_manager,
                                                session_manager,
                                                domain_manager, login_manager)

        job.engine = engine

        return job
Beispiel #8
0
    def GetURLDomainAndSubdomainIds(self, domain, only_www_subdomains=False):

        domain = ClientNetworkingDomain.RemoveWWWFromDomain(domain)

        domain_ids = set()

        domain_ids.add(self.GetURLDomainId(domain))

        if only_www_subdomains:

            search_phrase = 'www%.{}'.format(domain)

        else:

            search_phrase = '%.{}'.format(domain)

        for (domain_id, ) in self._Execute(
                'SELECT domain_id FROM url_domains WHERE domain LIKE ?;',
            (search_phrase, )):

            domain_ids.add(domain_id)

        return domain_ids
    def test_engine_shutdown_app(self):

        mock_controller = TestController.MockController()
        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()
        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        engine = ClientNetworking.NetworkEngine(mock_controller,
                                                bandwidth_manager,
                                                session_manager,
                                                domain_manager, login_manager)

        self.assertFalse(engine.IsRunning())
        self.assertFalse(engine.IsShutdown())

        mock_controller.CallToThread(engine.MainLoop)

        time.sleep(0.1)

        self.assertTrue(engine.IsRunning())
        self.assertFalse(engine.IsShutdown())

        HG.model_shutdown = True

        try:

            engine._new_work_to_do.set()

            time.sleep(0.1)

            self.assertFalse(engine.IsRunning())
            self.assertTrue(engine.IsShutdown())

        finally:

            HG.model_shutdown = False
    def test_url_classes(self):

        name = 'test'
        url_type = HC.URL_TYPE_POST
        preferred_scheme = 'https'
        netloc = 'testbooru.cx'

        alphabetise_get_parameters = True
        match_subdomains = False
        keep_matched_subdomains = False
        can_produce_multiple_files = False
        should_be_associated_with_files = True

        path_components = []

        path_components.append((ClientParsing.StringMatch(
            match_type=ClientParsing.STRING_MATCH_FIXED,
            match_value='post',
            example_string='post'), None))
        path_components.append((ClientParsing.StringMatch(
            match_type=ClientParsing.STRING_MATCH_FIXED,
            match_value='page.php',
            example_string='page.php'), None))

        parameters = {}

        parameters['s'] = (ClientParsing.StringMatch(
            match_type=ClientParsing.STRING_MATCH_FIXED,
            match_value='view',
            example_string='view'), None)
        parameters['id'] = (ClientParsing.StringMatch(
            match_type=ClientParsing.STRING_MATCH_FLEXIBLE,
            match_value=ClientParsing.NUMERIC,
            example_string='123456'), None)

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_ONLY_IF_PROVIDED
        referral_url_converter = None
        gallery_index_type = None
        gallery_index_identifier = None
        gallery_index_delta = 1
        example_url = 'https://testbooru.cx/post/page.php?id=123456&s=view'

        #

        referral_url = 'https://testbooru.cx/gallery/tags=samus_aran'
        good_url = 'https://testbooru.cx/post/page.php?id=123456&s=view'
        unnormalised_good_url_1 = 'https://testbooru.cx/post/page.php?id=123456&s=view&additional_gumpf=stuff'
        unnormalised_good_url_2 = 'https://testbooru.cx/post/page.php?s=view&id=123456'
        bad_url = 'https://wew.lad/123456'

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files)

        self.assertEqual(url_class.Matches(example_url), True)
        self.assertEqual(url_class.Matches(bad_url), False)

        self.assertEqual(url_class.Normalise(unnormalised_good_url_1),
                         good_url)
        self.assertEqual(url_class.Normalise(unnormalised_good_url_2),
                         good_url)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         referral_url)
        self.assertEqual(url_class.GetReferralURL(good_url, None), None)

        #

        alphabetise_get_parameters = False

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files)

        self.assertEqual(url_class.Normalise(unnormalised_good_url_2),
                         unnormalised_good_url_2)

        alphabetise_get_parameters = True

        #

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_NEVER

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         None)
        self.assertEqual(url_class.GetReferralURL(good_url, None), None)

        #

        converted_referral_url = good_url.replace('testbooru.cx',
                                                  'replace.com')

        transformations = []

        transformations.append((ClientParsing.STRING_TRANSFORMATION_REGEX_SUB,
                                ('testbooru.cx', 'replace.com')))

        referral_url_converter = ClientParsing.StringConverter(
            transformations, good_url)

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_CONVERTER_IF_NONE_PROVIDED

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         referral_url)
        self.assertEqual(url_class.GetReferralURL(good_url, None),
                         converted_referral_url)

        #

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_ONLY_CONVERTER

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         converted_referral_url)
        self.assertEqual(url_class.GetReferralURL(good_url, None),
                         converted_referral_url)
Beispiel #11
0
    def test_url_classes(self):

        name = 'test'
        url_type = HC.URL_TYPE_POST
        preferred_scheme = 'https'
        netloc = 'testbooru.cx'

        alphabetise_get_parameters = True
        match_subdomains = False
        keep_matched_subdomains = False
        can_produce_multiple_files = False
        should_be_associated_with_files = True
        keep_fragment = False

        path_components = []

        path_components.append((ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='post',
            example_string='post'), None))
        path_components.append((ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='page.php',
            example_string='page.php'), None))

        parameters = {}

        parameters['s'] = (ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='view',
            example_string='view'), None)
        parameters['id'] = (ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FLEXIBLE,
            match_value=ClientStrings.NUMERIC,
            example_string='123456'), None)

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_ONLY_IF_PROVIDED
        referral_url_converter = None
        gallery_index_type = None
        gallery_index_identifier = None
        gallery_index_delta = 1
        example_url = 'https://testbooru.cx/post/page.php?id=123456&s=view'

        #

        referral_url = 'https://testbooru.cx/gallery/tags=samus_aran'
        good_url = 'https://testbooru.cx/post/page.php?id=123456&s=view'
        unnormalised_good_url_1 = 'https://testbooru.cx/post/page.php?id=123456&s=view&additional_gumpf=stuff'
        unnormalised_good_url_2 = 'https://testbooru.cx/post/page.php?s=view&id=123456'
        bad_url = 'https://wew.lad/123456'

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.Matches(example_url), True)
        self.assertEqual(url_class.Matches(bad_url), False)

        self.assertEqual(url_class.Normalise(unnormalised_good_url_1),
                         good_url)
        self.assertEqual(url_class.Normalise(unnormalised_good_url_2),
                         good_url)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         referral_url)
        self.assertEqual(url_class.GetReferralURL(good_url, None), None)

        #

        alphabetise_get_parameters = False

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.Normalise(unnormalised_good_url_2),
                         unnormalised_good_url_2)

        alphabetise_get_parameters = True

        #

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_NEVER

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         None)
        self.assertEqual(url_class.GetReferralURL(good_url, None), None)

        #

        converted_referral_url = good_url.replace('testbooru.cx',
                                                  'replace.com')

        conversions = []

        conversions.append((ClientStrings.STRING_CONVERSION_REGEX_SUB,
                            ('testbooru.cx', 'replace.com')))

        referral_url_converter = ClientStrings.StringConverter(
            conversions, good_url)

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_CONVERTER_IF_NONE_PROVIDED

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         referral_url)
        self.assertEqual(url_class.GetReferralURL(good_url, None),
                         converted_referral_url)

        #

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_ONLY_CONVERTER

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.GetReferralURL(good_url, referral_url),
                         converted_referral_url)
        self.assertEqual(url_class.GetReferralURL(good_url, None),
                         converted_referral_url)

        # fragment test

        name = 'mega test'
        url_type = HC.URL_TYPE_POST
        preferred_scheme = 'https'
        netloc = 'mega.nz'

        alphabetise_get_parameters = True
        match_subdomains = False
        keep_matched_subdomains = False
        can_produce_multiple_files = True
        should_be_associated_with_files = True

        path_components = []

        path_components.append((ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='file',
            example_string='file'), None))
        path_components.append((ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_ANY), None))

        parameters = {}

        send_referral_url = ClientNetworkingDomain.SEND_REFERRAL_URL_ONLY_IF_PROVIDED
        referral_url_converter = None
        gallery_index_type = None
        gallery_index_identifier = None
        gallery_index_delta = 1
        example_url = 'https://mega.nz/file/KxJHVKhT#0JPvygZDQcjBHrTWWECaDyNfXAFDyNZyE3Uonif5j-w'

        keep_fragment = False

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.Normalise(example_url),
                         'https://mega.nz/file/KxJHVKhT')

        keep_fragment = True

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.Normalise(example_url), example_url)

        # single-value params test

        single_value_good_url = 'https://testbooru.cx/post/page.php?id=123456&token&s=view'
        single_value_bad_url = 'https://testbooru.cx/post/page.php?id=123456&bad_token&s=view'
        single_value_missing_url = 'https://testbooru.cx/post/page.php?id=123456&s=view'
        single_value_good_url_multiple = 'https://testbooru.cx/post/page.php?id=123456&token1&token2&s=view&token0'

        single_value_good_url_alphabetical_normalised = 'https://testbooru.cx/post/page.php?id=123456&s=view&token'
        single_value_good_url_multiple_alphabetical_normalised = 'https://testbooru.cx/post/page.php?id=123456&s=view&token0&token1&token2'

        name = 'single value lad'
        url_type = HC.URL_TYPE_POST
        preferred_scheme = 'https'
        netloc = 'testbooru.cx'

        alphabetise_get_parameters = True
        match_subdomains = False
        keep_matched_subdomains = False
        can_produce_multiple_files = False
        should_be_associated_with_files = True
        keep_fragment = False

        path_components = []

        path_components.append((ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='post',
            example_string='post'), None))
        path_components.append((ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='page.php',
            example_string='page.php'), None))

        parameters = {}

        parameters['s'] = (ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FIXED,
            match_value='view',
            example_string='view'), None)
        parameters['id'] = (ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_FLEXIBLE,
            match_value=ClientStrings.NUMERIC,
            example_string='123456'), None)

        has_single_value_parameters = True
        single_value_parameters_string_match = ClientStrings.StringMatch(
            match_type=ClientStrings.STRING_MATCH_REGEX,
            match_value='^token.*',
            example_string='token1')

        example_url = single_value_good_url

        url_class = ClientNetworkingDomain.URLClass(
            name,
            url_type=url_type,
            preferred_scheme=preferred_scheme,
            netloc=netloc,
            path_components=path_components,
            parameters=parameters,
            has_single_value_parameters=has_single_value_parameters,
            single_value_parameters_string_match=
            single_value_parameters_string_match,
            send_referral_url=send_referral_url,
            referral_url_converter=referral_url_converter,
            gallery_index_type=gallery_index_type,
            gallery_index_identifier=gallery_index_identifier,
            gallery_index_delta=gallery_index_delta,
            example_url=example_url)

        url_class.SetURLBooleans(match_subdomains, keep_matched_subdomains,
                                 alphabetise_get_parameters,
                                 can_produce_multiple_files,
                                 should_be_associated_with_files,
                                 keep_fragment)

        self.assertEqual(url_class.Normalise(single_value_good_url),
                         single_value_good_url_alphabetical_normalised)
        self.assertEqual(
            url_class.Normalise(single_value_good_url_multiple),
            single_value_good_url_multiple_alphabetical_normalised)

        self.assertEqual(url_class.Matches(single_value_good_url), True)
        self.assertEqual(
            url_class.Matches(single_value_good_url_alphabetical_normalised),
            True)
        self.assertEqual(url_class.Matches(single_value_good_url_multiple),
                         True)
        self.assertEqual(
            url_class.Matches(
                single_value_good_url_multiple_alphabetical_normalised), True)
        self.assertEqual(url_class.Matches(single_value_bad_url), False)
        self.assertEqual(url_class.Matches(single_value_missing_url), False)

        url_class.SetAlphabetiseGetParameters(False)

        self.assertEqual(url_class.Normalise(single_value_good_url),
                         single_value_good_url)
        self.assertEqual(url_class.Normalise(single_value_good_url_multiple),
                         single_value_good_url_multiple)

        self.assertEqual(url_class.Matches(single_value_good_url), True)
        self.assertEqual(
            url_class.Matches(single_value_good_url_alphabetical_normalised),
            True)
        self.assertEqual(url_class.Matches(single_value_good_url_multiple),
                         True)
        self.assertEqual(
            url_class.Matches(
                single_value_good_url_multiple_alphabetical_normalised), True)
        self.assertEqual(url_class.Matches(single_value_bad_url), False)
        self.assertEqual(url_class.Matches(single_value_missing_url), False)
Beispiel #12
0
    def __init__(self, win, only_run):

        self.app = win
        self.win = win
        self.only_run = only_run

        self.db_dir = tempfile.mkdtemp()

        global DB_DIR

        DB_DIR = self.db_dir

        self._server_files_dir = os.path.join(self.db_dir, 'server_files')
        self._updates_dir = os.path.join(self.db_dir, 'test_updates')

        client_files_default = os.path.join(self.db_dir, 'client_files')

        HydrusPaths.MakeSureDirectoryExists(self._server_files_dir)
        HydrusPaths.MakeSureDirectoryExists(self._updates_dir)
        HydrusPaths.MakeSureDirectoryExists(client_files_default)

        HG.controller = self
        HG.client_controller = self
        HG.server_controller = self
        HG.test_controller = self

        self.db = self
        self.gui = self

        self.frame_splash_status = ClientGUISplash.FrameSplashStatus()

        self._call_to_threads = []

        self._pubsub = HydrusPubSub.HydrusPubSub(self, lambda o: True)

        self.new_options = ClientOptions.ClientOptions()

        HC.options = ClientDefaults.GetClientDefaultOptions()

        self.options = HC.options

        def show_text(text):
            pass

        HydrusData.ShowText = show_text

        self._reads = {}

        self._reads['local_booru_share_keys'] = []
        self._reads['messaging_sessions'] = []
        self._reads['options'] = ClientDefaults.GetClientDefaultOptions()
        self._reads['file_system_predicates'] = []
        self._reads['media_results'] = []

        self._param_reads = {}

        self.example_tag_repo_service_key = HydrusData.GenerateKey()

        services = []

        services.append(
            ClientServices.GenerateService(CC.LOCAL_BOORU_SERVICE_KEY,
                                           HC.LOCAL_BOORU, 'local booru'))
        services.append(
            ClientServices.GenerateService(CC.CLIENT_API_SERVICE_KEY,
                                           HC.CLIENT_API_SERVICE,
                                           'client api'))
        services.append(
            ClientServices.GenerateService(CC.COMBINED_LOCAL_FILE_SERVICE_KEY,
                                           HC.COMBINED_LOCAL_FILE,
                                           'all local files'))
        services.append(
            ClientServices.GenerateService(CC.LOCAL_FILE_SERVICE_KEY,
                                           HC.LOCAL_FILE_DOMAIN, 'my files'))
        services.append(
            ClientServices.GenerateService(CC.TRASH_SERVICE_KEY,
                                           HC.LOCAL_FILE_TRASH_DOMAIN,
                                           'trash'))
        services.append(
            ClientServices.GenerateService(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY,
                                           HC.LOCAL_TAG, 'my tags'))
        services.append(
            ClientServices.GenerateService(self.example_tag_repo_service_key,
                                           HC.TAG_REPOSITORY,
                                           'example tag repo'))
        services.append(
            ClientServices.GenerateService(CC.COMBINED_TAG_SERVICE_KEY,
                                           HC.COMBINED_TAG, 'all known tags'))
        services.append(
            ClientServices.GenerateService(
                LOCAL_RATING_LIKE_SERVICE_KEY, HC.LOCAL_RATING_LIKE,
                'example local rating like service'))
        services.append(
            ClientServices.GenerateService(
                LOCAL_RATING_NUMERICAL_SERVICE_KEY, HC.LOCAL_RATING_NUMERICAL,
                'example local rating numerical service'))

        self._reads['services'] = services

        client_files_locations = {}

        for prefix in HydrusData.IterateHexPrefixes():

            for c in ('f', 't'):

                client_files_locations[c + prefix] = client_files_default

        self._reads['client_files_locations'] = client_files_locations

        self._reads['sessions'] = []
        self._reads['tag_parents'] = {}
        self._reads['tag_siblings_all_ideals'] = {}
        self._reads['in_inbox'] = False

        self._writes = collections.defaultdict(list)

        self._managers = {}

        self.column_list_manager = ClientGUIListManager.ColumnListManager()

        self.services_manager = ClientServices.ServicesManager(self)
        self.client_files_manager = ClientFiles.ClientFilesManager(self)

        self.parsing_cache = ClientCaches.ParsingCache()

        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()

        ClientDefaults.SetDefaultDomainManagerData(domain_manager)

        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        self.network_engine = ClientNetworking.NetworkEngine(
            self, bandwidth_manager, session_manager, domain_manager,
            login_manager)

        self.CallToThreadLongRunning(self.network_engine.MainLoop)

        self.tag_display_manager = ClientTagsHandling.TagDisplayManager()

        self._managers['undo'] = ClientManagers.UndoManager(self)
        self.server_session_manager = HydrusSessions.HydrusSessionManagerServer(
        )

        self.bitmap_manager = ClientManagers.BitmapManager(self)

        self.local_booru_manager = ClientCaches.LocalBooruCache(self)
        self.client_api_manager = ClientAPI.APIManager()

        self._cookies = {}

        self._job_scheduler = HydrusThreading.JobScheduler(self)

        self._job_scheduler.start()