Exemplo n.º 1
0
    def _UpdateSerialisableInfo(self, version, old_serialisable_info):

        if version == 1:

            (url_type, preferred_scheme, netloc, allow_subdomains,
             keep_subdomains, serialisable_path_components,
             serialisable_parameters, example_url) = old_serialisable_info

            url_match_key = HydrusData.GenerateKey()

            serialisable_url_match_key = url_match_key.encode('hex')

            api_lookup_converter = ClientParsing.StringConverter(
                example_string=example_url)

            serialisable_api_lookup_converter = api_lookup_converter.GetSerialisableTuple(
            )

            new_serialisable_info = (serialisable_url_match_key, url_type,
                                     preferred_scheme, netloc,
                                     allow_subdomains, keep_subdomains,
                                     serialisable_path_components,
                                     serialisable_parameters,
                                     serialisable_api_lookup_converter,
                                     example_url)

            return (2, new_serialisable_info)
Exemplo n.º 2
0
    def __init__(
            self,
            name,
            url_match_key=None,
            url_type=None,
            preferred_scheme='https',
            netloc='hostname.com',
            allow_subdomains=False,
            keep_subdomains=False,
            path_components=None,
            parameters=None,
            api_lookup_converter=None,
            example_url='https://hostname.com/post/page.php?id=123456&s=view'):

        if url_match_key is None:

            url_match_key = HydrusData.GenerateKey()

        if url_type is None:

            url_type = HC.URL_TYPE_POST

        if path_components is None:

            path_components = HydrusSerialisable.SerialisableList()

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

        if parameters is None:

            parameters = HydrusSerialisable.SerialisableDictionary()

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

        if api_lookup_converter is None:

            api_lookup_converter = ClientParsing.StringConverter(
                example_string=
                'https://hostname.com/post/page.php?id=123456&s=view')

        # if the args are not serialisable stuff, lets overwrite here

        path_components = HydrusSerialisable.SerialisableList(path_components)
        parameters = HydrusSerialisable.SerialisableDictionary(parameters)

        HydrusSerialisable.SerialisableBaseNamed.__init__(self, name)

        self._url_match_key = url_match_key
        self._url_type = url_type
        self._preferred_scheme = preferred_scheme
        self._netloc = netloc
        self._allow_subdomains = allow_subdomains
        self._keep_subdomains = keep_subdomains
        self._path_components = path_components
        self._parameters = parameters
        self._api_lookup_converter = api_lookup_converter

        self._example_url = example_url